Chromium Code Reviews| 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/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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 | 609 |
| 610 ProviderClientMap::iterator found = provider_clients_.find(provider_id); | 610 ProviderClientMap::iterator found = provider_clients_.find(provider_id); |
| 611 if (found != provider_clients_.end()) { | 611 if (found != provider_clients_.end()) { |
| 612 // Populate the .controller field with the new worker object. | 612 // Populate the .controller field with the new worker object. |
| 613 found->second->setController(GetServiceWorker(info, false), | 613 found->second->setController(GetServiceWorker(info, false), |
| 614 should_notify_controllerchange); | 614 should_notify_controllerchange); |
| 615 } | 615 } |
| 616 } | 616 } |
| 617 | 617 |
| 618 void ServiceWorkerDispatcher::OnPostMessage( | 618 void ServiceWorkerDispatcher::OnPostMessage( |
| 619 int thread_id, | 619 const ServiceWorkerMsg_MessageToDocument_Params& params) { |
| 620 int provider_id, | |
| 621 const base::string16& message, | |
| 622 const std::vector<TransferredMessagePort>& sent_message_ports, | |
| 623 const std::vector<int>& new_routing_ids) { | |
| 624 // Make sure we're on the main document thread. (That must be the only | 620 // Make sure we're on the main document thread. (That must be the only |
| 625 // thread we get this message) | 621 // thread we get this message) |
| 626 DCHECK(ChildThreadImpl::current()); | 622 DCHECK(ChildThreadImpl::current()); |
| 627 TRACE_EVENT1("ServiceWorker", | 623 TRACE_EVENT1("ServiceWorker", "ServiceWorkerDispatcher::OnPostMessage", |
| 628 "ServiceWorkerDispatcher::OnPostMessage", | 624 "Thread ID", params.thread_id); |
| 629 "Thread ID", thread_id); | |
| 630 | 625 |
| 631 ProviderClientMap::iterator found = provider_clients_.find(provider_id); | 626 ProviderClientMap::iterator found = |
| 627 provider_clients_.find(params.provider_id); | |
| 632 if (found == provider_clients_.end()) { | 628 if (found == provider_clients_.end()) { |
| 633 // For now we do no queueing for messages sent to nonexistent / unattached | 629 // For now we do no queueing for messages sent to nonexistent / unattached |
| 634 // client. | 630 // client. |
| 635 return; | 631 return; |
| 636 } | 632 } |
| 637 | 633 |
| 638 blink::WebMessagePortChannelArray ports = | 634 blink::WebMessagePortChannelArray ports = |
| 639 WebMessagePortChannelImpl::CreatePorts(sent_message_ports, | 635 WebMessagePortChannelImpl::CreatePorts(params.message_ports, |
| 640 new_routing_ids, | 636 params.new_routing_ids, |
| 641 base::MessageLoopProxy::current()); | 637 base::MessageLoopProxy::current()); |
| 642 | 638 |
| 643 found->second->dispatchMessageEvent(message, ports); | 639 found->second->dispatchMessageEvent( |
| 640 GetServiceWorker(params.service_worker_info, false), | |
|
falken
2015/05/18 03:37:09
nit: false /* adopt_handle */
xiang
2015/06/15 02:37:34
Done.
| |
| 641 params.message, ports); | |
| 644 } | 642 } |
| 645 | 643 |
| 646 void ServiceWorkerDispatcher::AddServiceWorker( | 644 void ServiceWorkerDispatcher::AddServiceWorker( |
| 647 int handle_id, WebServiceWorkerImpl* worker) { | 645 int handle_id, WebServiceWorkerImpl* worker) { |
| 648 DCHECK(!ContainsKey(service_workers_, handle_id)); | 646 DCHECK(!ContainsKey(service_workers_, handle_id)); |
| 649 service_workers_[handle_id] = worker; | 647 service_workers_[handle_id] = worker; |
| 650 } | 648 } |
| 651 | 649 |
| 652 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { | 650 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { |
| 653 DCHECK(ContainsKey(service_workers_, handle_id)); | 651 DCHECK(ContainsKey(service_workers_, handle_id)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 bool adopt_handle = true; | 685 bool adopt_handle = true; |
| 688 WebServiceWorkerRegistrationImpl* registration = | 686 WebServiceWorkerRegistrationImpl* registration = |
| 689 CreateServiceWorkerRegistration(info, adopt_handle); | 687 CreateServiceWorkerRegistration(info, adopt_handle); |
| 690 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); | 688 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); |
| 691 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); | 689 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); |
| 692 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); | 690 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); |
| 693 return registration; | 691 return registration; |
| 694 } | 692 } |
| 695 | 693 |
| 696 } // namespace content | 694 } // namespace content |
| OLD | NEW |