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

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

Powered by Google App Engine
This is Rietveld 408576698