Bug 1249438 P1 Move guts of RegisterServiceWorker() into a protected method that can be tested in gtest. r=baku
authorBen Kelly <ben@wanderview.com>
Tue, 29 Mar 2016 07:20:48 -0700
changeset 290933 580604cd40cb0b298287383659035d2ee52d5266
parent 290932 e2ce2fa79b3ad7b73c5664b57184e4365991e75a
child 290934 af6b4f4f55cb0c237c66be379dbd8344725f9136
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1249438
milestone48.0a1
Bug 1249438 P1 Move guts of RegisterServiceWorker() into a protected method that can be tested in gtest. r=baku
dom/workers/ServiceWorkerRegistrar.cpp
dom/workers/ServiceWorkerRegistrar.h
--- a/dom/workers/ServiceWorkerRegistrar.cpp
+++ b/dom/workers/ServiceWorkerRegistrar.cpp
@@ -175,29 +175,17 @@ ServiceWorkerRegistrar::RegisterServiceW
   if (mShuttingDown) {
     NS_WARNING("Failed to register a serviceWorker during shutting down.");
     return;
   }
 
   {
     MonitorAutoLock lock(mMonitor);
     MOZ_ASSERT(mDataLoaded);
-
-    bool found = false;
-    for (uint32_t i = 0, len = mData.Length(); i < len; ++i) {
-      if (Equivalent(aData, mData[i])) {
-        mData[i] = aData;
-        found = true;
-        break;
-      }
-    }
-
-    if (!found) {
-      mData.AppendElement(aData);
-    }
+    RegisterServiceWorkerInternal(aData);
   }
 
   ScheduleSaveData();
 }
 
 void
 ServiceWorkerRegistrar::UnregisterServiceWorker(
                                             const PrincipalInfo& aPrincipalInfo,
@@ -511,16 +499,33 @@ ServiceWorkerRegistrar::DeleteData()
     return;
   }
 
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 }
 
+void
+ServiceWorkerRegistrar::RegisterServiceWorkerInternal(const ServiceWorkerRegistrationData& aData)
+{
+  bool found = false;
+  for (uint32_t i = 0, len = mData.Length(); i < len; ++i) {
+    if (Equivalent(aData, mData[i])) {
+      mData[i] = aData;
+      found = true;
+      break;
+    }
+  }
+
+  if (!found) {
+    mData.AppendElement(aData);
+  }
+}
+
 class ServiceWorkerRegistrarSaveDataRunnable final : public nsRunnable
 {
 public:
   ServiceWorkerRegistrarSaveDataRunnable()
     : mThread(do_GetCurrentThread())
   {
     AssertIsOnBackgroundThread();
   }
--- a/dom/workers/ServiceWorkerRegistrar.h
+++ b/dom/workers/ServiceWorkerRegistrar.h
@@ -61,16 +61,18 @@ protected:
   // subclassing it.
   void LoadData();
   void SaveData();
 
   nsresult ReadData();
   nsresult WriteData();
   void DeleteData();
 
+  void RegisterServiceWorkerInternal(const ServiceWorkerRegistrationData& aData);
+
   ServiceWorkerRegistrar();
   virtual ~ServiceWorkerRegistrar();
 
 private:
   void ProfileStarted();
   void ProfileStopped();
 
   void ScheduleSaveData();