Bug 1509135 - Only define UnregisterCallback once r=mrbkap
authorPerry Jiang <proxy@perryjiang.com>
Tue, 27 Nov 2018 00:58:44 +0000
changeset 507434 21bc8b9a89ac7658f85a4f2e0fd278e012f2e32e
parent 507433 02c470cc3f8dcd686cdcda402a514d3c8501ce89
child 507435 d2d2b375ea0aa3b0eddb50428c37e901fa7b90d3
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1509135
milestone65.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 1509135 - Only define UnregisterCallback once r=mrbkap Differential Revision: https://phabricator.services.mozilla.com/D13018
dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp
dom/serviceworkers/ServiceWorkerRegistrationProxy.cpp
dom/serviceworkers/ServiceWorkerUnregisterCallback.cpp
dom/serviceworkers/ServiceWorkerUnregisterCallback.h
dom/serviceworkers/moz.build
--- a/dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp
+++ b/dom/serviceworkers/ServiceWorkerRegistrationImpl.cpp
@@ -21,16 +21,17 @@
 #include "mozilla/Unused.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsNetUtil.h"
 #include "nsServiceManagerUtils.h"
 #include "ServiceWorker.h"
 #include "ServiceWorkerManager.h"
 #include "ServiceWorkerPrivate.h"
 #include "ServiceWorkerRegistration.h"
+#include "ServiceWorkerUnregisterCallback.h"
 
 #include "nsIDocument.h"
 #include "nsIServiceWorkerManager.h"
 #include "nsISupportsPrimitives.h"
 #include "nsPIDOMWindow.h"
 #include "nsContentUtils.h"
 
 namespace mozilla {
@@ -389,54 +390,16 @@ private:
   RefPtr<ThreadSafeWorkerRef> mWorkerRef;
   RefPtr<ServiceWorkerRegistrationPromise::Private> mPromise;
   const ServiceWorkerDescriptor mDescriptor;
   bool mDelayed;
 };
 
 NS_IMPL_ISUPPORTS(SWRUpdateRunnable::TimerCallback, nsITimerCallback)
 
-class UnregisterCallback final : public nsIServiceWorkerUnregisterCallback
-{
-  RefPtr<GenericPromise::Private> mPromise;
-
-public:
-  NS_DECL_ISUPPORTS
-
-  UnregisterCallback()
-    : mPromise(new GenericPromise::Private(__func__))
-  {
-  }
-
-  NS_IMETHOD
-  UnregisterSucceeded(bool aState) override
-  {
-    mPromise->Resolve(aState, __func__);
-    return NS_OK;
-  }
-
-  NS_IMETHOD
-  UnregisterFailed() override
-  {
-    mPromise->Reject(NS_ERROR_DOM_SECURITY_ERR, __func__);
-    return NS_OK;
-  }
-
-  RefPtr<GenericPromise>
-  Promise() const
-  {
-    return mPromise;
-  }
-
-private:
-  ~UnregisterCallback() = default;
-};
-
-NS_IMPL_ISUPPORTS(UnregisterCallback, nsIServiceWorkerUnregisterCallback)
-
 class WorkerUnregisterCallback final : public nsIServiceWorkerUnregisterCallback
 {
   RefPtr<ThreadSafeWorkerRef> mWorkerRef;
   RefPtr<GenericPromise::Private> mPromise;
 public:
   NS_DECL_ISUPPORTS
 
   WorkerUnregisterCallback(RefPtr<ThreadSafeWorkerRef>&& aWorkerRef,
--- a/dom/serviceworkers/ServiceWorkerRegistrationProxy.cpp
+++ b/dom/serviceworkers/ServiceWorkerRegistrationProxy.cpp
@@ -4,16 +4,17 @@
  * 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 "ServiceWorkerRegistrationProxy.h"
 
 #include "mozilla/ipc/BackgroundParent.h"
 #include "ServiceWorkerManager.h"
 #include "ServiceWorkerRegistrationParent.h"
+#include "ServiceWorkerUnregisterCallback.h"
 
 namespace mozilla {
 namespace dom {
 
 using mozilla::ipc::AssertIsOnBackgroundThread;
 
 ServiceWorkerRegistrationProxy::~ServiceWorkerRegistrationProxy()
 {
@@ -165,52 +166,16 @@ ServiceWorkerRegistrationProxy::RevokeAc
   mActor = nullptr;
 
   nsCOMPtr<nsIRunnable> r =
     NewRunnableMethod(__func__, this,
                       &ServiceWorkerRegistrationProxy::StopListeningOnMainThread);
   MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget()));
 }
 
-namespace {
-
-class UnregisterCallback final : public nsIServiceWorkerUnregisterCallback
-{
-  RefPtr<GenericPromise::Private> mPromise;
-
-  ~UnregisterCallback() = default;
-
-public:
-  explicit UnregisterCallback(GenericPromise::Private* aPromise)
-    : mPromise(aPromise)
-  {
-    MOZ_DIAGNOSTIC_ASSERT(mPromise);
-  }
-
-  NS_IMETHOD
-  UnregisterSucceeded(bool aState) override
-  {
-    mPromise->Resolve(aState, __func__);
-    return NS_OK;
-  }
-
-  NS_IMETHOD
-  UnregisterFailed() override
-  {
-    mPromise->Reject(NS_ERROR_DOM_SECURITY_ERR, __func__);
-    return NS_OK;
-  }
-
-  NS_DECL_ISUPPORTS
-};
-
-NS_IMPL_ISUPPORTS(UnregisterCallback, nsIServiceWorkerUnregisterCallback)
-
-} // anonymous namespace
-
 RefPtr<GenericPromise>
 ServiceWorkerRegistrationProxy::Unregister()
 {
   AssertIsOnBackgroundThread();
 
   RefPtr<ServiceWorkerRegistrationProxy> self = this;
   RefPtr<GenericPromise::Private> promise =
     new GenericPromise::Private(__func__);
new file mode 100644
--- /dev/null
+++ b/dom/serviceworkers/ServiceWorkerUnregisterCallback.cpp
@@ -0,0 +1,44 @@
+/* -*- 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 "ServiceWorkerUnregisterCallback.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_ISUPPORTS(UnregisterCallback, nsIServiceWorkerUnregisterCallback)
+
+UnregisterCallback::UnregisterCallback()
+  : mPromise(new GenericPromise::Private(__func__)) {}
+
+UnregisterCallback::UnregisterCallback(GenericPromise::Private* aPromise)
+  : mPromise(aPromise)
+{
+  MOZ_DIAGNOSTIC_ASSERT(mPromise);
+}
+
+NS_IMETHODIMP
+UnregisterCallback::UnregisterSucceeded(bool aState)
+{
+  mPromise->Resolve(aState, __func__);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+UnregisterCallback::UnregisterFailed()
+{
+  mPromise->Reject(NS_ERROR_DOM_SECURITY_ERR, __func__);
+  return NS_OK;
+}
+
+RefPtr<GenericPromise>
+UnregisterCallback::Promise() const
+{
+  return mPromise;
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/serviceworkers/ServiceWorkerUnregisterCallback.h
@@ -0,0 +1,45 @@
+/* -*- 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 mozilla_dom_ServiceWorkerUnregisterCallback_h
+#define mozilla_dom_ServiceWorkerUnregisterCallback_h
+
+#include "mozilla/MozPromise.h"
+#include "mozilla/RefPtr.h"
+#include "nsIServiceWorkerManager.h"
+
+namespace mozilla {
+namespace dom {
+
+class UnregisterCallback final : public nsIServiceWorkerUnregisterCallback
+{
+ public:
+   NS_DECL_ISUPPORTS
+
+   UnregisterCallback();
+
+   explicit UnregisterCallback(GenericPromise::Private* aPromise);
+
+   // nsIServiceWorkerUnregisterCallback implementation
+   NS_IMETHOD
+   UnregisterSucceeded(bool aState) override;
+
+   NS_IMETHOD
+   UnregisterFailed() override;
+
+   RefPtr<GenericPromise>
+   Promise() const;
+
+ private:
+  ~UnregisterCallback() = default;
+
+  RefPtr<GenericPromise::Private> mPromise;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_ServiceWorkerUnregisterCallback_h
--- a/dom/serviceworkers/moz.build
+++ b/dom/serviceworkers/moz.build
@@ -59,16 +59,17 @@ UNIFIED_SOURCES += [
     'ServiceWorkerRegistration.cpp',
     'ServiceWorkerRegistrationChild.cpp',
     'ServiceWorkerRegistrationDescriptor.cpp',
     'ServiceWorkerRegistrationImpl.cpp',
     'ServiceWorkerRegistrationInfo.cpp',
     'ServiceWorkerRegistrationParent.cpp',
     'ServiceWorkerRegistrationProxy.cpp',
     'ServiceWorkerScriptCache.cpp',
+    'ServiceWorkerUnregisterCallback.cpp',
     'ServiceWorkerUnregisterJob.cpp',
     'ServiceWorkerUpdateJob.cpp',
     'ServiceWorkerUpdaterChild.cpp',
     'ServiceWorkerUpdaterParent.cpp',
     'ServiceWorkerUtils.cpp',
 ]
 
 IPDL_SOURCES += [