From 94f26a8af05d8a579bb5719387e1e39b8410e6e3 Mon Sep 17 00:00:00 2001 From: Tom Tung Date: Wed, 5 Apr 2017 09:59:48 +0800 Subject: [PATCH] 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 --HG-- extra : rebase_source : 6c4350a972ae396388b6bbae8a139e27dcf8fa6c --- dom/workers/ServiceWorkerInfo.h | 32 +++++++ dom/workers/ServiceWorkerManager.cpp | 11 +++ dom/workers/ServiceWorkerRegistrar.cpp | 92 +++++++++++++++++++ dom/workers/ServiceWorkerRegistrar.h | 2 +- dom/workers/ServiceWorkerRegistrarTypes.ipdlh | 4 + dom/workers/ServiceWorkerRegistrationInfo.cpp | 16 ++++ dom/workers/ServiceWorkerRegistrationInfo.h | 6 ++ 7 files changed, 162 insertions(+), 1 deletion(-) diff --git a/dom/workers/ServiceWorkerInfo.h b/dom/workers/ServiceWorkerInfo.h index 8553a87eac5a..0dceabefcd11 100644 --- a/dom/workers/ServiceWorkerInfo.h +++ b/dom/workers/ServiceWorkerInfo.h @@ -192,6 +192,38 @@ public: 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 diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index c7ec50eca1b5..bef622659dc3 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -187,10 +187,17 @@ PopulateRegistrationData(nsIPrincipal* aPrincipal, 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; } @@ -2024,6 +2031,8 @@ ServiceWorkerManager::LoadRegistration( } } + registration->SetLastUpdateTime(aRegistration.lastUpdateTime()); + const nsCString& currentWorkerURL = aRegistration.currentWorkerURL(); if (!currentWorkerURL.IsEmpty()) { registration->SetActive( @@ -2033,6 +2042,8 @@ ServiceWorkerManager::LoadRegistration( aRegistration.cacheName(), registration->GetLoadFlags())); registration->GetActive()->SetHandlesFetch(aRegistration.currentWorkerHandlesFetch()); + registration->GetActive()->SetInstalledTime(aRegistration.currentWorkerInstalledTime()); + registration->GetActive()->SetActivatedTime(aRegistration.currentWorkerActivatedTime()); } } diff --git a/dom/workers/ServiceWorkerRegistrar.cpp b/dom/workers/ServiceWorkerRegistrar.cpp index c1fce972814d..6118c71bae32 100644 --- a/dom/workers/ServiceWorkerRegistrar.cpp +++ b/dom/workers/ServiceWorkerRegistrar.cpp @@ -41,6 +41,7 @@ namespace { static const char* gSupportedRegistrarVersions[] = { SERVICEWORKERREGISTRAR_VERSION, + "6", "5", "4", "3", @@ -380,6 +381,72 @@ ServiceWorkerRegistrar::ReadData() 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; @@ -413,6 +480,10 @@ ServiceWorkerRegistrar::ReadData() 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; @@ -440,6 +511,10 @@ ServiceWorkerRegistrar::ReadData() 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; @@ -470,6 +545,10 @@ ServiceWorkerRegistrar::ReadData() 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; @@ -506,6 +585,10 @@ ServiceWorkerRegistrar::ReadData() 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!"); } @@ -822,6 +905,15 @@ ServiceWorkerRegistrar::WriteData() 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'); diff --git a/dom/workers/ServiceWorkerRegistrar.h b/dom/workers/ServiceWorkerRegistrar.h index 01b572594ac2..e18eb74a80f5 100644 --- a/dom/workers/ServiceWorkerRegistrar.h +++ b/dom/workers/ServiceWorkerRegistrar.h @@ -16,7 +16,7 @@ #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" diff --git a/dom/workers/ServiceWorkerRegistrarTypes.ipdlh b/dom/workers/ServiceWorkerRegistrarTypes.ipdlh index 3e2fe97a36b4..ad77af34ea64 100644 --- a/dom/workers/ServiceWorkerRegistrarTypes.ipdlh +++ b/dom/workers/ServiceWorkerRegistrarTypes.ipdlh @@ -20,6 +20,10 @@ struct ServiceWorkerRegistrationData PrincipalInfo principal; uint32_t loadFlags; + + int64_t currentWorkerInstalledTime; + int64_t currentWorkerActivatedTime; + int64_t lastUpdateTime; }; } // namespace dom diff --git a/dom/workers/ServiceWorkerRegistrationInfo.cpp b/dom/workers/ServiceWorkerRegistrationInfo.cpp index ff2cd29e779b..47facc2f913a 100644 --- a/dom/workers/ServiceWorkerRegistrationInfo.cpp +++ b/dom/workers/ServiceWorkerRegistrationInfo.cpp @@ -635,4 +635,20 @@ 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 diff --git a/dom/workers/ServiceWorkerRegistrationInfo.h b/dom/workers/ServiceWorkerRegistrationInfo.h index 318c308eeed5..a282f60fbad5 100644 --- a/dom/workers/ServiceWorkerRegistrationInfo.h +++ b/dom/workers/ServiceWorkerRegistrationInfo.h @@ -191,6 +191,12 @@ public: void SetLoadFlags(nsLoadFlags aLoadFlags); + int64_t + GetLastUpdateTime() const; + + void + SetLastUpdateTime(const int64_t aTime); + private: enum TransitionType { TransitionToNextState = 0,