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/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 OnAssociateRegistrationWithServiceWorker) | 61 OnAssociateRegistrationWithServiceWorker) |
62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_AssociateRegistration, | 62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_AssociateRegistration, |
63 OnAssociateRegistration) | 63 OnAssociateRegistration) |
64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DisassociateRegistration, | 64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DisassociateRegistration, |
65 OnDisassociateRegistration) | 65 OnDisassociateRegistration) |
66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) | 66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) |
67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, | 67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, |
68 OnUnregistered) | 68 OnUnregistered) |
69 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, | 69 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, |
70 OnDidGetRegistration) | 70 OnDidGetRegistration) |
71 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrations, | |
72 OnDidGetRegistrations) | |
71 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrationForReady, | 73 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrationForReady, |
72 OnDidGetRegistrationForReady) | 74 OnDidGetRegistrationForReady) |
73 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, | 75 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
74 OnRegistrationError) | 76 OnRegistrationError) |
75 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, | 77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, |
76 OnUnregistrationError) | 78 OnUnregistrationError) |
77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, | 79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, |
78 OnGetRegistrationError) | 80 OnGetRegistrationError) |
81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationsError, | |
82 OnGetRegistrationsError) | |
79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, | 83 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, |
80 OnServiceWorkerStateChanged) | 84 OnServiceWorkerStateChanged) |
81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, | 85 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, |
82 OnSetVersionAttributes) | 86 OnSetVersionAttributes) |
83 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, | 87 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, |
84 OnUpdateFound) | 88 OnUpdateFound) |
85 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, | 89 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, |
86 OnSetControllerServiceWorker) | 90 OnSetControllerServiceWorker) |
87 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, | 91 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, |
88 OnPostMessage) | 92 OnPostMessage) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 | 176 |
173 int request_id = pending_get_registration_callbacks_.Add(callbacks); | 177 int request_id = pending_get_registration_callbacks_.Add(callbacks); |
174 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 178 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
175 "ServiceWorkerDispatcher::GetRegistration", | 179 "ServiceWorkerDispatcher::GetRegistration", |
176 request_id, | 180 request_id, |
177 "Document URL", document_url.spec()); | 181 "Document URL", document_url.spec()); |
178 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( | 182 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( |
179 CurrentWorkerId(), request_id, provider_id, document_url)); | 183 CurrentWorkerId(), request_id, provider_id, document_url)); |
180 } | 184 } |
181 | 185 |
186 void ServiceWorkerDispatcher::GetRegistrations( | |
187 int provider_id, | |
188 WebServiceWorkerGetRegistrationsCallbacks* callbacks) { | |
189 DCHECK(callbacks); | |
190 | |
191 int request_id = pending_get_registrations_callbacks_.Add(callbacks); | |
192 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | |
193 "ServiceWorkerDispatcher::GetRegistrations", | |
194 request_id); | |
195 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrations( | |
196 CurrentWorkerId(), request_id, provider_id)); | |
197 } | |
198 | |
182 void ServiceWorkerDispatcher::GetRegistrationForReady( | 199 void ServiceWorkerDispatcher::GetRegistrationForReady( |
183 int provider_id, | 200 int provider_id, |
184 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { | 201 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { |
185 int request_id = get_for_ready_callbacks_.Add(callbacks); | 202 int request_id = get_for_ready_callbacks_.Add(callbacks); |
186 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 203 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
187 "ServiceWorkerDispatcher::GetRegistrationForReady", | 204 "ServiceWorkerDispatcher::GetRegistrationForReady", |
188 request_id); | 205 request_id); |
189 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady( | 206 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady( |
190 CurrentWorkerId(), request_id, provider_id)); | 207 CurrentWorkerId(), request_id, provider_id)); |
191 } | 208 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 return; | 426 return; |
410 | 427 |
411 WebServiceWorkerRegistrationImpl* registration = NULL; | 428 WebServiceWorkerRegistrationImpl* registration = NULL; |
412 if (info.handle_id != kInvalidServiceWorkerHandleId) | 429 if (info.handle_id != kInvalidServiceWorkerHandleId) |
413 registration = FindOrCreateRegistration(info, attrs); | 430 registration = FindOrCreateRegistration(info, attrs); |
414 | 431 |
415 callbacks->onSuccess(registration); | 432 callbacks->onSuccess(registration); |
416 pending_get_registration_callbacks_.Remove(request_id); | 433 pending_get_registration_callbacks_.Remove(request_id); |
417 } | 434 } |
418 | 435 |
436 void ServiceWorkerDispatcher::OnDidGetRegistrations( | |
437 int thread_id, | |
438 int request_id, | |
439 const std::vector<ServiceWorkerRegistrationObjectInfo>& infos, | |
440 const std::vector<ServiceWorkerVersionAttributes>& attrs) { | |
441 TRACE_EVENT_ASYNC_STEP_INTO0( | |
442 "ServiceWorker", | |
443 "ServiceWorkerDispatcher::GetRegistrations", | |
444 request_id, | |
445 "OnDidGetRegistrations"); | |
446 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
447 "ServiceWorkerDispatcher::GetRegistrations", | |
448 request_id); | |
449 | |
450 WebServiceWorkerGetRegistrationsCallbacks* callbacks = | |
451 pending_get_registrations_callbacks_.Lookup(request_id); | |
452 DCHECK(callbacks); | |
453 if (!callbacks) | |
454 return; | |
falken
2015/06/05 02:58:22
JFYI: We're not suppsoed to write code like this,
jungkees
2015/06/05 06:58:07
Thanks for the pointer. So in this particular file
falken
2015/06/08 04:59:09
Right, we should either DCHECK() and not handle th
| |
455 | |
456 typedef blink::WebVector<blink::WebServiceWorkerRegistration*> | |
457 WebServiceWorkerRegistrationArray; | |
458 scoped_ptr<WebServiceWorkerRegistrationArray> | |
459 registrations(new WebServiceWorkerRegistrationArray(infos.size())); | |
460 for (size_t i = 0; i < infos.size(); ++i) { | |
461 if (infos[i].handle_id != kInvalidServiceWorkerHandleId) { | |
462 ServiceWorkerRegistrationObjectInfo info(infos[i]); | |
463 ServiceWorkerVersionAttributes attr(attrs[i]); | |
464 (*registrations)[i] = FindOrCreateRegistration(info, attr); | |
465 } | |
466 } | |
467 | |
468 callbacks->onSuccess(registrations.release()); | |
469 pending_get_registrations_callbacks_.Remove(request_id); | |
470 } | |
471 | |
419 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady( | 472 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady( |
420 int thread_id, | 473 int thread_id, |
421 int request_id, | 474 int request_id, |
422 const ServiceWorkerRegistrationObjectInfo& info, | 475 const ServiceWorkerRegistrationObjectInfo& info, |
423 const ServiceWorkerVersionAttributes& attrs) { | 476 const ServiceWorkerVersionAttributes& attrs) { |
424 TRACE_EVENT_ASYNC_STEP_INTO0( | 477 TRACE_EVENT_ASYNC_STEP_INTO0( |
425 "ServiceWorker", | 478 "ServiceWorker", |
426 "ServiceWorkerDispatcher::GetRegistrationForReady", | 479 "ServiceWorkerDispatcher::GetRegistrationForReady", |
427 request_id, | 480 request_id, |
428 "OnDidGetRegistrationForReady"); | 481 "OnDidGetRegistrationForReady"); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 DCHECK(callbacks); | 562 DCHECK(callbacks); |
510 if (!callbacks) | 563 if (!callbacks) |
511 return; | 564 return; |
512 | 565 |
513 scoped_ptr<WebServiceWorkerError> error( | 566 scoped_ptr<WebServiceWorkerError> error( |
514 new WebServiceWorkerError(error_type, message)); | 567 new WebServiceWorkerError(error_type, message)); |
515 callbacks->onError(error.release()); | 568 callbacks->onError(error.release()); |
516 pending_get_registration_callbacks_.Remove(request_id); | 569 pending_get_registration_callbacks_.Remove(request_id); |
517 } | 570 } |
518 | 571 |
572 void ServiceWorkerDispatcher::OnGetRegistrationsError( | |
573 int thread_id, | |
574 int request_id, | |
575 WebServiceWorkerError::ErrorType error_type, | |
576 const base::string16& message) { | |
577 TRACE_EVENT_ASYNC_STEP_INTO0( | |
578 "ServiceWorker", | |
579 "ServiceWorkerDispatcher::GetRegistrations", | |
580 request_id, | |
581 "OnGetRegistrationsError"); | |
582 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
583 "ServiceWorkerDispatcher::GetRegistrations", | |
584 request_id); | |
585 WebServiceWorkerGetRegistrationsCallbacks* callbacks = | |
586 pending_get_registrations_callbacks_.Lookup(request_id); | |
587 DCHECK(callbacks); | |
588 if (!callbacks) | |
589 return; | |
590 | |
591 scoped_ptr<WebServiceWorkerError> error( | |
592 new WebServiceWorkerError(error_type, message)); | |
593 callbacks->onError(error.release()); | |
594 pending_get_registrations_callbacks_.Remove(request_id); | |
595 } | |
596 | |
519 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( | 597 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( |
520 int thread_id, | 598 int thread_id, |
521 int handle_id, | 599 int handle_id, |
522 blink::WebServiceWorkerState state) { | 600 blink::WebServiceWorkerState state) { |
523 TRACE_EVENT2("ServiceWorker", | 601 TRACE_EVENT2("ServiceWorker", |
524 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", | 602 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", |
525 "Thread ID", thread_id, | 603 "Thread ID", thread_id, |
526 "State", state); | 604 "State", state); |
527 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); | 605 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); |
528 if (worker != service_workers_.end()) | 606 if (worker != service_workers_.end()) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 bool adopt_handle = true; | 765 bool adopt_handle = true; |
688 WebServiceWorkerRegistrationImpl* registration = | 766 WebServiceWorkerRegistrationImpl* registration = |
689 CreateServiceWorkerRegistration(info, adopt_handle); | 767 CreateServiceWorkerRegistration(info, adopt_handle); |
690 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); | 768 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); |
691 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); | 769 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); |
692 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); | 770 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); |
693 return registration; | 771 return registration; |
694 } | 772 } |
695 | 773 |
696 } // namespace content | 774 } // namespace content |
OLD | NEW |