OLD | NEW |
---|---|
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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_AssociateRegistration, | 57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_AssociateRegistration, |
58 OnAssociateRegistration) | 58 OnAssociateRegistration) |
59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DisassociateRegistration, | 59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DisassociateRegistration, |
60 OnDisassociateRegistration) | 60 OnDisassociateRegistration) |
61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) | 61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) |
62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, | 62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, |
63 OnUnregistered) | 63 OnUnregistered) |
64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, | |
65 OnDidGetRegistration) | |
64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, | 66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
65 OnRegistrationError) | 67 OnRegistrationError) |
66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, | 68 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, |
67 OnUnregistrationError) | 69 OnUnregistrationError) |
70 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, | |
71 OnGetRegistrationError) | |
68 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, | 72 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, |
69 OnServiceWorkerStateChanged) | 73 OnServiceWorkerStateChanged) |
70 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, | 74 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, |
71 OnSetVersionAttributes) | 75 OnSetVersionAttributes) |
72 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, | 76 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, |
73 OnUpdateFound) | 77 OnUpdateFound) |
74 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, | 78 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, |
75 OnSetControllerServiceWorker) | 79 OnSetControllerServiceWorker) |
76 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, | 80 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, |
77 OnPostMessage) | 81 OnPostMessage) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 | 132 |
129 int request_id = pending_unregistration_callbacks_.Add(callbacks); | 133 int request_id = pending_unregistration_callbacks_.Add(callbacks); |
130 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 134 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
131 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 135 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
132 request_id, | 136 request_id, |
133 "Pettern", pattern.spec()); | 137 "Pettern", pattern.spec()); |
134 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 138 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
135 CurrentWorkerId(), request_id, provider_id, pattern)); | 139 CurrentWorkerId(), request_id, provider_id, pattern)); |
136 } | 140 } |
137 | 141 |
142 void ServiceWorkerDispatcher::GetRegistration( | |
143 int provider_id, | |
144 const GURL& document_url, | |
145 WebServiceWorkerRegistrationCallbacks* callbacks) { | |
146 DCHECK(callbacks); | |
147 | |
148 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { | |
149 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | |
150 owned_callbacks(callbacks); | |
151 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | |
152 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | |
153 callbacks->onError(error.release()); | |
154 return; | |
155 } | |
156 | |
157 int request_id = pending_get_registration_callbacks_.Add(callbacks); | |
158 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | |
159 "ServiceWorkerDispatcher::GetRegistration", | |
160 request_id, | |
161 "Document URL", document_url.spec()); | |
162 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( | |
163 CurrentWorkerId(), request_id, provider_id, document_url)); | |
164 } | |
165 | |
138 void ServiceWorkerDispatcher::AddProviderContext( | 166 void ServiceWorkerDispatcher::AddProviderContext( |
139 ServiceWorkerProviderContext* provider_context) { | 167 ServiceWorkerProviderContext* provider_context) { |
140 DCHECK(provider_context); | 168 DCHECK(provider_context); |
141 int provider_id = provider_context->provider_id(); | 169 int provider_id = provider_context->provider_id(); |
142 DCHECK(!ContainsKey(provider_contexts_, provider_id)); | 170 DCHECK(!ContainsKey(provider_contexts_, provider_id)); |
143 provider_contexts_[provider_id] = provider_context; | 171 provider_contexts_[provider_id] = provider_context; |
144 } | 172 } |
145 | 173 |
146 void ServiceWorkerDispatcher::RemoveProviderContext( | 174 void ServiceWorkerDispatcher::RemoveProviderContext( |
147 ServiceWorkerProviderContext* provider_context) { | 175 ServiceWorkerProviderContext* provider_context) { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 DCHECK(callbacks); | 369 DCHECK(callbacks); |
342 if (!callbacks) | 370 if (!callbacks) |
343 return; | 371 return; |
344 callbacks->onSuccess(&is_success); | 372 callbacks->onSuccess(&is_success); |
345 pending_unregistration_callbacks_.Remove(request_id); | 373 pending_unregistration_callbacks_.Remove(request_id); |
346 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 374 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
347 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 375 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
348 request_id); | 376 request_id); |
349 } | 377 } |
350 | 378 |
379 void ServiceWorkerDispatcher::OnDidGetRegistration( | |
380 int thread_id, | |
381 int request_id, | |
382 const ServiceWorkerRegistrationObjectInfo& info, | |
383 const ServiceWorkerVersionAttributes& attrs) { | |
384 WebServiceWorkerRegistrationCallbacks* callbacks = | |
385 pending_get_registration_callbacks_.Lookup(request_id); | |
386 TRACE_EVENT_ASYNC_STEP_INTO0( | |
387 "ServiceWorker", | |
388 "ServiceWorkerDispatcher::GetRegistration", | |
389 request_id, | |
390 "OnDidGetRegistration"); | |
391 DCHECK(callbacks); | |
392 if (!callbacks) | |
393 return; | |
394 | |
395 WebServiceWorkerRegistrationImpl* registration = | |
396 FindServiceWorkerRegistration(info, true); | |
Kunihiko Sakamoto
2014/09/11 04:23:52
nhiroki@: Since your patch has landed, I've rebase
nhiroki
2014/09/11 07:23:49
If a registration object hasn't been created, Find
Kunihiko Sakamoto
2014/09/11 08:48:10
Thanks for the explanation. Fixed by introducing a
| |
397 if (registration) { | |
398 // |registration| must already have version attributes, so adopt and destroy | |
399 // handle refs for them. | |
400 ServiceWorkerHandleReference::Adopt( | |
401 attrs.installing, thread_safe_sender_.get()); | |
402 ServiceWorkerHandleReference::Adopt( | |
403 attrs.waiting, thread_safe_sender_.get()); | |
404 ServiceWorkerHandleReference::Adopt( | |
405 attrs.active, thread_safe_sender_.get()); | |
406 } | |
407 callbacks->onSuccess(registration); | |
408 pending_get_registration_callbacks_.Remove(request_id); | |
409 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
410 "ServiceWorkerDispatcher::GetRegistration", | |
411 request_id); | |
nhiroki
2014/09/11 07:23:50
This is also likely to be skipped due to an early
Kunihiko Sakamoto
2014/09/11 08:48:10
Since that is an exceptional case (DCHECK fails),
| |
412 } | |
413 | |
351 void ServiceWorkerDispatcher::OnRegistrationError( | 414 void ServiceWorkerDispatcher::OnRegistrationError( |
352 int thread_id, | 415 int thread_id, |
353 int request_id, | 416 int request_id, |
354 WebServiceWorkerError::ErrorType error_type, | 417 WebServiceWorkerError::ErrorType error_type, |
355 const base::string16& message) { | 418 const base::string16& message) { |
356 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", | 419 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", |
357 "ServiceWorkerDispatcher::RegisterServiceWorker", | 420 "ServiceWorkerDispatcher::RegisterServiceWorker", |
358 request_id, | 421 request_id, |
359 "OnRegistrationError"); | 422 "OnRegistrationError"); |
360 WebServiceWorkerRegistrationCallbacks* callbacks = | 423 WebServiceWorkerRegistrationCallbacks* callbacks = |
(...skipping 29 matching lines...) Expand all Loading... | |
390 | 453 |
391 scoped_ptr<WebServiceWorkerError> error( | 454 scoped_ptr<WebServiceWorkerError> error( |
392 new WebServiceWorkerError(error_type, message)); | 455 new WebServiceWorkerError(error_type, message)); |
393 callbacks->onError(error.release()); | 456 callbacks->onError(error.release()); |
394 pending_unregistration_callbacks_.Remove(request_id); | 457 pending_unregistration_callbacks_.Remove(request_id); |
395 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 458 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
396 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 459 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
397 request_id); | 460 request_id); |
398 } | 461 } |
399 | 462 |
463 void ServiceWorkerDispatcher::OnGetRegistrationError( | |
464 int thread_id, | |
465 int request_id, | |
466 WebServiceWorkerError::ErrorType error_type, | |
467 const base::string16& message) { | |
468 TRACE_EVENT_ASYNC_STEP_INTO0( | |
469 "ServiceWorker", | |
470 "ServiceWorkerDispatcher::GetRegistration", | |
471 request_id, | |
472 "OnGetRegistrationError"); | |
473 WebServiceWorkerGetRegistrationCallbacks* callbacks = | |
474 pending_get_registration_callbacks_.Lookup(request_id); | |
475 DCHECK(callbacks); | |
476 if (!callbacks) | |
477 return; | |
478 | |
479 scoped_ptr<WebServiceWorkerError> error( | |
480 new WebServiceWorkerError(error_type, message)); | |
481 callbacks->onError(error.release()); | |
482 pending_get_registration_callbacks_.Remove(request_id); | |
483 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
484 "ServiceWorkerDispatcher::GetRegistration", | |
485 request_id); | |
nhiroki
2014/09/11 07:23:50
ditto.
Kunihiko Sakamoto
2014/09/11 08:48:10
see the comment above.
| |
486 } | |
487 | |
400 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( | 488 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( |
401 int thread_id, | 489 int thread_id, |
402 int handle_id, | 490 int handle_id, |
403 blink::WebServiceWorkerState state) { | 491 blink::WebServiceWorkerState state) { |
404 TRACE_EVENT2("ServiceWorker", | 492 TRACE_EVENT2("ServiceWorker", |
405 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", | 493 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", |
406 "Thread ID", thread_id, | 494 "Thread ID", thread_id, |
407 "State", state); | 495 "State", state); |
408 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); | 496 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); |
409 if (worker != service_workers_.end()) | 497 if (worker != service_workers_.end()) |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 registrations_[registration_handle_id] = registration; | 732 registrations_[registration_handle_id] = registration; |
645 } | 733 } |
646 | 734 |
647 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 735 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
648 int registration_handle_id) { | 736 int registration_handle_id) { |
649 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 737 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
650 registrations_.erase(registration_handle_id); | 738 registrations_.erase(registration_handle_id); |
651 } | 739 } |
652 | 740 |
653 } // namespace content | 741 } // namespace content |
OLD | NEW |