Bug 1459209 P7 Scaffold a ServiceWorkerContainerProxy class to connect the parent actor to the main thread SWM. r=mrbkap
authorBen Kelly <ben@wanderview.com>
Mon, 09 Jul 2018 16:02:40 -0700
changeset 425710 6503e9d70bf5ac804d023a88915f7c4429ab7c65
parent 425709 e50b0e9556281d0d4b6f0b2c94d2d6efc50aeb24
child 425711 c5328bc15a3fe38059e1e8a7fac3a23d5c0f438c
push id34262
push usercsabou@mozilla.com
push dateTue, 10 Jul 2018 21:51:50 +0000
treeherdermozilla-central@70f901964f97 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1459209
milestone63.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 1459209 P7 Scaffold a ServiceWorkerContainerProxy class to connect the parent actor to the main thread SWM. r=mrbkap
dom/serviceworkers/ServiceWorkerContainerParent.cpp
dom/serviceworkers/ServiceWorkerContainerParent.h
dom/serviceworkers/ServiceWorkerContainerProxy.cpp
dom/serviceworkers/ServiceWorkerContainerProxy.h
dom/serviceworkers/moz.build
--- a/dom/serviceworkers/ServiceWorkerContainerParent.cpp
+++ b/dom/serviceworkers/ServiceWorkerContainerParent.cpp
@@ -1,34 +1,48 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "mozilla/dom/PServiceWorkerContainerParent.h"
+#include "ServiceWorkerContainerParent.h"
+
+#include "ServiceWorkerContainerProxy.h"
 
 namespace mozilla {
 namespace dom {
 
 using mozilla::ipc::IPCResult;
 
 void
 ServiceWorkerContainerParent::ActorDestroy(ActorDestroyReason aReason)
 {
-  // TODO
+  if (mProxy) {
+    mProxy->RevokeActor(this);
+    mProxy = nullptr;
+  }
 }
 
 IPCResult
 ServiceWorkerContainerParent::RecvTeardown()
 {
-  // TODO
+  Unused << Send__delete__(this);
   return IPC_OK();
 }
 
+ServiceWorkerContainerParent::ServiceWorkerContainerParent()
+{
+}
+
+ServiceWorkerContainerParent::~ServiceWorkerContainerParent()
+{
+  MOZ_DIAGNOSTIC_ASSERT(!mProxy);
+}
+
 void
 ServiceWorkerContainerParent::Init()
 {
-  // TODO
+  mProxy = new ServiceWorkerContainerProxy(this);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/serviceworkers/ServiceWorkerContainerParent.h
+++ b/dom/serviceworkers/ServiceWorkerContainerParent.h
@@ -8,29 +8,32 @@
 #define mozilla_dom_serviceworkercontainerparent_h__
 
 #include "mozilla/dom/PServiceWorkerContainerParent.h"
 
 namespace mozilla {
 namespace dom {
 
 class IPCServiceWorkerDescriptor;
+class ServiceWorkerContainerProxy;
 
 class ServiceWorkerContainerParent final : public PServiceWorkerContainerParent
 {
+  RefPtr<ServiceWorkerContainerProxy> mProxy;
+
   // PServiceWorkerContainerParent
   void
   ActorDestroy(ActorDestroyReason aReason) override;
 
   mozilla::ipc::IPCResult
   RecvTeardown() override;
 
 public:
-  ServiceWorkerContainerParent() = default;
-  ~ServiceWorkerContainerParent() = default;
+  ServiceWorkerContainerParent();
+  ~ServiceWorkerContainerParent();
 
   void
   Init();
 };
 
 } // namespace dom
 } // namespace mozilla
 
new file mode 100644
--- /dev/null
+++ b/dom/serviceworkers/ServiceWorkerContainerProxy.cpp
@@ -0,0 +1,43 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "ServiceWorkerContainerProxy.h"
+
+#include "mozilla/ipc/BackgroundParent.h"
+
+namespace mozilla {
+namespace dom {
+
+using mozilla::ipc::AssertIsOnBackgroundThread;
+
+ServiceWorkerContainerProxy::~ServiceWorkerContainerProxy()
+{
+  // Any thread
+  MOZ_DIAGNOSTIC_ASSERT(!mActor);
+}
+
+ServiceWorkerContainerProxy::ServiceWorkerContainerProxy(ServiceWorkerContainerParent* aActor)
+  : mActor(aActor)
+{
+  AssertIsOnBackgroundThread();
+  MOZ_DIAGNOSTIC_ASSERT(mActor);
+
+  // The container does not directly listen for updates, so we don't need
+  // to immediately initialize.  The controllerchange event comes via the
+  // ClientSource associated with the ServiceWorkerContainer's bound global.
+}
+
+void
+ServiceWorkerContainerProxy::RevokeActor(ServiceWorkerContainerParent* aActor)
+{
+  AssertIsOnBackgroundThread();
+  MOZ_DIAGNOSTIC_ASSERT(mActor);
+  MOZ_DIAGNOSTIC_ASSERT(mActor == aActor);
+  mActor = nullptr;
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/serviceworkers/ServiceWorkerContainerProxy.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef moz_dom_ServiceWorkerContainerProxy_h
+#define moz_dom_ServiceWorkerContainerProxy_h
+
+namespace mozilla {
+namespace dom {
+
+class ServiceWorkerContainerParent;
+
+class ServiceWorkerContainerProxy final
+{
+  // Background thread only
+  ServiceWorkerContainerParent* mActor;
+
+  ~ServiceWorkerContainerProxy();
+
+public:
+  explicit ServiceWorkerContainerProxy(ServiceWorkerContainerParent* aActor);
+
+  void
+  RevokeActor(ServiceWorkerContainerParent* aActor);
+
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerContainerProxy);
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // moz_dom_ServiceWorkerContainerProxy_h
--- a/dom/serviceworkers/moz.build
+++ b/dom/serviceworkers/moz.build
@@ -34,16 +34,17 @@ UNIFIED_SOURCES += [
     'ServiceWorker.cpp',
     'ServiceWorkerActors.cpp',
     'ServiceWorkerChild.cpp',
     'ServiceWorkerCloneData.cpp',
     'ServiceWorkerContainer.cpp',
     'ServiceWorkerContainerChild.cpp',
     'ServiceWorkerContainerImpl.cpp',
     'ServiceWorkerContainerParent.cpp',
+    'ServiceWorkerContainerProxy.cpp',
     'ServiceWorkerDescriptor.cpp',
     'ServiceWorkerEvents.cpp',
     'ServiceWorkerImpl.cpp',
     'ServiceWorkerInfo.cpp',
     'ServiceWorkerInterceptController.cpp',
     'ServiceWorkerJob.cpp',
     'ServiceWorkerJobQueue.cpp',
     'ServiceWorkerManager.cpp',