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

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

Issue 1270513002: Service Worker: Make ServiceWorkerRegistration.update() return a promise. (Chromium 2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass a raw ptr to callback's onError instead of a scoped_ptr. Created 5 years, 5 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 1c443d33f8d9c4dc99dbff486b2f8f87197fa1c8..f1ee3e7ec5112814edb05ac63361907f595f089e 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
@@ -41,6 +41,7 @@ const char kShutdownErrorMessage[] =
"The Service Worker system has shutdown.";
const char kUserDeniedPermissionMessage[] =
"The user denied permission to use Service Worker.";
+const char kInvalidStateErrorMessage[] = "The object is in an invalid state.";
const uint32 kFilteredMessageClasses[] = {
ServiceWorkerMsgStart,
@@ -364,12 +365,19 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
request_id));
}
-void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id,
+void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int thread_id,
+ int request_id,
+ int provider_id,
int64 registration_id) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerDispatcherHost::OnUpdateServiceWorker");
- if (!GetContext())
+ if (!GetContext()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerUpdateError(
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort,
+ base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) +
+ base::ASCIIToUTF16(kShutdownErrorMessage)));
return;
+ }
ServiceWorkerProviderHost* provider_host =
GetContext()->GetProviderHost(render_process_id_, provider_id);
@@ -377,12 +385,22 @@ void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id,
bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_NO_HOST);
return;
}
- if (!provider_host->IsContextAlive())
+ if (!provider_host->IsContextAlive()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerUpdateError(
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort,
+ base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) +
+ base::ASCIIToUTF16(kShutdownErrorMessage)));
return;
+ }
- // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed.
- if (provider_host->document_url().is_empty())
+ // TODO(jungkees): This check can be removed once crbug.com/439697 is fixed.
+ if (provider_host->document_url().is_empty()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerUpdateError(
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity,
+ base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) +
+ base::ASCIIToUTF16(kNoDocumentURLErrorMessage)));
return;
+ }
ServiceWorkerRegistration* registration =
GetContext()->GetLiveRegistration(registration_id);
@@ -403,19 +421,29 @@ void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id,
if (!GetContentClient()->browser()->AllowServiceWorker(
registration->pattern(), provider_host->topmost_frame_url(),
resource_context_, render_process_id_, provider_host->frame_id())) {
+ Send(new ServiceWorkerMsg_ServiceWorkerUpdateError(
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown,
+ base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) +
+ base::ASCIIToUTF16(kUserDeniedPermissionMessage)));
return;
}
if (!registration->GetNewestVersion()) {
// This can happen if update() is called during initial script evaluation.
// Abort the following steps according to the spec.
+ Send(new ServiceWorkerMsg_ServiceWorkerUpdateError(
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeState,
+ base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) +
+ base::ASCIIToUTF16(kInvalidStateErrorMessage)));
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,
- true /* force_bypass_cache */);
+ GetContext()->UpdateServiceWorker(
+ registration, true, /* force_bypass_cache */
+ provider_host, base::Bind(&ServiceWorkerDispatcherHost::UpdateComplete,
+ this, thread_id, provider_id, request_id));
}
void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
@@ -844,6 +872,41 @@ void ServiceWorkerDispatcherHost::RegistrationComplete(
registration_id);
}
+void ServiceWorkerDispatcherHost::UpdateComplete(
+ int thread_id,
+ int provider_id,
+ int request_id,
+ ServiceWorkerStatusCode status,
+ const std::string& status_message,
+ int64 registration_id) {
+ if (!GetContext())
+ return;
+
+ ServiceWorkerProviderHost* provider_host =
+ GetContext()->GetProviderHost(render_process_id_, provider_id);
+ if (!provider_host)
+ return; // The provider has already been destroyed.
+
+ if (status != SERVICE_WORKER_OK) {
+ SendRegistrationError(thread_id, request_id, status, status_message);
+ return;
+ }
+
+ ServiceWorkerRegistration* registration =
+ GetContext()->GetLiveRegistration(registration_id);
+ DCHECK(registration);
+
+ ServiceWorkerRegistrationObjectInfo info;
+ ServiceWorkerVersionAttributes attrs;
+ GetRegistrationObjectInfoAndVersionAttributes(provider_host->AsWeakPtr(),
+ registration, &info, &attrs);
+
+ Send(new ServiceWorkerMsg_ServiceWorkerUpdated(thread_id, request_id));
+ TRACE_EVENT_ASYNC_END1("ServiceWorker",
+ "ServiceWorkerDispatcherHost::UpdateServiceWorker",
+ request_id, "Registration ID", registration_id);
+}
+
void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection(
int embedded_worker_id) {
TRACE_EVENT0("ServiceWorker",

Powered by Google App Engine
This is Rietveld 408576698