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

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

Issue 535753002: ServiceWorker: Implement navigator.serviceWorker.getRegistration [2/3] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch for review Created 6 years, 3 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 a0bdabf61db8196e2f0104d6e715dfa67d828a11..3ee8cadc8ea593bcfd7d2a427dfee0cdc39daf6b 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
@@ -113,6 +113,8 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived(
OnRegisterServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
OnUnregisterServiceWorker)
+ IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
+ OnGetRegistration)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated,
OnProviderCreated)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed,
@@ -303,6 +305,46 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
request_id));
}
+void ServiceWorkerDispatcherHost::OnGetRegistration(
+ int thread_id,
+ int request_id,
+ int provider_id,
+ const GURL& document_url) {
+ TRACE_EVENT0("ServiceWorker",
+ "ServiceWorkerDispatcherHost::OnGetRegistration");
+ if (!GetContext()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
+ thread_id,
+ request_id,
+ blink::WebServiceWorkerError::ErrorTypeAbort,
+ base::ASCIIToUTF16(kShutdownErrorMessage)));
+ return;
+ }
+
+ ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
+ render_process_id_, provider_id);
+ if (!provider_host) {
+ BadMessageReceived();
+ return;
+ }
+ if (!provider_host->IsContextAlive()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
+ thread_id,
+ request_id,
+ blink::WebServiceWorkerError::ErrorTypeAbort,
+ base::ASCIIToUTF16(kShutdownErrorMessage)));
+ return;
+ }
+
nhiroki 2014/09/10 04:07:22 You may want to check that the origin of |document
Kunihiko Sakamoto 2014/09/10 08:22:44 Done.
+ GetContext()->GetRegistration(
nhiroki 2014/09/10 04:07:22 You may want to add "TRACE_EVENT_ASYNC_BEGIN" here
Kunihiko Sakamoto 2014/09/10 08:22:44 Done.
+ document_url,
+ base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete,
+ this,
+ thread_id,
+ provider_id,
+ request_id));
+}
+
void ServiceWorkerDispatcherHost::OnPostMessageToWorker(
int handle_id,
const base::string16& message,
@@ -390,6 +432,27 @@ ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id,
return NULL;
}
+void ServiceWorkerDispatcherHost::GetRegistrationObjectInfoAndVersionAttributes(
+ int provider_id,
+ int64 registration_id,
+ ServiceWorkerRegistrationObjectInfo* info,
+ ServiceWorkerVersionAttributes* attrs) {
+ ServiceWorkerRegistration* registration =
+ GetContext()->GetLiveRegistration(registration_id);
+ DCHECK(registration);
+
+ ServiceWorkerRegistrationHandle* handle =
+ GetOrCreateRegistrationHandle(provider_id, registration);
+ *info = handle->GetObjectInfo();
+
+ attrs->installing = handle->CreateServiceWorkerHandleAndPass(
+ registration->installing_version());
+ attrs->waiting = handle->CreateServiceWorkerHandleAndPass(
+ registration->waiting_version());
+ attrs->active = handle->CreateServiceWorkerHandleAndPass(
+ registration->active_version());
+}
+
void ServiceWorkerDispatcherHost::RegistrationComplete(
int thread_id,
int provider_id,
@@ -405,23 +468,13 @@ void ServiceWorkerDispatcherHost::RegistrationComplete(
return;
}
- ServiceWorkerRegistration* registration =
- GetContext()->GetLiveRegistration(registration_id);
- DCHECK(registration);
-
- ServiceWorkerRegistrationHandle* handle =
- GetOrCreateRegistrationHandle(provider_id, registration);
-
+ ServiceWorkerRegistrationObjectInfo info;
ServiceWorkerVersionAttributes attrs;
- attrs.installing = handle->CreateServiceWorkerHandleAndPass(
- registration->installing_version());
- attrs.waiting = handle->CreateServiceWorkerHandleAndPass(
- registration->waiting_version());
- attrs.active = handle->CreateServiceWorkerHandleAndPass(
- registration->active_version());
+ GetRegistrationObjectInfoAndVersionAttributes(
+ provider_id, registration_id, &info, &attrs);
Send(new ServiceWorkerMsg_ServiceWorkerRegistered(
- thread_id, request_id, handle->GetObjectInfo(), attrs));
+ thread_id, request_id, info, attrs));
TRACE_EVENT_ASYNC_END2("ServiceWorker",
"ServiceWorkerDispatcherHost::RegisterServiceWorker",
request_id,
@@ -608,6 +661,31 @@ void ServiceWorkerDispatcherHost::UnregistrationComplete(
"Status", status);
}
+void ServiceWorkerDispatcherHost::GetRegistrationComplete(
+ int thread_id,
+ int provider_id,
+ int request_id,
+ ServiceWorkerStatusCode status,
+ int64 registration_id) {
+ if (!GetContext())
+ return;
+
+ if (status != SERVICE_WORKER_OK) {
+ SendGetRegistrationError(thread_id, request_id, status);
+ return;
+ }
+
+ ServiceWorkerRegistrationObjectInfo info;
+ ServiceWorkerVersionAttributes attrs;
+ if (registration_id != kInvalidServiceWorkerRegistrationId) {
+ GetRegistrationObjectInfoAndVersionAttributes(
+ provider_id, registration_id, &info, &attrs);
+ }
+
+ Send(new ServiceWorkerMsg_DidGetRegistration(
+ thread_id, request_id, info, attrs));
nhiroki 2014/09/10 04:07:22 "TRACE_EVENT_ASYNC_END" (a separate CL is ok)
Kunihiko Sakamoto 2014/09/10 08:22:44 Done.
+}
+
void ServiceWorkerDispatcherHost::SendRegistrationError(
int thread_id,
int request_id,
@@ -632,6 +710,18 @@ void ServiceWorkerDispatcherHost::SendUnregistrationError(
thread_id, request_id, error_type, error_message));
}
+void ServiceWorkerDispatcherHost::SendGetRegistrationError(
+ int thread_id,
+ int request_id,
+ ServiceWorkerStatusCode status) {
+ base::string16 error_message;
+ blink::WebServiceWorkerError::ErrorType error_type;
+ GetServiceWorkerRegistrationStatusResponse(
+ status, &error_type, &error_message);
+ Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
+ thread_id, request_id, error_type, error_message));
+}
+
ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
return context_wrapper_->context();
}

Powered by Google App Engine
This is Rietveld 408576698