From 5368b8a344376ea857e826de223320d7ec6a2474 Mon Sep 17 00:00:00 2001 From: Garvan Keeley Date: Tue, 8 Sep 2015 21:20:57 -0400 Subject: [PATCH] Bug 1200310 - No need to wifi+cell scan if stumble file is full, just trigger upload. r=jdm --- dom/system/gonk/mozstumbler/MozStumbler.cpp | 10 ++++++++++ dom/system/gonk/mozstumbler/WriteStumbleOnThread.cpp | 10 ++++++++++ dom/system/gonk/mozstumbler/WriteStumbleOnThread.h | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/dom/system/gonk/mozstumbler/MozStumbler.cpp b/dom/system/gonk/mozstumbler/MozStumbler.cpp index d59aaf9e78b0..e535e321c826 100644 --- a/dom/system/gonk/mozstumbler/MozStumbler.cpp +++ b/dom/system/gonk/mozstumbler/MozStumbler.cpp @@ -77,6 +77,16 @@ private: void MozStumble(nsGeoPosition* position) { + if (WriteStumbleOnThread::IsFileWaitingForUpload()) { + nsCOMPtr target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); + MOZ_ASSERT(target); + // Knowing that file is waiting to upload, and no collection will take place, + // just trigger the thread with an empty string. + nsCOMPtr event = new WriteStumbleOnThread(EmptyCString()); + target->Dispatch(event, NS_DISPATCH_NORMAL); + return; + } + nsCOMPtr coords; position->GetCoords(getter_AddRefs(coords)); if (!coords) { diff --git a/dom/system/gonk/mozstumbler/WriteStumbleOnThread.cpp b/dom/system/gonk/mozstumbler/WriteStumbleOnThread.cpp index 8ea27ce24892..42cf5e940151 100644 --- a/dom/system/gonk/mozstumbler/WriteStumbleOnThread.cpp +++ b/dom/system/gonk/mozstumbler/WriteStumbleOnThread.cpp @@ -17,6 +17,7 @@ #define ONEDAY_IN_MSEC (24 * 60 * 60 * 1000) #define MAX_UPLOAD_ATTEMPTS 20 +mozilla::Atomic WriteStumbleOnThread::sIsFileWaitingForUpload(false); mozilla::Atomic WriteStumbleOnThread::sIsAlreadyRunning(false); WriteStumbleOnThread::UploadFreqGuard WriteStumbleOnThread::sUploadFreqGuard = {0}; @@ -42,6 +43,7 @@ class DeleteRunnable : public nsRunnable } // critically, this sets this flag to false so writing can happen again WriteStumbleOnThread::sIsAlreadyRunning = false; + WriteStumbleOnThread::sIsFileWaitingForUpload = false; return NS_OK; } @@ -49,6 +51,12 @@ class DeleteRunnable : public nsRunnable ~DeleteRunnable() {} }; +bool +WriteStumbleOnThread::IsFileWaitingForUpload() +{ + return sIsFileWaitingForUpload; +} + void WriteStumbleOnThread::UploadEnded(bool deleteUploadFile) { @@ -194,6 +202,7 @@ WriteStumbleOnThread::Run() if (UploadFileStatus::NoFile != status) { if (UploadFileStatus::ExistsAndReadyToUpload == status) { + sIsFileWaitingForUpload = true; Upload(); return NS_OK; } @@ -206,6 +215,7 @@ WriteStumbleOnThread::Run() } } + sIsFileWaitingForUpload = false; sIsAlreadyRunning = false; return NS_OK; } diff --git a/dom/system/gonk/mozstumbler/WriteStumbleOnThread.h b/dom/system/gonk/mozstumbler/WriteStumbleOnThread.h index d32cc05043f9..35cb6def689a 100644 --- a/dom/system/gonk/mozstumbler/WriteStumbleOnThread.h +++ b/dom/system/gonk/mozstumbler/WriteStumbleOnThread.h @@ -46,6 +46,10 @@ public: static void UploadEnded(bool deleteUploadFile); + // Used externally to determine if cell+wifi scans should happen + // (returns false for that case). + static bool IsFileWaitingForUpload(); + private: friend class DeleteRunnable; @@ -72,6 +76,8 @@ private: // Only run one instance of this static mozilla::Atomic sIsAlreadyRunning; + static mozilla::Atomic sIsFileWaitingForUpload; + // Limit the upload attempts per day. If the device is rebooted // this resets the allowed attempts, which is acceptable. struct UploadFreqGuard {