Bug 1438211 P6 Add an integer identifier to each ServiceWorkerRegistrationDescriptor. r=asuth
authorBen Kelly <ben@wanderview.com>
Fri, 02 Mar 2018 13:02:50 -0800
changeset 407228 43c8c3b917ea
parent 407227 98cfdc9a7826
child 407229 076cd67616db
push id33596
push userncsoregi@mozilla.com
push dateFri, 09 Mar 2018 00:18:11 +0000
treeherdermozilla-central@31a33fc61956 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1438211
milestone60.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 1438211 P6 Add an integer identifier to each ServiceWorkerRegistrationDescriptor. r=asuth
dom/serviceworkers/IPCServiceWorkerRegistrationDescriptor.ipdlh
dom/serviceworkers/ServiceWorkerRegistration.cpp
dom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp
dom/serviceworkers/ServiceWorkerRegistrationDescriptor.h
dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp
dom/serviceworkers/ServiceWorkerRegistrationInfo.h
--- a/dom/serviceworkers/IPCServiceWorkerRegistrationDescriptor.ipdlh
+++ b/dom/serviceworkers/IPCServiceWorkerRegistrationDescriptor.ipdlh
@@ -10,16 +10,18 @@ using ServiceWorkerUpdateViaCache from "
 namespace mozilla {
 namespace dom {
 
 // IPC type with enough information to create a ServiceWorker DOM object
 // in a child process.  Note that the state may be slightly out-of-sync
 // with the parent and should be updated dynamically if necessary.
 struct IPCServiceWorkerRegistrationDescriptor
 {
+  uint64_t id;
+
   // These values should match the principal and scope in each
   // associated worker.  It may be possible to optimize in the future,
   // but for now we duplicate the information here to ensure correctness.
   // Its possible we may need to reference a registration before the
   // worker is installed yet, etc.
   PrincipalInfo principalInfo;
   nsCString scope;
 
--- a/dom/serviceworkers/ServiceWorkerRegistration.cpp
+++ b/dom/serviceworkers/ServiceWorkerRegistration.cpp
@@ -161,17 +161,18 @@ ServiceWorkerRegistration::UpdateState(c
   } else {
     mInstallingWorker = nullptr;
   }
 }
 
 bool
 ServiceWorkerRegistration::MatchesDescriptor(const ServiceWorkerRegistrationDescriptor& aDescriptor) const
 {
-  return aDescriptor.PrincipalInfo() == mDescriptor.PrincipalInfo() &&
+  return aDescriptor.Id() == mDescriptor.Id() &&
+         aDescriptor.PrincipalInfo() == mDescriptor.PrincipalInfo() &&
          aDescriptor.Scope() == mDescriptor.Scope();
 }
 
 void
 ServiceWorkerRegistration::GetScope(nsAString& aScope) const
 {
   CopyUTF8toUTF16(mDescriptor.Scope(), aScope);
 }
--- a/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp
+++ b/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp
@@ -23,36 +23,40 @@ ServiceWorkerRegistrationDescriptor::New
     result.emplace(mData->waiting().get_IPCServiceWorkerDescriptor());
   } else if (mData->active().type() != OptionalIPCServiceWorkerDescriptor::Tvoid_t) {
     result.emplace(mData->active().get_IPCServiceWorkerDescriptor());
   }
   return Move(result);
 }
 
 ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor(
+                                    uint64_t aId,
                                     nsIPrincipal* aPrincipal,
                                     const nsACString& aScope,
                                     ServiceWorkerUpdateViaCache aUpdateViaCache)
   : mData(MakeUnique<IPCServiceWorkerRegistrationDescriptor>())
 {
   MOZ_ALWAYS_SUCCEEDS(
     PrincipalToPrincipalInfo(aPrincipal, &mData->principalInfo()));
 
+  mData->id() = aId;
   mData->scope() = aScope;
   mData->updateViaCache() = aUpdateViaCache;
   mData->installing() = void_t();
   mData->waiting() = void_t();
   mData->active() = void_t();
 }
 
 ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor(
+                                    uint64_t aId,
                                     const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
                                     const nsACString& aScope,
                                     ServiceWorkerUpdateViaCache aUpdateViaCache)
-  : mData(MakeUnique<IPCServiceWorkerRegistrationDescriptor>(aPrincipalInfo,
+  : mData(MakeUnique<IPCServiceWorkerRegistrationDescriptor>(aId,
+                                                             aPrincipalInfo,
                                                              nsCString(aScope),
                                                              aUpdateViaCache,
                                                              void_t(),
                                                              void_t(),
                                                              void_t()))
 {
 }
 
@@ -103,16 +107,22 @@ ServiceWorkerRegistrationDescriptor::~Se
 }
 
 bool
 ServiceWorkerRegistrationDescriptor::operator==(const ServiceWorkerRegistrationDescriptor& aRight) const
 {
   return *mData == *aRight.mData;
 }
 
+uint64_t
+ServiceWorkerRegistrationDescriptor::Id() const
+{
+  return mData->id();
+}
+
 ServiceWorkerUpdateViaCache
 ServiceWorkerRegistrationDescriptor::UpdateViaCache() const
 {
   return mData->updateViaCache();
 }
 
 const mozilla::ipc::PrincipalInfo&
 ServiceWorkerRegistrationDescriptor::PrincipalInfo() const
--- a/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.h
+++ b/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.h
@@ -32,21 +32,23 @@ class ServiceWorkerRegistrationDescripto
   // need the wrapper class since IPDL generated code includes windows.h
   // which is in turn incompatible with bindings code.
   UniquePtr<IPCServiceWorkerRegistrationDescriptor> mData;
 
   Maybe<IPCServiceWorkerDescriptor>
   NewestInternal() const;
 
 public:
-  ServiceWorkerRegistrationDescriptor(nsIPrincipal* aPrincipal,
+  ServiceWorkerRegistrationDescriptor(uint64_t aId,
+                                      nsIPrincipal* aPrincipal,
                                       const nsACString& aScope,
                                       ServiceWorkerUpdateViaCache aUpdateViaCache);
 
-  ServiceWorkerRegistrationDescriptor(const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
+  ServiceWorkerRegistrationDescriptor(uint64_t aId,
+                                      const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
                                       const nsACString& aScope,
                                       ServiceWorkerUpdateViaCache aUpdateViaCache);
 
   explicit ServiceWorkerRegistrationDescriptor(const IPCServiceWorkerRegistrationDescriptor& aDescriptor);
 
   ServiceWorkerRegistrationDescriptor(const ServiceWorkerRegistrationDescriptor& aRight);
 
   ServiceWorkerRegistrationDescriptor&
@@ -57,16 +59,19 @@ public:
   ServiceWorkerRegistrationDescriptor&
   operator=(ServiceWorkerRegistrationDescriptor&& aRight);
 
   ~ServiceWorkerRegistrationDescriptor();
 
   bool
   operator==(const ServiceWorkerRegistrationDescriptor& aRight) const;
 
+  uint64_t
+  Id() const;
+
   ServiceWorkerUpdateViaCache
   UpdateViaCache() const;
 
   const mozilla::ipc::PrincipalInfo&
   PrincipalInfo() const;
 
   const nsCString&
   Scope() const;
--- a/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp
+++ b/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp
@@ -80,17 +80,17 @@ ServiceWorkerRegistrationInfo::Clear()
   NotifyChromeRegistrationListeners();
 }
 
 ServiceWorkerRegistrationInfo::ServiceWorkerRegistrationInfo(
     const nsACString& aScope,
     nsIPrincipal* aPrincipal,
     ServiceWorkerUpdateViaCache aUpdateViaCache)
   : mPrincipal(aPrincipal)
-  , mDescriptor(aPrincipal, aScope, aUpdateViaCache)
+  , mDescriptor(GetNextId(), aPrincipal, aScope, aUpdateViaCache)
   , mControlledClientsCounter(0)
   , mDelayMultiplier(0)
   , mUpdateState(NoUpdate)
   , mCreationTime(PR_Now())
   , mCreationTimeStamp(TimeStamp::Now())
   , mLastUpdateTime(0)
   , mPendingUninstall(false)
 {}
@@ -725,10 +725,19 @@ ServiceWorkerRegistrationInfo::GetUpdate
 
   if (!mControlledClientsCounter && mDelayMultiplier < (INT_MAX / 30)) {
     mDelayMultiplier = (mDelayMultiplier ? mDelayMultiplier : 1) * 30;
   }
 
   return delay;
 }
 
+// static
+uint64_t
+ServiceWorkerRegistrationInfo::GetNextId()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  static uint64_t sNextId = 0;
+  return ++sNextId;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/serviceworkers/ServiceWorkerRegistrationInfo.h
+++ b/dom/serviceworkers/ServiceWorkerRegistrationInfo.h
@@ -224,14 +224,17 @@ private:
   UpdateRegistrationState();
 
   // Used by devtools to track changes to the properties of *nsIServiceWorkerRegistrationInfo*.
   // Note, this doesn't necessarily need to be in sync with the DOM registration objects, but
   // it does need to be called in the same task that changed |mInstallingWorker|,
   // |mWaitingWorker| or |mActiveWorker|.
   void
   NotifyChromeRegistrationListeners();
+
+  static uint64_t
+  GetNextId();
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_serviceworkerregistrationinfo_h