| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/renderer/service_worker/service_worker_context_client.h" | 5 #include "content/renderer/service_worker/service_worker_context_client.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "base/threading/thread_local.h" | 15 #include "base/threading/thread_local.h" |
| 16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "content/child/navigator_connect/service_port_dispatcher_impl.h" | 17 #include "content/child/navigator_connect/service_port_dispatcher_impl.h" |
| 18 #include "content/child/notifications/notification_data_conversions.h" | 18 #include "content/child/notifications/notification_data_conversions.h" |
| 19 #include "content/child/request_extra_data.h" | 19 #include "content/child/request_extra_data.h" |
| 20 #include "content/child/service_worker/service_worker_dispatcher.h" | 20 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 21 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 21 #include "content/child/service_worker/service_worker_network_provider.h" | 22 #include "content/child/service_worker/service_worker_network_provider.h" |
| 22 #include "content/child/service_worker/service_worker_provider_context.h" | 23 #include "content/child/service_worker/service_worker_provider_context.h" |
| 23 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 24 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
| 24 #include "content/child/service_worker/web_service_worker_impl.h" | 25 #include "content/child/service_worker/web_service_worker_impl.h" |
| 25 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 26 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
| 26 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 27 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 27 #include "content/child/thread_safe_sender.h" | 28 #include "content/child/thread_safe_sender.h" |
| 28 #include "content/child/webmessageportchannel_impl.h" | 29 #include "content/child/webmessageportchannel_impl.h" |
| 29 #include "content/common/devtools_messages.h" | 30 #include "content/common/devtools_messages.h" |
| 30 #include "content/common/geofencing_messages.h" | 31 #include "content/common/geofencing_messages.h" |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 void ServiceWorkerContextClient::OnActivateEvent(int request_id) { | 733 void ServiceWorkerContextClient::OnActivateEvent(int request_id) { |
| 733 TRACE_EVENT0("ServiceWorker", | 734 TRACE_EVENT0("ServiceWorker", |
| 734 "ServiceWorkerContextClient::OnActivateEvent"); | 735 "ServiceWorkerContextClient::OnActivateEvent"); |
| 735 proxy_->dispatchActivateEvent(request_id); | 736 proxy_->dispatchActivateEvent(request_id); |
| 736 } | 737 } |
| 737 | 738 |
| 738 void ServiceWorkerContextClient::OnExtendableMessageEvent( | 739 void ServiceWorkerContextClient::OnExtendableMessageEvent( |
| 739 int request_id, | 740 int request_id, |
| 740 const base::string16& message, | 741 const base::string16& message, |
| 741 const std::vector<TransferredMessagePort>& sent_message_ports, | 742 const std::vector<TransferredMessagePort>& sent_message_ports, |
| 742 const std::vector<int>& new_routing_ids) { | 743 const std::vector<int>& new_routing_ids, |
| 744 const ExtendableMessageEventSource& source) { |
| 743 TRACE_EVENT0("ServiceWorker", | 745 TRACE_EVENT0("ServiceWorker", |
| 744 "ServiceWorkerContextClient::OnExtendableMessageEvent"); | 746 "ServiceWorkerContextClient::OnExtendableMessageEvent"); |
| 745 blink::WebMessagePortChannelArray ports = | 747 blink::WebMessagePortChannelArray ports = |
| 746 WebMessagePortChannelImpl::CreatePorts( | 748 WebMessagePortChannelImpl::CreatePorts( |
| 747 sent_message_ports, new_routing_ids, main_thread_task_runner_); | 749 sent_message_ports, new_routing_ids, main_thread_task_runner_); |
| 748 proxy_->dispatchExtendableMessageEvent(request_id, message, ports); | 750 |
| 751 if (source.client_info.IsValid()) { |
| 752 blink::WebServiceWorkerClientInfo web_client = |
| 753 ToWebServiceWorkerClientInfo(source.client_info); |
| 754 proxy_->dispatchExtendableMessageEvent(request_id, message, ports, |
| 755 web_client); |
| 756 return; |
| 757 } |
| 758 |
| 759 DCHECK(source.service_worker_info.IsValid()); |
| 760 scoped_ptr<ServiceWorkerHandleReference> handle = |
| 761 ServiceWorkerHandleReference::Adopt(source.service_worker_info, |
| 762 sender_.get()); |
| 763 ServiceWorkerDispatcher* dispatcher = |
| 764 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
| 765 sender_.get(), main_thread_task_runner_.get()); |
| 766 scoped_refptr<WebServiceWorkerImpl> worker = |
| 767 dispatcher->GetOrCreateServiceWorker(std::move(handle)); |
| 768 proxy_->dispatchExtendableMessageEvent( |
| 769 request_id, message, ports, WebServiceWorkerImpl::CreateHandle(worker)); |
| 749 } | 770 } |
| 750 | 771 |
| 751 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { | 772 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { |
| 752 TRACE_EVENT0("ServiceWorker", | 773 TRACE_EVENT0("ServiceWorker", |
| 753 "ServiceWorkerContextClient::OnInstallEvent"); | 774 "ServiceWorkerContextClient::OnInstallEvent"); |
| 754 proxy_->dispatchInstallEvent(request_id); | 775 proxy_->dispatchInstallEvent(request_id); |
| 755 } | 776 } |
| 756 | 777 |
| 757 void ServiceWorkerContextClient::OnFetchEvent( | 778 void ServiceWorkerContextClient::OnFetchEvent( |
| 758 int request_id, | 779 int request_id, |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 } | 1089 } |
| 1069 | 1090 |
| 1070 base::WeakPtr<ServiceWorkerContextClient> | 1091 base::WeakPtr<ServiceWorkerContextClient> |
| 1071 ServiceWorkerContextClient::GetWeakPtr() { | 1092 ServiceWorkerContextClient::GetWeakPtr() { |
| 1072 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1093 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1073 DCHECK(context_); | 1094 DCHECK(context_); |
| 1074 return context_->weak_factory.GetWeakPtr(); | 1095 return context_->weak_factory.GetWeakPtr(); |
| 1075 } | 1096 } |
| 1076 | 1097 |
| 1077 } // namespace content | 1098 } // namespace content |
| OLD | NEW |