Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Unified Diff: content/browser/service_worker/service_worker_dispatcher_host.cc

Issue 1175823002: ServiceWorker: Implement ServiceWorkerRegistration.update() (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address kinuko@'s comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_dispatcher_host.cc
diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc
index d80cd145383564fe60cf3592cacea310c20fa7b6..4d1fe4f471d751d4ea1804907120f5f2eaac9f97 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
@@ -158,6 +158,8 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived(
IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
OnRegisterServiceWorker)
+ IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UpdateServiceWorker,
+ OnUpdateServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
OnUnregisterServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
@@ -360,6 +362,38 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
request_id));
}
+void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id,
+ int64 registration_id) {
+ TRACE_EVENT0("ServiceWorker",
+ "ServiceWorkerDispatcherHost::OnUpdateServiceWorker");
+ if (!GetContext())
+ return;
+
+ ServiceWorkerProviderHost* provider_host =
+ GetContext()->GetProviderHost(render_process_id_, provider_id);
+ if (!provider_host) {
+ bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_NO_HOST);
+ return;
+ }
+ if (!provider_host->IsContextAlive())
+ return;
+
+ // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed.
+ if (provider_host->document_url().is_empty())
+ return;
+
+ if (!GetContentClient()->browser()->AllowServiceWorker(
+ provider_host->document_url(), provider_host->topmost_frame_url(),
+ resource_context_, render_process_id_, provider_host->frame_id())) {
+ return;
+ }
+
+ GetContext()->storage()->FindRegistrationForId(
kinuko 2015/06/11 06:33:06 If this comes from WebServiceWorkerRegistration th
michaeln 2015/06/11 21:40:48 Yes, it should be valid to look this up in the liv
nhiroki 2015/06/12 08:50:57 You're right. This registration should be in the l
+ registration_id, provider_host->document_url().GetOrigin(),
+ base::Bind(&ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate,
+ this, provider_host->document_url()));
+}
+
void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
int thread_id,
int request_id,
@@ -721,6 +755,32 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId(
kDocumentMainThreadId, provider_id, info, attrs));
}
+void ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate(
+ const GURL& document_url,
+ ServiceWorkerStatusCode status,
+ const scoped_refptr<ServiceWorkerRegistration>& registration) {
+ if (status != SERVICE_WORKER_OK)
+ return;
+ if (!GetContext())
+ return;
+
+ if (registration->pattern().GetOrigin() != document_url.GetOrigin()) {
kinuko 2015/06/11 06:33:06 I wonder if we should perform this check in FindRe
nhiroki 2015/06/12 08:50:57 Sounds reasonable. I'll make it in a separate CL (
+ bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_CANNOT);
+ return;
+ }
+
+ if (!registration->GetNewestVersion()) {
+ // This can happen if update() is called during initial script evaluation.
+ // Abort the following steps according to the spec.
+ return;
+ }
+
+ // The spec says, "update() pings the server for an updated version of this
+ // script without consulting caches", so set |force_bypass_cache| to true.
+ GetContext()->UpdateServiceWorker(registration.get(),
+ true /* force_bypass_cache */);
+}
+
ServiceWorkerRegistrationHandle*
ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id,
int64 registration_id) {

Powered by Google App Engine
This is Rietveld 408576698