Bug 1251238 - Part 5: Store installed/activated time for a service worker and last updated time for a service worker's registration into serviceWorkerRegistrar. r=bkelly
authorTom Tung <shes050117@gmail.com>
Wed, 05 Apr 2017 09:59:48 +0800
changeset 353093 9e42a7e438e95180d82e6173b191db95f81b1983
parent 353092 35fafa7f1a8dde638c456b3c328c0d66682c7e74
child 353094 3bb85700229ed20029a8ddeae2c68d39762edee7
push id31656
push userihsiao@mozilla.com
push dateFri, 14 Apr 2017 09:10:41 +0000
treeherdermozilla-central@cda24082bff8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1251238
milestone55.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 1251238 - Part 5: Store installed/activated time for a service worker and last updated time for a service worker's registration into serviceWorkerRegistrar. r=bkelly
dom/workers/ServiceWorkerInfo.h
dom/workers/ServiceWorkerManager.cpp
dom/workers/ServiceWorkerRegistrar.cpp
dom/workers/ServiceWorkerRegistrar.h
dom/workers/ServiceWorkerRegistrarTypes.ipdlh
dom/workers/ServiceWorkerRegistrationInfo.cpp
dom/workers/ServiceWorkerRegistrationInfo.h
--- a/dom/workers/ServiceWorkerInfo.h
+++ b/dom/workers/ServiceWorkerInfo.h
@@ -187,15 +187,47 @@ public:
   void
   UpdateInstalledTime();
 
   void
   UpdateActivatedTime();
 
   void
   UpdateRedundantTime();
+
+  int64_t
+  GetInstalledTime() const
+  {
+    return mInstalledTime;
+  }
+
+  void
+  SetInstalledTime(const int64_t aTime)
+  {
+    if (aTime == 0) {
+      return;
+    }
+
+    mInstalledTime = aTime;
+  }
+
+  int64_t
+  GetActivatedTime() const
+  {
+    return mActivatedTime;
+  }
+
+  void
+  SetActivatedTime(const int64_t aTime)
+  {
+    if (aTime == 0) {
+      return;
+    }
+
+    mActivatedTime = aTime;
+  }
 };
 
 } // namespace workers
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_workers_serviceworkerinfo_h
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -182,20 +182,27 @@ PopulateRegistrationData(nsIPrincipal* a
   if (NS_WARN_IF(!newest)) {
     return NS_ERROR_FAILURE;
   }
 
   if (aRegistration->GetActive()) {
     aData.currentWorkerURL() = aRegistration->GetActive()->ScriptSpec();
     aData.cacheName() = aRegistration->GetActive()->CacheName();
     aData.currentWorkerHandlesFetch() = aRegistration->GetActive()->HandlesFetch();
+
+    aData.currentWorkerInstalledTime() =
+      aRegistration->GetActive()->GetInstalledTime();
+    aData.currentWorkerActivatedTime() =
+      aRegistration->GetActive()->GetActivatedTime();
   }
 
   aData.loadFlags() = aRegistration->GetLoadFlags();
 
+  aData.lastUpdateTime() = aRegistration->GetLastUpdateTime();
+
   return NS_OK;
 }
 
 class TeardownRunnable final : public Runnable
 {
 public:
   explicit TeardownRunnable(ServiceWorkerManagerChild* aActor)
     : mActor(aActor)
@@ -2019,25 +2026,29 @@ ServiceWorkerManager::LoadRegistration(
     // the CacheName is an UUID generated when a new script is found.
     if (registration->GetActive() &&
         registration->GetActive()->CacheName() == aRegistration.cacheName()) {
       // No needs for updates.
       return;
     }
   }
 
+  registration->SetLastUpdateTime(aRegistration.lastUpdateTime());
+
   const nsCString& currentWorkerURL = aRegistration.currentWorkerURL();
   if (!currentWorkerURL.IsEmpty()) {
     registration->SetActive(
       new ServiceWorkerInfo(registration->mPrincipal,
                             registration->mScope,
                             currentWorkerURL,
                             aRegistration.cacheName(),
                             registration->GetLoadFlags()));
     registration->GetActive()->SetHandlesFetch(aRegistration.currentWorkerHandlesFetch());
+    registration->GetActive()->SetInstalledTime(aRegistration.currentWorkerInstalledTime());
+    registration->GetActive()->SetActivatedTime(aRegistration.currentWorkerActivatedTime());
   }
 }
 
 void
 ServiceWorkerManager::LoadRegistrations(
                   const nsTArray<ServiceWorkerRegistrationData>& aRegistrations)
 {
   AssertIsOnMainThread();
--- a/dom/workers/ServiceWorkerRegistrar.cpp
+++ b/dom/workers/ServiceWorkerRegistrar.cpp
@@ -36,16 +36,17 @@ using namespace mozilla::ipc;
 
 namespace mozilla {
 namespace dom {
 
 namespace {
 
 static const char* gSupportedRegistrarVersions[] = {
   SERVICEWORKERREGISTRAR_VERSION,
+  "6",
   "5",
   "4",
   "3",
   "2"
 };
 
 StaticRefPtr<ServiceWorkerRegistrar> gServiceWorkerRegistrar;
 
@@ -375,16 +376,82 @@ ServiceWorkerRegistrar::ReadData()
       GET_LINE(loadFlags);
       entry->loadFlags() = loadFlags.ToInteger(&rv, 16);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       } else if (entry->loadFlags() != nsIRequest::LOAD_NORMAL &&
                  entry->loadFlags() != nsIRequest::VALIDATE_ALWAYS) {
         return NS_ERROR_INVALID_ARG;
       }
+
+      nsAutoCString installedTimeStr;
+      GET_LINE(installedTimeStr);
+      int64_t installedTime = installedTimeStr.ToInteger64(&rv);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+      entry->currentWorkerInstalledTime() = installedTime;
+
+      nsAutoCString activatedTimeStr;
+      GET_LINE(activatedTimeStr);
+      int64_t activatedTime = activatedTimeStr.ToInteger64(&rv);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+      entry->currentWorkerActivatedTime() = activatedTime;
+
+      nsAutoCString lastUpdateTimeStr;
+      GET_LINE(lastUpdateTimeStr);
+      int64_t lastUpdateTime = lastUpdateTimeStr.ToInteger64(&rv);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+      entry->lastUpdateTime() = lastUpdateTime;
+    } else if (version.EqualsLiteral("6")) {
+      nsAutoCString suffix;
+      GET_LINE(suffix);
+
+      OriginAttributes attrs;
+      if (!attrs.PopulateFromSuffix(suffix)) {
+        return NS_ERROR_INVALID_ARG;
+      }
+
+      GET_LINE(entry->scope());
+
+      entry->principal() =
+        mozilla::ipc::ContentPrincipalInfo(attrs, void_t(), entry->scope());
+
+      GET_LINE(entry->currentWorkerURL());
+
+      nsAutoCString fetchFlag;
+      GET_LINE(fetchFlag);
+      if (!fetchFlag.EqualsLiteral(SERVICEWORKERREGISTRAR_TRUE) &&
+          !fetchFlag.EqualsLiteral(SERVICEWORKERREGISTRAR_FALSE)) {
+        return NS_ERROR_INVALID_ARG;
+      }
+      entry->currentWorkerHandlesFetch() =
+        fetchFlag.EqualsLiteral(SERVICEWORKERREGISTRAR_TRUE);
+
+      nsAutoCString cacheName;
+      GET_LINE(cacheName);
+      CopyUTF8toUTF16(cacheName, entry->cacheName());
+
+      nsAutoCString loadFlags;
+      GET_LINE(loadFlags);
+      entry->loadFlags() = loadFlags.ToInteger(&rv, 16);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      } else if (entry->loadFlags() != nsIRequest::LOAD_NORMAL &&
+                 entry->loadFlags() != nsIRequest::VALIDATE_ALWAYS) {
+        return NS_ERROR_INVALID_ARG;
+      }
+
+      entry->currentWorkerInstalledTime() = 0;
+      entry->currentWorkerActivatedTime() = 0;
+      entry->lastUpdateTime() = 0;
     } else if (version.EqualsLiteral("5")) {
       overwrite = true;
       dedupe = true;
 
       nsAutoCString suffix;
       GET_LINE(suffix);
 
       OriginAttributes attrs;
@@ -408,16 +475,20 @@ ServiceWorkerRegistrar::ReadData()
       entry->currentWorkerHandlesFetch() =
         fetchFlag.EqualsLiteral(SERVICEWORKERREGISTRAR_TRUE);
 
       nsAutoCString cacheName;
       GET_LINE(cacheName);
       CopyUTF8toUTF16(cacheName, entry->cacheName());
 
       entry->loadFlags() = nsIRequest::VALIDATE_ALWAYS;
+
+      entry->currentWorkerInstalledTime() = 0;
+      entry->currentWorkerActivatedTime() = 0;
+      entry->lastUpdateTime() = 0;
     } else if (version.EqualsLiteral("4")) {
       overwrite = true;
       dedupe = true;
 
       nsAutoCString suffix;
       GET_LINE(suffix);
 
       OriginAttributes attrs;
@@ -435,16 +506,20 @@ ServiceWorkerRegistrar::ReadData()
       // default handlesFetch flag to Enabled
       entry->currentWorkerHandlesFetch() = true;
 
       nsAutoCString cacheName;
       GET_LINE(cacheName);
       CopyUTF8toUTF16(cacheName, entry->cacheName());
 
       entry->loadFlags() = nsIRequest::VALIDATE_ALWAYS;
+
+      entry->currentWorkerInstalledTime() = 0;
+      entry->currentWorkerActivatedTime() = 0;
+      entry->lastUpdateTime() = 0;
     } else if (version.EqualsLiteral("3")) {
       overwrite = true;
       dedupe = true;
 
       nsAutoCString suffix;
       GET_LINE(suffix);
 
       OriginAttributes attrs;
@@ -465,16 +540,20 @@ ServiceWorkerRegistrar::ReadData()
       // default handlesFetch flag to Enabled
       entry->currentWorkerHandlesFetch() = true;
 
       nsAutoCString cacheName;
       GET_LINE(cacheName);
       CopyUTF8toUTF16(cacheName, entry->cacheName());
 
       entry->loadFlags() = nsIRequest::VALIDATE_ALWAYS;
+
+      entry->currentWorkerInstalledTime() = 0;
+      entry->currentWorkerActivatedTime() = 0;
+      entry->lastUpdateTime() = 0;
     } else if (version.EqualsLiteral("2")) {
       overwrite = true;
       dedupe = true;
 
       nsAutoCString suffix;
       GET_LINE(suffix);
 
       OriginAttributes attrs;
@@ -501,16 +580,20 @@ ServiceWorkerRegistrar::ReadData()
       nsAutoCString cacheName;
       GET_LINE(cacheName);
       CopyUTF8toUTF16(cacheName, entry->cacheName());
 
       // waitingCacheName is no more used in latest version.
       GET_LINE(unused);
 
       entry->loadFlags() = nsIRequest::VALIDATE_ALWAYS;
+
+      entry->currentWorkerInstalledTime() = 0;
+      entry->currentWorkerActivatedTime() = 0;
+      entry->lastUpdateTime() = 0;
     } else {
       MOZ_ASSERT_UNREACHABLE("Should never get here!");
     }
 
 #undef GET_LINE
 
     rv = lineInputStream->ReadLine(line, &hasMoreLines);
     if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -817,16 +900,25 @@ ServiceWorkerRegistrar::WriteData()
     MOZ_DIAGNOSTIC_ASSERT(data[i].loadFlags() == nsIRequest::LOAD_NORMAL ||
                           data[i].loadFlags() == nsIRequest::VALIDATE_ALWAYS);
 
     static_assert(nsIRequest::LOAD_NORMAL == 0,
                   "LOAD_NORMAL matches serialized value.");
     static_assert(nsIRequest::VALIDATE_ALWAYS == (1 << 11),
                   "VALIDATE_ALWAYS matches serialized value");
 
+    buffer.AppendInt(data[i].currentWorkerInstalledTime());
+    buffer.Append('\n');
+
+    buffer.AppendInt(data[i].currentWorkerActivatedTime());
+    buffer.Append('\n');
+
+    buffer.AppendInt(data[i].lastUpdateTime());
+    buffer.Append('\n');
+
     buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR);
     buffer.Append('\n');
 
     rv = stream->Write(buffer.Data(), buffer.Length(), &count);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
--- a/dom/workers/ServiceWorkerRegistrar.h
+++ b/dom/workers/ServiceWorkerRegistrar.h
@@ -11,17 +11,17 @@
 #include "mozilla/Telemetry.h"
 #include "nsClassHashtable.h"
 #include "nsIObserver.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsTArray.h"
 
 #define SERVICEWORKERREGISTRAR_FILE "serviceworker.txt"
-#define SERVICEWORKERREGISTRAR_VERSION "6"
+#define SERVICEWORKERREGISTRAR_VERSION "7"
 #define SERVICEWORKERREGISTRAR_TERMINATOR "#"
 #define SERVICEWORKERREGISTRAR_TRUE "true"
 #define SERVICEWORKERREGISTRAR_FALSE "false"
 
 class nsIFile;
 
 namespace mozilla {
 
--- a/dom/workers/ServiceWorkerRegistrarTypes.ipdlh
+++ b/dom/workers/ServiceWorkerRegistrarTypes.ipdlh
@@ -15,12 +15,16 @@ struct ServiceWorkerRegistrationData
   nsCString currentWorkerURL;
   bool currentWorkerHandlesFetch;
 
   nsString cacheName;
 
   PrincipalInfo principal;
 
   uint32_t loadFlags;
+
+  int64_t currentWorkerInstalledTime;
+  int64_t currentWorkerActivatedTime;
+  int64_t lastUpdateTime;
 };
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/workers/ServiceWorkerRegistrationInfo.cpp
+++ b/dom/workers/ServiceWorkerRegistrationInfo.cpp
@@ -630,9 +630,25 @@ ServiceWorkerRegistrationInfo::GetLoadFl
 }
 
 void
 ServiceWorkerRegistrationInfo::SetLoadFlags(nsLoadFlags aLoadFlags)
 {
   mLoadFlags = aLoadFlags;
 }
 
+int64_t
+ServiceWorkerRegistrationInfo::GetLastUpdateTime() const
+{
+  return mLastUpdateTime;
+}
+
+void
+ServiceWorkerRegistrationInfo::SetLastUpdateTime(const int64_t aTime)
+{
+  if (aTime == 0) {
+    return;
+  }
+
+  mLastUpdateTime = aTime;
+}
+
 END_WORKERS_NAMESPACE
--- a/dom/workers/ServiceWorkerRegistrationInfo.h
+++ b/dom/workers/ServiceWorkerRegistrationInfo.h
@@ -186,16 +186,22 @@ public:
   IsIdle() const;
 
   nsLoadFlags
   GetLoadFlags() const;
 
   void
   SetLoadFlags(nsLoadFlags aLoadFlags);
 
+  int64_t
+  GetLastUpdateTime() const;
+
+  void
+  SetLastUpdateTime(const int64_t aTime);
+
 private:
   enum TransitionType {
     TransitionToNextState = 0,
     Invalidate
   };
 
   // Queued as a runnable from UpdateRegistrationStateProperties.
   void