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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
13 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
14 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
15 #include "content/child/service_worker/service_worker_handle_reference.h" | 16 #include "content/child/service_worker/service_worker_handle_reference.h" |
16 #include "content/child/service_worker/service_worker_provider_context.h" | 17 #include "content/child/service_worker/service_worker_provider_context.h" |
17 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 18 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 scoped_ptr<ServiceWorkerHandleReference> handle_ref) { | 269 scoped_ptr<ServiceWorkerHandleReference> handle_ref) { |
269 if (!handle_ref) | 270 if (!handle_ref) |
270 return nullptr; | 271 return nullptr; |
271 | 272 |
272 WorkerObjectMap::iterator found = | 273 WorkerObjectMap::iterator found = |
273 service_workers_.find(handle_ref->handle_id()); | 274 service_workers_.find(handle_ref->handle_id()); |
274 if (found != service_workers_.end()) | 275 if (found != service_workers_.end()) |
275 return found->second; | 276 return found->second; |
276 | 277 |
277 // WebServiceWorkerImpl constructor calls AddServiceWorker. | 278 // WebServiceWorkerImpl constructor calls AddServiceWorker. |
278 return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_.get()); | 279 return new WebServiceWorkerImpl(std::move(handle_ref), |
| 280 thread_safe_sender_.get()); |
279 } | 281 } |
280 | 282 |
281 scoped_refptr<WebServiceWorkerRegistrationImpl> | 283 scoped_refptr<WebServiceWorkerRegistrationImpl> |
282 ServiceWorkerDispatcher::GetOrCreateRegistration( | 284 ServiceWorkerDispatcher::GetOrCreateRegistration( |
283 const ServiceWorkerRegistrationObjectInfo& info, | 285 const ServiceWorkerRegistrationObjectInfo& info, |
284 const ServiceWorkerVersionAttributes& attrs) { | 286 const ServiceWorkerVersionAttributes& attrs) { |
285 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); | 287 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); |
286 if (found != registrations_.end()) | 288 if (found != registrations_.end()) |
287 return found->second; | 289 return found->second; |
288 | 290 |
(...skipping 27 matching lines...) Expand all Loading... |
316 scoped_ptr<ServiceWorkerHandleReference> waiting_ref = Adopt(attrs.waiting); | 318 scoped_ptr<ServiceWorkerHandleReference> waiting_ref = Adopt(attrs.waiting); |
317 scoped_ptr<ServiceWorkerHandleReference> active_ref = Adopt(attrs.active); | 319 scoped_ptr<ServiceWorkerHandleReference> active_ref = Adopt(attrs.active); |
318 | 320 |
319 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); | 321 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); |
320 if (found != registrations_.end()) | 322 if (found != registrations_.end()) |
321 return found->second; | 323 return found->second; |
322 | 324 |
323 // WebServiceWorkerRegistrationImpl constructor calls | 325 // WebServiceWorkerRegistrationImpl constructor calls |
324 // AddServiceWorkerRegistration. | 326 // AddServiceWorkerRegistration. |
325 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( | 327 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( |
326 new WebServiceWorkerRegistrationImpl(registration_ref.Pass())); | 328 new WebServiceWorkerRegistrationImpl(std::move(registration_ref))); |
327 registration->SetInstalling(GetOrCreateServiceWorker(installing_ref.Pass())); | 329 registration->SetInstalling( |
328 registration->SetWaiting(GetOrCreateServiceWorker(waiting_ref.Pass())); | 330 GetOrCreateServiceWorker(std::move(installing_ref))); |
329 registration->SetActive(GetOrCreateServiceWorker(active_ref.Pass())); | 331 registration->SetWaiting(GetOrCreateServiceWorker(std::move(waiting_ref))); |
| 332 registration->SetActive(GetOrCreateServiceWorker(std::move(active_ref))); |
330 return registration; | 333 return registration; |
331 } | 334 } |
332 | 335 |
333 void ServiceWorkerDispatcher::OnAssociateRegistration( | 336 void ServiceWorkerDispatcher::OnAssociateRegistration( |
334 int thread_id, | 337 int thread_id, |
335 int provider_id, | 338 int provider_id, |
336 const ServiceWorkerRegistrationObjectInfo& info, | 339 const ServiceWorkerRegistrationObjectInfo& info, |
337 const ServiceWorkerVersionAttributes& attrs) { | 340 const ServiceWorkerVersionAttributes& attrs) { |
338 // Adopt the references sent from the browser process and pass them to the | 341 // Adopt the references sent from the browser process and pass them to the |
339 // provider context if it exists. | 342 // provider context if it exists. |
340 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration = | 343 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration = |
341 Adopt(info); | 344 Adopt(info); |
342 scoped_ptr<ServiceWorkerHandleReference> installing = Adopt(attrs.installing); | 345 scoped_ptr<ServiceWorkerHandleReference> installing = Adopt(attrs.installing); |
343 scoped_ptr<ServiceWorkerHandleReference> waiting = Adopt(attrs.waiting); | 346 scoped_ptr<ServiceWorkerHandleReference> waiting = Adopt(attrs.waiting); |
344 scoped_ptr<ServiceWorkerHandleReference> active = Adopt(attrs.active); | 347 scoped_ptr<ServiceWorkerHandleReference> active = Adopt(attrs.active); |
345 ProviderContextMap::iterator context = provider_contexts_.find(provider_id); | 348 ProviderContextMap::iterator context = provider_contexts_.find(provider_id); |
346 if (context != provider_contexts_.end()) { | 349 if (context != provider_contexts_.end()) { |
347 context->second->OnAssociateRegistration( | 350 context->second->OnAssociateRegistration( |
348 registration.Pass(), installing.Pass(), waiting.Pass(), active.Pass()); | 351 std::move(registration), std::move(installing), std::move(waiting), |
| 352 std::move(active)); |
349 } | 353 } |
350 } | 354 } |
351 | 355 |
352 void ServiceWorkerDispatcher::OnDisassociateRegistration( | 356 void ServiceWorkerDispatcher::OnDisassociateRegistration( |
353 int thread_id, | 357 int thread_id, |
354 int provider_id) { | 358 int provider_id) { |
355 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 359 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
356 if (provider == provider_contexts_.end()) | 360 if (provider == provider_contexts_.end()) |
357 return; | 361 return; |
358 provider->second->OnDisassociateRegistration(); | 362 provider->second->OnDisassociateRegistration(); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 scoped_ptr<ServiceWorkerHandleReference> installing = Adopt(attrs.installing); | 654 scoped_ptr<ServiceWorkerHandleReference> installing = Adopt(attrs.installing); |
651 scoped_ptr<ServiceWorkerHandleReference> waiting = Adopt(attrs.waiting); | 655 scoped_ptr<ServiceWorkerHandleReference> waiting = Adopt(attrs.waiting); |
652 scoped_ptr<ServiceWorkerHandleReference> active = Adopt(attrs.active); | 656 scoped_ptr<ServiceWorkerHandleReference> active = Adopt(attrs.active); |
653 | 657 |
654 RegistrationObjectMap::iterator found = | 658 RegistrationObjectMap::iterator found = |
655 registrations_.find(registration_handle_id); | 659 registrations_.find(registration_handle_id); |
656 if (found != registrations_.end()) { | 660 if (found != registrations_.end()) { |
657 // Populate the version fields (eg. .installing) with worker objects. | 661 // Populate the version fields (eg. .installing) with worker objects. |
658 ChangedVersionAttributesMask mask(changed_mask); | 662 ChangedVersionAttributesMask mask(changed_mask); |
659 if (mask.installing_changed()) | 663 if (mask.installing_changed()) |
660 found->second->SetInstalling(GetOrCreateServiceWorker(installing.Pass())); | 664 found->second->SetInstalling( |
| 665 GetOrCreateServiceWorker(std::move(installing))); |
661 if (mask.waiting_changed()) | 666 if (mask.waiting_changed()) |
662 found->second->SetWaiting(GetOrCreateServiceWorker(waiting.Pass())); | 667 found->second->SetWaiting(GetOrCreateServiceWorker(std::move(waiting))); |
663 if (mask.active_changed()) | 668 if (mask.active_changed()) |
664 found->second->SetActive(GetOrCreateServiceWorker(active.Pass())); | 669 found->second->SetActive(GetOrCreateServiceWorker(std::move(active))); |
665 } | 670 } |
666 } | 671 } |
667 | 672 |
668 void ServiceWorkerDispatcher::OnUpdateFound( | 673 void ServiceWorkerDispatcher::OnUpdateFound( |
669 int thread_id, | 674 int thread_id, |
670 int registration_handle_id) { | 675 int registration_handle_id) { |
671 TRACE_EVENT0("ServiceWorker", | 676 TRACE_EVENT0("ServiceWorker", |
672 "ServiceWorkerDispatcher::OnUpdateFound"); | 677 "ServiceWorkerDispatcher::OnUpdateFound"); |
673 RegistrationObjectMap::iterator found = | 678 RegistrationObjectMap::iterator found = |
674 registrations_.find(registration_handle_id); | 679 registrations_.find(registration_handle_id); |
675 if (found != registrations_.end()) | 680 if (found != registrations_.end()) |
676 found->second->OnUpdateFound(); | 681 found->second->OnUpdateFound(); |
677 } | 682 } |
678 | 683 |
679 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( | 684 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( |
680 int thread_id, | 685 int thread_id, |
681 int provider_id, | 686 int provider_id, |
682 const ServiceWorkerObjectInfo& info, | 687 const ServiceWorkerObjectInfo& info, |
683 bool should_notify_controllerchange) { | 688 bool should_notify_controllerchange) { |
684 TRACE_EVENT2("ServiceWorker", | 689 TRACE_EVENT2("ServiceWorker", |
685 "ServiceWorkerDispatcher::OnSetControllerServiceWorker", | 690 "ServiceWorkerDispatcher::OnSetControllerServiceWorker", |
686 "Thread ID", thread_id, | 691 "Thread ID", thread_id, |
687 "Provider ID", provider_id); | 692 "Provider ID", provider_id); |
688 | 693 |
689 // Adopt the reference sent from the browser process and pass it to the | 694 // Adopt the reference sent from the browser process and pass it to the |
690 // provider context if it exists. | 695 // provider context if it exists. |
691 scoped_ptr<ServiceWorkerHandleReference> handle_ref = Adopt(info); | 696 scoped_ptr<ServiceWorkerHandleReference> handle_ref = Adopt(info); |
692 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 697 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
693 if (provider != provider_contexts_.end()) | 698 if (provider != provider_contexts_.end()) |
694 provider->second->OnSetControllerServiceWorker(handle_ref.Pass()); | 699 provider->second->OnSetControllerServiceWorker(std::move(handle_ref)); |
695 | 700 |
696 ProviderClientMap::iterator found = provider_clients_.find(provider_id); | 701 ProviderClientMap::iterator found = provider_clients_.find(provider_id); |
697 if (found != provider_clients_.end()) { | 702 if (found != provider_clients_.end()) { |
698 // Get the existing worker object or create a new one with a new reference | 703 // Get the existing worker object or create a new one with a new reference |
699 // to populate the .controller field. | 704 // to populate the .controller field. |
700 scoped_refptr<WebServiceWorkerImpl> worker = GetOrCreateServiceWorker( | 705 scoped_refptr<WebServiceWorkerImpl> worker = GetOrCreateServiceWorker( |
701 ServiceWorkerHandleReference::Create(info, thread_safe_sender_.get())); | 706 ServiceWorkerHandleReference::Create(info, thread_safe_sender_.get())); |
702 found->second->setController(WebServiceWorkerImpl::CreateHandle(worker), | 707 found->second->setController(WebServiceWorkerImpl::CreateHandle(worker), |
703 should_notify_controllerchange); | 708 should_notify_controllerchange); |
704 } | 709 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 return ServiceWorkerRegistrationHandleReference::Adopt( | 769 return ServiceWorkerRegistrationHandleReference::Adopt( |
765 info, thread_safe_sender_.get()); | 770 info, thread_safe_sender_.get()); |
766 } | 771 } |
767 | 772 |
768 scoped_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( | 773 scoped_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
769 const ServiceWorkerObjectInfo& info) { | 774 const ServiceWorkerObjectInfo& info) { |
770 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 775 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
771 } | 776 } |
772 | 777 |
773 } // namespace content | 778 } // namespace content |
OLD | NEW |