| 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/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 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 | 680 |
| 681 ProviderClientMap::iterator found = provider_clients_.find(provider_id); | 681 ProviderClientMap::iterator found = provider_clients_.find(provider_id); |
| 682 if (found != provider_clients_.end()) { | 682 if (found != provider_clients_.end()) { |
| 683 // Populate the .controller field with the new worker object. | 683 // Populate the .controller field with the new worker object. |
| 684 found->second->setController(GetServiceWorker(info, false), | 684 found->second->setController(GetServiceWorker(info, false), |
| 685 should_notify_controllerchange); | 685 should_notify_controllerchange); |
| 686 } | 686 } |
| 687 } | 687 } |
| 688 | 688 |
| 689 void ServiceWorkerDispatcher::OnPostMessage( | 689 void ServiceWorkerDispatcher::OnPostMessage( |
| 690 int thread_id, | 690 const ServiceWorkerMsg_MessageToDocument_Params& params) { |
| 691 int provider_id, | |
| 692 const base::string16& message, | |
| 693 const std::vector<TransferredMessagePort>& sent_message_ports, | |
| 694 const std::vector<int>& new_routing_ids) { | |
| 695 // Make sure we're on the main document thread. (That must be the only | 691 // Make sure we're on the main document thread. (That must be the only |
| 696 // thread we get this message) | 692 // thread we get this message) |
| 697 DCHECK(ChildThreadImpl::current()); | 693 DCHECK(ChildThreadImpl::current()); |
| 698 TRACE_EVENT1("ServiceWorker", | 694 TRACE_EVENT1("ServiceWorker", "ServiceWorkerDispatcher::OnPostMessage", |
| 699 "ServiceWorkerDispatcher::OnPostMessage", | 695 "Thread ID", params.thread_id); |
| 700 "Thread ID", thread_id); | |
| 701 | 696 |
| 702 ProviderClientMap::iterator found = provider_clients_.find(provider_id); | 697 ProviderClientMap::iterator found = |
| 698 provider_clients_.find(params.provider_id); |
| 703 if (found == provider_clients_.end()) { | 699 if (found == provider_clients_.end()) { |
| 704 // For now we do no queueing for messages sent to nonexistent / unattached | 700 // For now we do no queueing for messages sent to nonexistent / unattached |
| 705 // client. | 701 // client. |
| 706 return; | 702 return; |
| 707 } | 703 } |
| 708 | 704 |
| 709 blink::WebMessagePortChannelArray ports = | 705 blink::WebMessagePortChannelArray ports = |
| 710 WebMessagePortChannelImpl::CreatePorts( | 706 WebMessagePortChannelImpl::CreatePorts( |
| 711 sent_message_ports, new_routing_ids, | 707 params.message_ports, params.new_routing_ids, |
| 712 base::ThreadTaskRunnerHandle::Get()); | 708 base::ThreadTaskRunnerHandle::Get()); |
| 713 | 709 |
| 714 found->second->dispatchMessageEvent(message, ports); | 710 found->second->dispatchMessageEvent( |
| 711 GetServiceWorker(params.service_worker_info, false /* adopt_handle */), |
| 712 params.message, ports); |
| 715 } | 713 } |
| 716 | 714 |
| 717 void ServiceWorkerDispatcher::AddServiceWorker( | 715 void ServiceWorkerDispatcher::AddServiceWorker( |
| 718 int handle_id, WebServiceWorkerImpl* worker) { | 716 int handle_id, WebServiceWorkerImpl* worker) { |
| 719 DCHECK(!ContainsKey(service_workers_, handle_id)); | 717 DCHECK(!ContainsKey(service_workers_, handle_id)); |
| 720 service_workers_[handle_id] = worker; | 718 service_workers_[handle_id] = worker; |
| 721 } | 719 } |
| 722 | 720 |
| 723 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { | 721 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { |
| 724 DCHECK(ContainsKey(service_workers_, handle_id)); | 722 DCHECK(ContainsKey(service_workers_, handle_id)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 bool adopt_handle = true; | 756 bool adopt_handle = true; |
| 759 WebServiceWorkerRegistrationImpl* registration = | 757 WebServiceWorkerRegistrationImpl* registration = |
| 760 CreateServiceWorkerRegistration(info, adopt_handle); | 758 CreateServiceWorkerRegistration(info, adopt_handle); |
| 761 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); | 759 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); |
| 762 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); | 760 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); |
| 763 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); | 761 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); |
| 764 return registration; | 762 return registration; |
| 765 } | 763 } |
| 766 | 764 |
| 767 } // namespace content | 765 } // namespace content |
| OLD | NEW |