Bug 1286126 - Move ServiceWorker initialization early in the ContentChild startup, r=gabor, a=gchang
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 13 Jul 2016 10:34:24 +0200
changeset 340014 9af7cca3f8b600a85ae8afdd0ead3e6e73345642
parent 340013 6392bfa3a579158561cf39c250e42c33f594b5ad
child 340015 f8b494dbf1ea9c6dca06c6c820ff5160bffccdd7
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor, gchang
bugs1286126
milestone49.0a2
Bug 1286126 - Move ServiceWorker initialization early in the ContentChild startup, r=gabor, a=gchang
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -1086,24 +1086,16 @@ ContentChild::InitXPCOM()
     global->SetInitialProcessData(data);
   }
 
   // This object is held alive by the observer service.
   RefPtr<SystemMessageHandledObserver> sysMsgObserver =
     new SystemMessageHandledObserver();
   sysMsgObserver->Init();
 
-  // Loading the ServiceWorker configuration.
-  ServiceWorkerConfiguration configuration;
-  SendGetServiceWorkerConfiguration(&configuration);
-
-  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
-  MOZ_ASSERT(swm);
-  swm->LoadRegistrations(configuration.serviceWorkerRegistrations());
-
   InitOnContentProcessCreated();
 }
 
 PMemoryReportRequestChild*
 ContentChild::AllocPMemoryReportRequestChild(const uint32_t& aGeneration,
                                              const bool &aAnonymize,
                                              const bool &aMinimizeMemoryUsage,
                                              const MaybeFileDesc& aDMDFile)
@@ -2687,16 +2679,25 @@ ContentChild::RecvAppInit()
     MessageLoop::current()->PostTask(NewRunnableFunction(OnFinishNuwaPreparation));
   }
 #endif
 
   return true;
 }
 
 bool
+ContentChild::RecvInitServiceWorkers(const ServiceWorkerConfiguration& aConfig)
+{
+  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
+  MOZ_ASSERT(swm);
+  swm->LoadRegistrations(aConfig.serviceWorkerRegistrations());
+  return true;
+}
+
+bool
 ContentChild::RecvLastPrivateDocShellDestroyed()
 {
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   obs->NotifyObservers(nullptr, "last-pb-context-exited", nullptr);
   return true;
 }
 
 bool
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -450,16 +450,19 @@ public:
   virtual bool RecvCycleCollect() override;
 
   virtual bool RecvAppInfo(const nsCString& version, const nsCString& buildID,
                            const nsCString& name, const nsCString& UAName,
                            const nsCString& ID, const nsCString& vendor) override;
 
   virtual bool RecvAppInit() override;
 
+  virtual bool
+  RecvInitServiceWorkers(const ServiceWorkerConfiguration& aConfig) override;
+
   virtual bool RecvLastPrivateDocShellDestroyed() override;
 
   virtual bool RecvVolumes(InfallibleTArray<VolumeInfo>&& aVolumes) override;
 
   virtual bool RecvFilePathUpdate(const nsString& aStorageType,
                                   const nsString& aStorageName,
                                   const nsString& aPath,
                                   const nsCString& aReason) override;
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -2633,16 +2633,24 @@ ContentParent::InitInternal(ProcessPrior
   nsID id;
   nsString sessionName;
   nsString iconPath;
   if (NS_SUCCEEDED(mozilla::widget::GetAudioSessionData(id, sessionName,
                                                         iconPath))) {
     Unused << SendSetAudioSessionData(id, sessionName, iconPath);
   }
 #endif
+
+  RefPtr<ServiceWorkerRegistrar> swr = ServiceWorkerRegistrar::Get();
+  MOZ_ASSERT(swr);
+
+  nsTArray<ServiceWorkerRegistrationData> registrations;
+  swr->GetRegistrations(registrations);
+
+  Unused << SendInitServiceWorkers(ServiceWorkerConfiguration(registrations));
 }
 
 bool
 ContentParent::IsAlive() const
 {
   return mIsAlive;
 }
 
@@ -5634,28 +5642,16 @@ ContentParent::PermissionManagerRelease(
   if (appId != nsIScriptSecurityManager::NO_APP_ID && permMgr) {
     permMgr->ReleaseAppId(appId);
     return true;
   }
   return false;
 }
 
 bool
-ContentParent::RecvGetServiceWorkerConfiguration(ServiceWorkerConfiguration* aConfig)
-{
-  MOZ_ASSERT(XRE_IsParentProcess());
-
-  RefPtr<ServiceWorkerRegistrar> swr = ServiceWorkerRegistrar::Get();
-  MOZ_ASSERT(swr);
-
-  swr->GetRegistrations(aConfig->serviceWorkerRegistrations());
-  return true;
-}
-
-bool
 ContentParent::RecvGamepadListenerAdded()
 {
 #ifdef MOZ_GAMEPAD
   if (mHasGamepadListener) {
     NS_WARNING("Gamepad listener already started, cannot start again!");
     return false;
   }
   mHasGamepadListener = true;
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -1138,19 +1138,16 @@ private:
 
   virtual PWebrtcGlobalParent* AllocPWebrtcGlobalParent() override;
   virtual bool DeallocPWebrtcGlobalParent(PWebrtcGlobalParent *aActor) override;
 
 
   virtual bool RecvUpdateDropEffect(const uint32_t& aDragAction,
                                     const uint32_t& aDropEffect) override;
 
-  virtual bool
-  RecvGetServiceWorkerConfiguration(ServiceWorkerConfiguration* aConfig) override;
-
   virtual bool RecvGamepadListenerAdded() override;
 
   virtual bool RecvGamepadListenerRemoved() override;
 
   virtual bool RecvProfile(const nsCString& aProfile) override;
 
   virtual bool RecvGetGraphicsDeviceInitData(DeviceInitData* aOut) override;
 
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -551,16 +551,21 @@ child:
      * Start accessibility engine in content process.
      */
     async ActivateA11y();
 
     async AppInfo(nsCString version, nsCString buildID, nsCString name, nsCString UAName,
                   nsCString ID, nsCString vendor);
     async AppInit();
 
+    /**
+     * Send ServiceWorkerRegistrationData to child process.
+     */
+    async InitServiceWorkers(ServiceWorkerConfiguration aConfig);
+
     // Notify child that last-pb-context-exited notification was observed
     async LastPrivateDocShellDestroyed();
 
     async FilePathUpdate(nsString storageType, nsString storageName, nsString filepath,
                          nsCString reasons);
 
     // Note: Any changes to this structure should also be changed in
     // VolumeInfo above.
@@ -1115,22 +1120,16 @@ parent:
      *
      * NOTE: The principal is untrusted in the parent process. Only
      *       principals that can live in the content process should
      *       provided.
      */
     async PContentPermissionRequest(PermissionRequest[] aRequests, Principal aPrincipal,
                                     TabId tabId);
 
-    /**
-     * Send ServiceWorkerRegistrationData to child process.
-     */
-    sync GetServiceWorkerConfiguration()
-        returns (ServiceWorkerConfiguration aConfig);
-
     /*
      * Tells the parent to start the gamepad listening service if it hasn't already.
      */
     async GamepadListenerAdded();
 
     /**
      * Tells the parent to stop the gamepad listening service if it hasn't already.
      */