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

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: Created 5 years, 7 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/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
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
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 const GURL& document_url,
kinuko 2015/05/21 07:57:06 I have a feeling that this doesn't need to be (or
jungkees 2015/05/21 13:46:25 Agreed. Correct and much simpler!
189 WebServiceWorkerGetRegistrationsCallbacks* callbacks) {
190 DCHECK(callbacks);
191
192 int request_id = pending_get_registrations_callbacks_.Add(callbacks);
193 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker",
194 "ServiceWorkerDispatcher::GetRegistrations",
195 request_id,
196 "Document URL", document_url.spec());
197 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrations(
198 CurrentWorkerId(), request_id, provider_id, document_url));
199 }
200
182 void ServiceWorkerDispatcher::GetRegistrationForReady( 201 void ServiceWorkerDispatcher::GetRegistrationForReady(
183 int provider_id, 202 int provider_id,
184 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { 203 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) {
185 int request_id = get_for_ready_callbacks_.Add(callbacks); 204 int request_id = get_for_ready_callbacks_.Add(callbacks);
186 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", 205 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker",
187 "ServiceWorkerDispatcher::GetRegistrationForReady", 206 "ServiceWorkerDispatcher::GetRegistrationForReady",
188 request_id); 207 request_id);
189 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady( 208 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady(
190 CurrentWorkerId(), request_id, provider_id)); 209 CurrentWorkerId(), request_id, provider_id));
191 } 210 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 return; 428 return;
410 429
411 WebServiceWorkerRegistrationImpl* registration = NULL; 430 WebServiceWorkerRegistrationImpl* registration = NULL;
412 if (info.handle_id != kInvalidServiceWorkerHandleId) 431 if (info.handle_id != kInvalidServiceWorkerHandleId)
413 registration = FindOrCreateRegistration(info, attrs); 432 registration = FindOrCreateRegistration(info, attrs);
414 433
415 callbacks->onSuccess(registration); 434 callbacks->onSuccess(registration);
416 pending_get_registration_callbacks_.Remove(request_id); 435 pending_get_registration_callbacks_.Remove(request_id);
417 } 436 }
418 437
438 void ServiceWorkerDispatcher::OnDidGetRegistrations(
439 int thread_id,
440 int request_id,
441 const std::vector<ServiceWorkerRegistrationObjectInfo>& infos,
442 const std::vector<ServiceWorkerVersionAttributes>& attrs) {
443 TRACE_EVENT_ASYNC_STEP_INTO0(
444 "ServiceWorker",
445 "ServiceWorkerDispatcher::GetRegistrations",
446 request_id,
447 "OnDidGetRegistrations");
448 TRACE_EVENT_ASYNC_END0("ServiceWorker",
449 "ServiceWorkerDispatcher::GetRegistrations",
450 request_id);
451
452 WebServiceWorkerGetRegistrationsCallbacks* callbacks =
453 pending_get_registrations_callbacks_.Lookup(request_id);
454 DCHECK(callbacks);
455 if (!callbacks)
456 return;
457
458 typedef blink::WebVector<blink::WebServiceWorkerRegistration*>
459 WebServiceWorkerRegistrationArray;
460 scoped_ptr<WebServiceWorkerRegistrationArray>
461 registrations(new WebServiceWorkerRegistrationArray(infos.size()));
462 for (size_t i = 0; i < infos.size(); ++i) {
463 if (infos[i].handle_id != kInvalidServiceWorkerHandleId) {
464 ServiceWorkerRegistrationObjectInfo info(infos[i]);
465 ServiceWorkerVersionAttributes attr(attrs[i]);
466 (*registrations)[i] = FindOrCreateRegistration(info, attr);
467 }
468 }
469
470 callbacks->onSuccess(registrations.release());
471 pending_get_registrations_callbacks_.Remove(request_id);
472 }
473
419 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady( 474 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady(
420 int thread_id, 475 int thread_id,
421 int request_id, 476 int request_id,
422 const ServiceWorkerRegistrationObjectInfo& info, 477 const ServiceWorkerRegistrationObjectInfo& info,
423 const ServiceWorkerVersionAttributes& attrs) { 478 const ServiceWorkerVersionAttributes& attrs) {
424 TRACE_EVENT_ASYNC_STEP_INTO0( 479 TRACE_EVENT_ASYNC_STEP_INTO0(
425 "ServiceWorker", 480 "ServiceWorker",
426 "ServiceWorkerDispatcher::GetRegistrationForReady", 481 "ServiceWorkerDispatcher::GetRegistrationForReady",
427 request_id, 482 request_id,
428 "OnDidGetRegistrationForReady"); 483 "OnDidGetRegistrationForReady");
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 DCHECK(callbacks); 564 DCHECK(callbacks);
510 if (!callbacks) 565 if (!callbacks)
511 return; 566 return;
512 567
513 scoped_ptr<WebServiceWorkerError> error( 568 scoped_ptr<WebServiceWorkerError> error(
514 new WebServiceWorkerError(error_type, message)); 569 new WebServiceWorkerError(error_type, message));
515 callbacks->onError(error.release()); 570 callbacks->onError(error.release());
516 pending_get_registration_callbacks_.Remove(request_id); 571 pending_get_registration_callbacks_.Remove(request_id);
517 } 572 }
518 573
574 void ServiceWorkerDispatcher::OnGetRegistrationsError(
575 int thread_id,
576 int request_id,
577 WebServiceWorkerError::ErrorType error_type,
578 const base::string16& message) {
579 TRACE_EVENT_ASYNC_STEP_INTO0(
580 "ServiceWorker",
581 "ServiceWorkerDispatcher::GetRegistrations",
582 request_id,
583 "OnGetRegistrationsError");
584 TRACE_EVENT_ASYNC_END0("ServiceWorker",
585 "ServiceWorkerDispatcher::GetRegistrations",
586 request_id);
587 WebServiceWorkerGetRegistrationsCallbacks* callbacks =
588 pending_get_registrations_callbacks_.Lookup(request_id);
589 DCHECK(callbacks);
590 if (!callbacks)
591 return;
592
593 scoped_ptr<WebServiceWorkerError> error(
594 new WebServiceWorkerError(error_type, message));
595 callbacks->onError(error.release());
596 pending_get_registration_callbacks_.Remove(request_id);
597 }
598
519 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( 599 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
520 int thread_id, 600 int thread_id,
521 int handle_id, 601 int handle_id,
522 blink::WebServiceWorkerState state) { 602 blink::WebServiceWorkerState state) {
523 TRACE_EVENT2("ServiceWorker", 603 TRACE_EVENT2("ServiceWorker",
524 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", 604 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged",
525 "Thread ID", thread_id, 605 "Thread ID", thread_id,
526 "State", state); 606 "State", state);
527 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); 607 WorkerObjectMap::iterator worker = service_workers_.find(handle_id);
528 if (worker != service_workers_.end()) 608 if (worker != service_workers_.end())
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 bool adopt_handle = true; 767 bool adopt_handle = true;
688 WebServiceWorkerRegistrationImpl* registration = 768 WebServiceWorkerRegistrationImpl* registration =
689 CreateServiceWorkerRegistration(info, adopt_handle); 769 CreateServiceWorkerRegistration(info, adopt_handle);
690 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); 770 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle));
691 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); 771 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle));
692 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); 772 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle));
693 return registration; 773 return registration;
694 } 774 }
695 775
696 } // namespace content 776 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698