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

Unified Diff: content/child/service_worker/service_worker_dispatcher.cc

Issue 1146913004: Service Worker: Add ServiceWorkerContainer.getRegistrations() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update tools/metrics/histograms/histograms.xml. 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/child/service_worker/service_worker_dispatcher.cc
diff --git a/content/child/service_worker/service_worker_dispatcher.cc b/content/child/service_worker/service_worker_dispatcher.cc
index e68f64451ba918e53105238a7f6daec12016fdd6..d1c72a716e2b3c406c63ce314cabac8b32a4de67 100644
--- a/content/child/service_worker/service_worker_dispatcher.cc
+++ b/content/child/service_worker/service_worker_dispatcher.cc
@@ -69,6 +69,8 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) {
OnUnregistered)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration,
OnDidGetRegistration)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrations,
+ OnDidGetRegistrations)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrationForReady,
OnDidGetRegistrationForReady)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError,
@@ -77,6 +79,8 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) {
OnUnregistrationError)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError,
OnGetRegistrationError)
+ IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationsError,
+ OnGetRegistrationsError)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
OnServiceWorkerStateChanged)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
@@ -180,6 +184,19 @@ void ServiceWorkerDispatcher::GetRegistration(
CurrentWorkerId(), request_id, provider_id, document_url));
}
+void ServiceWorkerDispatcher::GetRegistrations(
+ int provider_id,
+ WebServiceWorkerGetRegistrationsCallbacks* callbacks) {
+ DCHECK(callbacks);
+
+ int request_id = pending_get_registrations_callbacks_.Add(callbacks);
+ TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker",
+ "ServiceWorkerDispatcher::GetRegistrations",
+ request_id);
+ thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrations(
+ CurrentWorkerId(), request_id, provider_id));
+}
+
void ServiceWorkerDispatcher::GetRegistrationForReady(
int provider_id,
WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) {
@@ -417,6 +434,42 @@ void ServiceWorkerDispatcher::OnDidGetRegistration(
pending_get_registration_callbacks_.Remove(request_id);
}
+void ServiceWorkerDispatcher::OnDidGetRegistrations(
+ int thread_id,
+ int request_id,
+ const std::vector<ServiceWorkerRegistrationObjectInfo>& infos,
+ const std::vector<ServiceWorkerVersionAttributes>& attrs) {
+ TRACE_EVENT_ASYNC_STEP_INTO0(
+ "ServiceWorker",
+ "ServiceWorkerDispatcher::GetRegistrations",
+ request_id,
+ "OnDidGetRegistrations");
+ TRACE_EVENT_ASYNC_END0("ServiceWorker",
+ "ServiceWorkerDispatcher::GetRegistrations",
+ request_id);
+
+ WebServiceWorkerGetRegistrationsCallbacks* callbacks =
+ pending_get_registrations_callbacks_.Lookup(request_id);
+ DCHECK(callbacks);
+ if (!callbacks)
+ return;
+
+ typedef blink::WebVector<blink::WebServiceWorkerRegistration*>
+ WebServiceWorkerRegistrationArray;
+ scoped_ptr<WebServiceWorkerRegistrationArray>
+ registrations(new WebServiceWorkerRegistrationArray(infos.size()));
+ for (size_t i = 0; i < infos.size(); ++i) {
+ if (infos[i].handle_id != kInvalidServiceWorkerHandleId) {
+ ServiceWorkerRegistrationObjectInfo info(infos[i]);
+ ServiceWorkerVersionAttributes attr(attrs[i]);
+ (*registrations)[i] = FindOrCreateRegistration(info, attr);
+ }
+ }
+
+ callbacks->onSuccess(registrations.release());
+ pending_get_registrations_callbacks_.Remove(request_id);
+}
+
void ServiceWorkerDispatcher::OnDidGetRegistrationForReady(
int thread_id,
int request_id,
@@ -517,6 +570,31 @@ void ServiceWorkerDispatcher::OnGetRegistrationError(
pending_get_registration_callbacks_.Remove(request_id);
}
+void ServiceWorkerDispatcher::OnGetRegistrationsError(
+ int thread_id,
+ int request_id,
+ WebServiceWorkerError::ErrorType error_type,
+ const base::string16& message) {
+ TRACE_EVENT_ASYNC_STEP_INTO0(
+ "ServiceWorker",
+ "ServiceWorkerDispatcher::GetRegistrations",
+ request_id,
+ "OnGetRegistrationsError");
+ TRACE_EVENT_ASYNC_END0("ServiceWorker",
+ "ServiceWorkerDispatcher::GetRegistrations",
+ request_id);
+ WebServiceWorkerGetRegistrationsCallbacks* callbacks =
+ pending_get_registrations_callbacks_.Lookup(request_id);
+ DCHECK(callbacks);
+ if (!callbacks)
+ return;
+
+ scoped_ptr<WebServiceWorkerError> error(
+ new WebServiceWorkerError(error_type, message));
+ callbacks->onError(error.release());
+ pending_get_registrations_callbacks_.Remove(request_id);
+}
+
void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
int thread_id,
int handle_id,

Powered by Google App Engine
This is Rietveld 408576698