Bug 1251238 - Part 6: Merge mLastUpdateCheckTime and mLastUpdateTime. r=bkelly
authorTom Tung <shes050117@gmail.com>
Thu, 06 Apr 2017 10:39:52 +0800
changeset 353094 3bb85700229ed20029a8ddeae2c68d39762edee7
parent 353093 9e42a7e438e95180d82e6173b191db95f81b1983
child 353095 8f3b554401e8b030221981cbb218c085c34601da
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 6: Merge mLastUpdateCheckTime and mLastUpdateTime. r=bkelly
dom/workers/ServiceWorkerRegistrationInfo.cpp
dom/workers/ServiceWorkerRegistrationInfo.h
--- a/dom/workers/ServiceWorkerRegistrationInfo.cpp
+++ b/dom/workers/ServiceWorkerRegistrationInfo.cpp
@@ -80,17 +80,16 @@ ServiceWorkerRegistrationInfo::Clear()
 ServiceWorkerRegistrationInfo::ServiceWorkerRegistrationInfo(const nsACString& aScope,
                                                              nsIPrincipal* aPrincipal,
                                                              nsLoadFlags aLoadFlags)
   : mControlledDocumentsCounter(0)
   , mUpdateState(NoUpdate)
   , mCreationTime(PR_Now())
   , mCreationTimeStamp(TimeStamp::Now())
   , mLastUpdateTime(0)
-  , mLastUpdateCheckTime(0)
   , mLoadFlags(aLoadFlags)
   , mScope(aScope)
   , mPrincipal(aPrincipal)
   , mPendingUninstall(false)
 {}
 
 ServiceWorkerRegistrationInfo::~ServiceWorkerRegistrationInfo()
 {
@@ -310,17 +309,16 @@ ServiceWorkerRegistrationInfo::FinishAct
   }
   swm->StoreRegistration(mPrincipal, this);
 }
 
 void
 ServiceWorkerRegistrationInfo::RefreshLastUpdateCheckTime()
 {
   AssertIsOnMainThread();
-  mLastUpdateCheckTime = PR_IntervalNow() / PR_MSEC_PER_SEC;
 
   mLastUpdateTime =
     mCreationTime + static_cast<PRTime>((TimeStamp::Now() -
                                          mCreationTimeStamp).ToMicroseconds());
   NotifyChromeRegistrationListeners();
 }
 
 bool
@@ -328,20 +326,25 @@ ServiceWorkerRegistrationInfo::IsLastUpd
 {
   AssertIsOnMainThread();
 
   // For testing.
   if (Preferences::GetBool("dom.serviceWorkers.testUpdateOverOneDay")) {
     return true;
   }
 
-  const uint64_t kSecondsPerDay = 86400;
-  const uint64_t now = PR_IntervalNow() / PR_MSEC_PER_SEC;
+  const int64_t kSecondsPerDay = 86400;
+  const int64_t now =
+    mCreationTime + static_cast<PRTime>((TimeStamp::Now() -
+                                         mCreationTimeStamp).ToMicroseconds());
 
-  if ((now - mLastUpdateCheckTime) > kSecondsPerDay) {
+  // now < mLastUpdateTime if the system time is reset between storing
+  // and loading mLastUpdateTime from ServiceWorkerRegistrar.
+  if (now < mLastUpdateTime ||
+      (now - mLastUpdateTime) / PR_MSEC_PER_SEC > kSecondsPerDay) {
     return true;
   }
   return false;
 }
 
 void
 ServiceWorkerRegistrationInfo::AsyncUpdateRegistrationStateProperties(WhichServiceWorker aWorker,
                                                                       TransitionType aTransition)
--- a/dom/workers/ServiceWorkerRegistrationInfo.h
+++ b/dom/workers/ServiceWorkerRegistrationInfo.h
@@ -26,18 +26,16 @@ class ServiceWorkerRegistrationInfo fina
   } mUpdateState;
 
   // Timestamp to track SWR's last update time
   PRTime mCreationTime;
   TimeStamp mCreationTimeStamp;
   // The time of update is 0, if SWR've never been updated yet.
   PRTime mLastUpdateTime;
 
-  uint64_t mLastUpdateCheckTime;
-
   nsLoadFlags mLoadFlags;
 
   RefPtr<ServiceWorkerInfo> mEvaluatingWorker;
   RefPtr<ServiceWorkerInfo> mActiveWorker;
   RefPtr<ServiceWorkerInfo> mWaitingWorker;
   RefPtr<ServiceWorkerInfo> mInstallingWorker;
 
   virtual ~ServiceWorkerRegistrationInfo();