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

Side by Side Diff: content/child/service_worker/service_worker_dispatcher.cc

Issue 535753002: ServiceWorker: Implement navigator.serviceWorker.getRegistration [2/3] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/service_worker/service_worker_dispatcher.h" 5 #include "content/child/service_worker/service_worker_dispatcher.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() { 50 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() {
51 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); 51 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted);
52 } 52 }
53 53
54 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { 54 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) {
55 bool handled = true; 55 bool handled = true;
56 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) 56 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg)
57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) 57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered)
58 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, 58 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered,
59 OnUnregistered) 59 OnUnregistered)
60 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration,
61 OnDidGetRegistration)
60 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, 62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError,
61 OnRegistrationError) 63 OnRegistrationError)
62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, 64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError,
63 OnUnregistrationError) 65 OnUnregistrationError)
66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError,
67 OnGetRegistrationError)
64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, 68 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
65 OnServiceWorkerStateChanged) 69 OnServiceWorkerStateChanged)
66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, 70 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
67 OnSetVersionAttributes) 71 OnSetVersionAttributes)
68 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, 72 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound,
69 OnUpdateFound) 73 OnUpdateFound)
70 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, 74 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker,
71 OnSetControllerServiceWorker) 75 OnSetControllerServiceWorker)
72 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, 76 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
73 OnPostMessage) 77 OnPostMessage)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 128
125 int request_id = pending_unregistration_callbacks_.Add(callbacks); 129 int request_id = pending_unregistration_callbacks_.Add(callbacks);
126 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", 130 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker",
127 "ServiceWorkerDispatcher::UnregisterServiceWorker", 131 "ServiceWorkerDispatcher::UnregisterServiceWorker",
128 request_id, 132 request_id,
129 "Pettern", pattern.spec()); 133 "Pettern", pattern.spec());
130 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( 134 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker(
131 CurrentWorkerId(), request_id, provider_id, pattern)); 135 CurrentWorkerId(), request_id, provider_id, pattern));
132 } 136 }
133 137
138 void ServiceWorkerDispatcher::GetRegistration(
139 int provider_id,
140 const GURL& document_url,
141 WebServiceWorkerRegistrationCallbacks* callbacks) {
142 DCHECK(callbacks);
143
144 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) {
145 scoped_ptr<WebServiceWorkerRegistrationCallbacks>
146 owned_callbacks(callbacks);
147 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
148 WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
149 callbacks->onError(error.release());
150 return;
151 }
152
153 int request_id = pending_get_registration_callbacks_.Add(callbacks);
154 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker",
155 "ServiceWorkerDispatcher::GetRegistration",
156 request_id,
157 "Document URL", document_url.spec());
158 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration(
159 CurrentWorkerId(), request_id, provider_id, document_url));
160 }
161
134 void ServiceWorkerDispatcher::AddProviderContext( 162 void ServiceWorkerDispatcher::AddProviderContext(
135 ServiceWorkerProviderContext* provider_context) { 163 ServiceWorkerProviderContext* provider_context) {
136 DCHECK(provider_context); 164 DCHECK(provider_context);
137 int provider_id = provider_context->provider_id(); 165 int provider_id = provider_context->provider_id();
138 DCHECK(!ContainsKey(provider_contexts_, provider_id)); 166 DCHECK(!ContainsKey(provider_contexts_, provider_id));
139 provider_contexts_[provider_id] = provider_context; 167 provider_contexts_[provider_id] = provider_context;
140 } 168 }
141 169
142 void ServiceWorkerDispatcher::RemoveProviderContext( 170 void ServiceWorkerDispatcher::RemoveProviderContext(
143 ServiceWorkerProviderContext* provider_context) { 171 ServiceWorkerProviderContext* provider_context) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 if (!callbacks) 319 if (!callbacks)
292 return; 320 return;
293 bool is_success = true; 321 bool is_success = true;
294 callbacks->onSuccess(&is_success); 322 callbacks->onSuccess(&is_success);
295 pending_unregistration_callbacks_.Remove(request_id); 323 pending_unregistration_callbacks_.Remove(request_id);
296 TRACE_EVENT_ASYNC_END0("ServiceWorker", 324 TRACE_EVENT_ASYNC_END0("ServiceWorker",
297 "ServiceWorkerDispatcher::UnregisterServiceWorker", 325 "ServiceWorkerDispatcher::UnregisterServiceWorker",
298 request_id); 326 request_id);
299 } 327 }
300 328
329 void ServiceWorkerDispatcher::OnDidGetRegistration(
330 int thread_id,
331 int request_id,
332 const ServiceWorkerRegistrationObjectInfo& info,
333 const ServiceWorkerVersionAttributes& attrs) {
334 WebServiceWorkerRegistrationCallbacks* callbacks =
335 pending_get_registration_callbacks_.Lookup(request_id);
336 TRACE_EVENT_ASYNC_STEP_INTO0(
337 "ServiceWorker",
338 "ServiceWorkerDispatcher::GetRegistration",
339 request_id,
340 "OnDidGetRegistration");
341 DCHECK(callbacks);
342 if (!callbacks)
343 return;
344
345 WebServiceWorkerRegistrationImpl* registration =
346 GetServiceWorkerRegistration(info, true);
347 if (registration) {
348 registration->SetInstalling(GetServiceWorker(attrs.installing, true));
349 registration->SetWaiting(GetServiceWorker(attrs.waiting, true));
350 registration->SetActive(GetServiceWorker(attrs.active, true));
351 }
352 callbacks->onSuccess(registration);
353 pending_get_registration_callbacks_.Remove(request_id);
354 TRACE_EVENT_ASYNC_END0("ServiceWorker",
355 "ServiceWorkerDispatcher::GetRegistration",
356 request_id);
357 }
358
301 void ServiceWorkerDispatcher::OnRegistrationError( 359 void ServiceWorkerDispatcher::OnRegistrationError(
302 int thread_id, 360 int thread_id,
303 int request_id, 361 int request_id,
304 WebServiceWorkerError::ErrorType error_type, 362 WebServiceWorkerError::ErrorType error_type,
305 const base::string16& message) { 363 const base::string16& message) {
306 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", 364 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker",
307 "ServiceWorkerDispatcher::RegisterServiceWorker", 365 "ServiceWorkerDispatcher::RegisterServiceWorker",
308 request_id, 366 request_id,
309 "OnRegistrationError"); 367 "OnRegistrationError");
310 WebServiceWorkerRegistrationCallbacks* callbacks = 368 WebServiceWorkerRegistrationCallbacks* callbacks =
(...skipping 29 matching lines...) Expand all
340 398
341 scoped_ptr<WebServiceWorkerError> error( 399 scoped_ptr<WebServiceWorkerError> error(
342 new WebServiceWorkerError(error_type, message)); 400 new WebServiceWorkerError(error_type, message));
343 callbacks->onError(error.release()); 401 callbacks->onError(error.release());
344 pending_unregistration_callbacks_.Remove(request_id); 402 pending_unregistration_callbacks_.Remove(request_id);
345 TRACE_EVENT_ASYNC_END0("ServiceWorker", 403 TRACE_EVENT_ASYNC_END0("ServiceWorker",
346 "ServiceWorkerDispatcher::UnregisterServiceWorker", 404 "ServiceWorkerDispatcher::UnregisterServiceWorker",
347 request_id); 405 request_id);
348 } 406 }
349 407
408 void ServiceWorkerDispatcher::OnGetRegistrationError(
409 int thread_id,
410 int request_id,
411 WebServiceWorkerError::ErrorType error_type,
412 const base::string16& message) {
413 TRACE_EVENT_ASYNC_STEP_INTO0(
414 "ServiceWorker",
415 "ServiceWorkerDispatcher::GetRegistration",
416 request_id,
417 "OnGetRegistrationError");
418 WebServiceWorkerGetRegistrationCallbacks* callbacks =
419 pending_get_registration_callbacks_.Lookup(request_id);
420 DCHECK(callbacks);
421 if (!callbacks)
422 return;
423
424 scoped_ptr<WebServiceWorkerError> error(
425 new WebServiceWorkerError(error_type, message));
426 callbacks->onError(error.release());
427 pending_get_registration_callbacks_.Remove(request_id);
428 TRACE_EVENT_ASYNC_END0("ServiceWorker",
429 "ServiceWorkerDispatcher::GetRegistration",
430 request_id);
431 }
432
350 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( 433 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
351 int thread_id, 434 int thread_id,
352 int handle_id, 435 int handle_id,
353 blink::WebServiceWorkerState state) { 436 blink::WebServiceWorkerState state) {
354 TRACE_EVENT2("ServiceWorker", 437 TRACE_EVENT2("ServiceWorker",
355 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", 438 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged",
356 "Thread ID", thread_id, 439 "Thread ID", thread_id,
357 "State", state); 440 "State", state);
358 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); 441 WorkerObjectMap::iterator worker = service_workers_.find(handle_id);
359 if (worker != service_workers_.end()) 442 if (worker != service_workers_.end())
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 registrations_[registration_handle_id] = registration; 640 registrations_[registration_handle_id] = registration;
558 } 641 }
559 642
560 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( 643 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration(
561 int registration_handle_id) { 644 int registration_handle_id) {
562 DCHECK(ContainsKey(registrations_, registration_handle_id)); 645 DCHECK(ContainsKey(registrations_, registration_handle_id));
563 registrations_.erase(registration_handle_id); 646 registrations_.erase(registration_handle_id);
564 } 647 }
565 648
566 } // namespace content 649 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698