Bug 1232444 Only store service worker registrations after install is successful. r=baku
authorBen Kelly <ben@wanderview.com>
Fri, 18 Dec 2015 11:04:40 -0500
changeset 277033 a6428efb2c020292d63fe2fa58071a471969ce65
parent 277032 0a595c83b21f9f1944fef016100daa61c6aefbaf
child 277034 4c71bfbcbaee35f9ee5fb8f1b7554dcbed30c388
push id16724
push usercbook@mozilla.com
push dateMon, 21 Dec 2015 11:00:52 +0000
treeherderfx-team@3f3f0361567c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1232444
milestone46.0a1
Bug 1232444 Only store service worker registrations after install is successful. r=baku
dom/workers/ServiceWorkerManager.cpp
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -1237,16 +1237,17 @@ public:
       if (NS_FAILED(rv)) {
         NS_WARNING("Failed to purge the old waiting cache.");
       }
     }
 
     mRegistration->mWaitingWorker = mRegistration->mInstallingWorker.forget();
     mRegistration->mWaitingWorker->UpdateState(ServiceWorkerState::Installed);
     mRegistration->NotifyListenersOnChange();
+    swm->StoreRegistration(mPrincipal, mRegistration);
     swm->InvalidateServiceWorkerRegistrationWorker(mRegistration,
                                                    WhichServiceWorker::INSTALLING_WORKER | WhichServiceWorker::WAITING_WORKER);
 
     // "If registration's waiting worker's skip waiting flag is set"
     if (mRegistration->mWaitingWorker->SkipWaitingFlag()) {
       mRegistration->PurgeActiveWorker();
     }
 
@@ -1317,34 +1318,31 @@ public:
     if (mJobType == RegisterJob) {
       MOZ_ASSERT(!mRegistration);
       mRegistration = swm->GetRegistration(mPrincipal, mScope);
 
       if (mRegistration) {
         mRegistration->mPendingUninstall = false;
         RefPtr<ServiceWorkerInfo> newest = mRegistration->Newest();
         if (newest && mScriptSpec.Equals(newest->ScriptSpec())) {
-          swm->StoreRegistration(mPrincipal, mRegistration);
           Succeed();
 
           // Done() must always be called async from Start()
           nsCOMPtr<nsIRunnable> runnable =
             NS_NewRunnableMethodWithArg<nsresult>(
               this,
               &ServiceWorkerRegisterJob::Done,
               NS_OK);
           MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToCurrentThread(runnable)));
 
           return;
         }
       } else {
         mRegistration = swm->CreateNewRegistration(mScope, mPrincipal);
       }
-
-      swm->StoreRegistration(mPrincipal, mRegistration);
     } else {
       MOZ_ASSERT(mJobType == UpdateJob);
 
       nsresult rv = EnsureAndVerifyRegistration();
       if (NS_WARN_IF(NS_FAILED(rv))) {
         // Do nothing here, but since mRegistration is nullptr we will
         // trigger the async Fail() call below.
         MOZ_ASSERT(!mRegistration);