| 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/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 352 |
| 353 // We can assume that this message handler is called before the worker context | 353 // We can assume that this message handler is called before the worker context |
| 354 // starts because script loading happens after this association. | 354 // starts because script loading happens after this association. |
| 355 void ServiceWorkerDispatcher::OnAssociateRegistrationWithServiceWorker( | 355 void ServiceWorkerDispatcher::OnAssociateRegistrationWithServiceWorker( |
| 356 int thread_id, | 356 int thread_id, |
| 357 int provider_id, | 357 int provider_id, |
| 358 const ServiceWorkerRegistrationObjectInfo& info, | 358 const ServiceWorkerRegistrationObjectInfo& info, |
| 359 const ServiceWorkerVersionAttributes& attrs) { | 359 const ServiceWorkerVersionAttributes& attrs) { |
| 360 DCHECK_EQ(kDocumentMainThreadId, thread_id); | 360 DCHECK_EQ(kDocumentMainThreadId, thread_id); |
| 361 | 361 |
| 362 // Adopt the references sent from the browser process and pass them to the |
| 363 // provider context if it exists. |
| 364 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration = |
| 365 Adopt(info); |
| 366 scoped_ptr<ServiceWorkerHandleReference> installing = Adopt(attrs.installing); |
| 367 scoped_ptr<ServiceWorkerHandleReference> waiting = Adopt(attrs.waiting); |
| 368 scoped_ptr<ServiceWorkerHandleReference> active = Adopt(attrs.active); |
| 362 ProviderContextMap::iterator context = provider_contexts_.find(provider_id); | 369 ProviderContextMap::iterator context = provider_contexts_.find(provider_id); |
| 363 if (context == provider_contexts_.end()) | 370 if (context != provider_contexts_.end()) { |
| 364 return; | 371 context->second->OnAssociateRegistration( |
| 365 context->second->OnAssociateRegistration(info, attrs); | 372 registration.Pass(), installing.Pass(), waiting.Pass(), active.Pass()); |
| 373 } |
| 366 } | 374 } |
| 367 | 375 |
| 368 void ServiceWorkerDispatcher::OnAssociateRegistration( | 376 void ServiceWorkerDispatcher::OnAssociateRegistration( |
| 369 int thread_id, | 377 int thread_id, |
| 370 int provider_id, | 378 int provider_id, |
| 371 const ServiceWorkerRegistrationObjectInfo& info, | 379 const ServiceWorkerRegistrationObjectInfo& info, |
| 372 const ServiceWorkerVersionAttributes& attrs) { | 380 const ServiceWorkerVersionAttributes& attrs) { |
| 373 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 381 // Adopt the references sent from the browser process and pass them to the |
| 374 if (provider == provider_contexts_.end()) | 382 // provider context if it exists. |
| 375 return; | 383 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration = |
| 376 provider->second->OnAssociateRegistration(info, attrs); | 384 Adopt(info); |
| 385 scoped_ptr<ServiceWorkerHandleReference> installing = Adopt(attrs.installing); |
| 386 scoped_ptr<ServiceWorkerHandleReference> waiting = Adopt(attrs.waiting); |
| 387 scoped_ptr<ServiceWorkerHandleReference> active = Adopt(attrs.active); |
| 388 ProviderContextMap::iterator context = provider_contexts_.find(provider_id); |
| 389 if (context != provider_contexts_.end()) { |
| 390 context->second->OnAssociateRegistration( |
| 391 registration.Pass(), installing.Pass(), waiting.Pass(), active.Pass()); |
| 392 } |
| 377 } | 393 } |
| 378 | 394 |
| 379 void ServiceWorkerDispatcher::OnDisassociateRegistration( | 395 void ServiceWorkerDispatcher::OnDisassociateRegistration( |
| 380 int thread_id, | 396 int thread_id, |
| 381 int provider_id) { | 397 int provider_id) { |
| 382 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 398 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 383 if (provider == provider_contexts_.end()) | 399 if (provider == provider_contexts_.end()) |
| 384 return; | 400 return; |
| 385 provider->second->OnDisassociateRegistration(); | 401 provider->second->OnDisassociateRegistration(); |
| 386 } | 402 } |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 DCHECK(!ContainsKey(registrations_, registration_handle_id)); | 785 DCHECK(!ContainsKey(registrations_, registration_handle_id)); |
| 770 registrations_[registration_handle_id] = registration; | 786 registrations_[registration_handle_id] = registration; |
| 771 } | 787 } |
| 772 | 788 |
| 773 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 789 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
| 774 int registration_handle_id) { | 790 int registration_handle_id) { |
| 775 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 791 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
| 776 registrations_.erase(registration_handle_id); | 792 registrations_.erase(registration_handle_id); |
| 777 } | 793 } |
| 778 | 794 |
| 795 scoped_ptr<ServiceWorkerRegistrationHandleReference> |
| 796 ServiceWorkerDispatcher::Adopt( |
| 797 const ServiceWorkerRegistrationObjectInfo& info) { |
| 798 return ServiceWorkerRegistrationHandleReference::Adopt( |
| 799 info, thread_safe_sender_.get()); |
| 800 } |
| 801 |
| 802 scoped_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
| 803 const ServiceWorkerObjectInfo& info) { |
| 804 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
| 805 } |
| 806 |
| 779 } // namespace content | 807 } // namespace content |
| OLD | NEW |