Bug 1200310 - No need to wifi+cell scan if stumble file is full, just trigger upload. r=jdm
authorGarvan Keeley <gkeeley@mozilla.com>
Tue, 08 Sep 2015 21:20:57 -0400
changeset 294066 d7edc758649a9a5a43fbe038b2e190dca4072f25
parent 294065 b542d5f36d6bb87025b0287ed89c7f9edb83ff0c
child 294067 947d0307ed7730e95171822033f6eb46cf3c2cd5
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1200310
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1200310 - No need to wifi+cell scan if stumble file is full, just trigger upload. r=jdm
dom/system/gonk/mozstumbler/MozStumbler.cpp
dom/system/gonk/mozstumbler/WriteStumbleOnThread.cpp
dom/system/gonk/mozstumbler/WriteStumbleOnThread.h
--- a/dom/system/gonk/mozstumbler/MozStumbler.cpp
+++ b/dom/system/gonk/mozstumbler/MozStumbler.cpp
@@ -72,16 +72,26 @@ public:
   }
 private:
   nsRefPtr<StumblerInfo> mRequestCallback;
 };
 
 void
 MozStumble(nsGeoPosition* position)
 {
+  if (WriteStumbleOnThread::IsFileWaitingForUpload()) {
+    nsCOMPtr<nsIEventTarget> 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<nsIRunnable> event = new WriteStumbleOnThread(EmptyCString());
+    target->Dispatch(event, NS_DISPATCH_NORMAL);
+    return;
+  }
+
   nsCOMPtr<nsIDOMGeoPositionCoords> coords;
   position->GetCoords(getter_AddRefs(coords));
   if (!coords) {
     return;
   }
 
   double latitude, longitude;
   coords->GetLatitude(&latitude);
--- a/dom/system/gonk/mozstumbler/WriteStumbleOnThread.cpp
+++ b/dom/system/gonk/mozstumbler/WriteStumbleOnThread.cpp
@@ -12,16 +12,17 @@
 #include "nsIFileStreams.h"
 #include "nsIInputStream.h"
 #include "nsPrintfCString.h"
 
 #define MAXFILESIZE_KB (15 * 1024)
 #define ONEDAY_IN_MSEC (24 * 60 * 60 * 1000)
 #define MAX_UPLOAD_ATTEMPTS 20
 
+mozilla::Atomic<bool> WriteStumbleOnThread::sIsFileWaitingForUpload(false);
 mozilla::Atomic<bool> WriteStumbleOnThread::sIsAlreadyRunning(false);
 WriteStumbleOnThread::UploadFreqGuard WriteStumbleOnThread::sUploadFreqGuard = {0};
 
 #define FILENAME_INPROGRESS NS_LITERAL_CSTRING("stumbles.json.gz")
 #define FILENAME_COMPLETED NS_LITERAL_CSTRING("stumbles.done.json.gz")
 #define OUTPUT_DIR NS_LITERAL_CSTRING("mozstumbler")
 
 class DeleteRunnable : public nsRunnable
@@ -37,23 +38,30 @@ class DeleteRunnable : public nsRunnable
                                               getter_AddRefs(tmpFile),
                                               OUTPUT_DIR,
                                               nsDumpUtils::CREATE);
       if (NS_SUCCEEDED(rv)) {
         tmpFile->Remove(true);
       }
       // critically, this sets this flag to false so writing can happen again
       WriteStumbleOnThread::sIsAlreadyRunning = false;
+      WriteStumbleOnThread::sIsFileWaitingForUpload = false;
       return NS_OK;
     }
 
   private:
     ~DeleteRunnable() {}
 };
 
+bool
+WriteStumbleOnThread::IsFileWaitingForUpload()
+{
+  return sIsFileWaitingForUpload;
+}
+
 void
 WriteStumbleOnThread::UploadEnded(bool deleteUploadFile)
 {
   if (!deleteUploadFile) {
     sIsAlreadyRunning = false;
     return;
   }
 
@@ -189,28 +197,30 @@ WriteStumbleOnThread::Run()
   if (b) {
     return NS_OK;
   }
 
   UploadFileStatus status = GetUploadFileStatus();
 
   if (UploadFileStatus::NoFile != status) {
     if (UploadFileStatus::ExistsAndReadyToUpload == status) {
+      sIsFileWaitingForUpload = true;
       Upload();
       return NS_OK;
     }
   } else {
     Partition partition = GetWritePosition();
     if (partition == Partition::Unknown) {
       STUMBLER_ERR("GetWritePosition failed, skip once");
     } else {
       WriteJSON(partition);
     }
   }
 
+  sIsFileWaitingForUpload = false;
   sIsAlreadyRunning = false;
   return NS_OK;
 }
 
 
 /*
  If the upload file exists, then check if it is one day old.
  • if it is a day old -> ExistsAndReadyToUpload
--- a/dom/system/gonk/mozstumbler/WriteStumbleOnThread.h
+++ b/dom/system/gonk/mozstumbler/WriteStumbleOnThread.h
@@ -41,16 +41,20 @@ public:
   explicit WriteStumbleOnThread(const nsCString& aDesc)
   : mDesc(aDesc)
   {}
 
   NS_IMETHODIMP Run() override;
 
   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;
 
   enum class Partition {
     Begining,
     Middle,
     End,
     Unknown
@@ -67,16 +71,18 @@ private:
   void WriteJSON(Partition aPart);
   void Upload();
 
   nsCString mDesc;
 
   // Only run one instance of this
   static mozilla::Atomic<bool> sIsAlreadyRunning;
 
+  static mozilla::Atomic<bool> sIsFileWaitingForUpload;
+
   // Limit the upload attempts per day. If the device is rebooted
   // this resets the allowed attempts, which is acceptable.
   struct UploadFreqGuard {
     int attempts;
     int daySinceEpoch;
   };
   static UploadFreqGuard sUploadFreqGuard;