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 <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 return g_worker_client_tls.Pointer()->Get(); | 547 return g_worker_client_tls.Pointer()->Get(); |
548 } | 548 } |
549 | 549 |
550 ServiceWorkerContextClient::ServiceWorkerContextClient( | 550 ServiceWorkerContextClient::ServiceWorkerContextClient( |
551 int embedded_worker_id, | 551 int embedded_worker_id, |
552 int64_t service_worker_version_id, | 552 int64_t service_worker_version_id, |
553 const GURL& service_worker_scope, | 553 const GURL& service_worker_scope, |
554 const GURL& script_url, | 554 const GURL& script_url, |
555 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, | 555 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, |
556 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, | 556 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, |
| 557 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info, |
557 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client) | 558 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client) |
558 : embedded_worker_id_(embedded_worker_id), | 559 : embedded_worker_id_(embedded_worker_id), |
559 service_worker_version_id_(service_worker_version_id), | 560 service_worker_version_id_(service_worker_version_id), |
560 service_worker_scope_(service_worker_scope), | 561 service_worker_scope_(service_worker_scope), |
561 script_url_(script_url), | 562 script_url_(script_url), |
562 sender_(ChildThreadImpl::current()->thread_safe_sender()), | 563 sender_(ChildThreadImpl::current()->thread_safe_sender()), |
563 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 564 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
564 proxy_(nullptr), | 565 proxy_(nullptr), |
565 pending_dispatcher_request_(std::move(dispatcher_request)), | 566 pending_dispatcher_request_(std::move(dispatcher_request)), |
566 embedded_worker_client_(std::move(embedded_worker_client)) { | 567 embedded_worker_client_(std::move(embedded_worker_client)) { |
567 instance_host_ = | 568 instance_host_ = |
568 mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr::Create( | 569 mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr::Create( |
569 std::move(instance_host), main_thread_task_runner_); | 570 std::move(instance_host), main_thread_task_runner_); |
570 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 571 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
571 "ServiceWorkerContextClient::StartingWorkerContext", | 572 "ServiceWorkerContextClient::StartingWorkerContext", |
572 this); | 573 this); |
573 TRACE_EVENT_ASYNC_STEP_INTO0( | 574 TRACE_EVENT_ASYNC_STEP_INTO0( |
574 "ServiceWorker", | 575 "ServiceWorker", |
575 "ServiceWorkerContextClient::StartingWorkerContext", | 576 "ServiceWorkerContextClient::StartingWorkerContext", |
576 this, | 577 this, |
577 "PrepareWorker"); | 578 "PrepareWorker"); |
| 579 // Create a content::ServiceWorkerNetworkProvider for this data source so |
| 580 // we can observe its requests. |
| 581 pending_network_provider_ = |
| 582 base::MakeUnique<ServiceWorkerNetworkProvider>(std::move(provider_info)); |
| 583 provider_context_ = pending_network_provider_->context(); |
578 } | 584 } |
579 | 585 |
580 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} | 586 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} |
581 | 587 |
582 void ServiceWorkerContextClient::OnMessageReceived( | 588 void ServiceWorkerContextClient::OnMessageReceived( |
583 int thread_id, | 589 int thread_id, |
584 int embedded_worker_id, | 590 int embedded_worker_id, |
585 const IPC::Message& message) { | 591 const IPC::Message& message) { |
586 CHECK_EQ(embedded_worker_id_, embedded_worker_id); | 592 CHECK_EQ(embedded_worker_id_, embedded_worker_id); |
587 bool handled = true; | 593 bool handled = true; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 DCHECK_NE(registration_info.registration_id, | 715 DCHECK_NE(registration_info.registration_id, |
710 kInvalidServiceWorkerRegistrationId); | 716 kInvalidServiceWorkerRegistrationId); |
711 | 717 |
712 DCHECK(pending_dispatcher_request_.is_pending()); | 718 DCHECK(pending_dispatcher_request_.is_pending()); |
713 DCHECK(!context_->event_dispatcher_binding.is_bound()); | 719 DCHECK(!context_->event_dispatcher_binding.is_bound()); |
714 context_->event_dispatcher_binding.Bind( | 720 context_->event_dispatcher_binding.Bind( |
715 std::move(pending_dispatcher_request_)); | 721 std::move(pending_dispatcher_request_)); |
716 | 722 |
717 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs); | 723 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs); |
718 | 724 |
719 (*instance_host_) | 725 (*instance_host_)->OnThreadStarted(WorkerThread::GetCurrentId()); |
720 ->OnThreadStarted(WorkerThread::GetCurrentId(), | |
721 provider_context_->provider_id()); | |
722 | 726 |
723 TRACE_EVENT_ASYNC_STEP_INTO0( | 727 TRACE_EVENT_ASYNC_STEP_INTO0( |
724 "ServiceWorker", | 728 "ServiceWorker", |
725 "ServiceWorkerContextClient::StartingWorkerContext", | 729 "ServiceWorkerContextClient::StartingWorkerContext", |
726 this, | 730 this, |
727 "ExecuteScript"); | 731 "ExecuteScript"); |
728 } | 732 } |
729 | 733 |
730 void ServiceWorkerContextClient::DidEvaluateWorkerScript(bool success) { | 734 void ServiceWorkerContextClient::DidEvaluateWorkerScript(bool success) { |
731 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence()); | 735 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence()); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 DispatchPaymentRequestEventCallback callback = | 1091 DispatchPaymentRequestEventCallback callback = |
1088 std::move(context_->payment_request_event_callbacks[payment_request_id]); | 1092 std::move(context_->payment_request_event_callbacks[payment_request_id]); |
1089 std::move(callback).Run(EventResultToStatus(result), | 1093 std::move(callback).Run(EventResultToStatus(result), |
1090 base::Time::FromDoubleT(event_dispatch_time)); | 1094 base::Time::FromDoubleT(event_dispatch_time)); |
1091 context_->payment_request_event_callbacks.erase(payment_request_id); | 1095 context_->payment_request_event_callbacks.erase(payment_request_id); |
1092 } | 1096 } |
1093 | 1097 |
1094 std::unique_ptr<blink::WebServiceWorkerNetworkProvider> | 1098 std::unique_ptr<blink::WebServiceWorkerNetworkProvider> |
1095 ServiceWorkerContextClient::CreateServiceWorkerNetworkProvider() { | 1099 ServiceWorkerContextClient::CreateServiceWorkerNetworkProvider() { |
1096 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); | 1100 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); |
1097 | |
1098 // Create a content::ServiceWorkerNetworkProvider for this data source so | |
1099 // we can observe its requests. | |
1100 std::unique_ptr<ServiceWorkerNetworkProvider> provider = | |
1101 base::MakeUnique<ServiceWorkerNetworkProvider>( | |
1102 MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, | |
1103 true /* is_parent_frame_secure */); | |
1104 provider_context_ = provider->context(); | |
1105 network_provider_id_ = provider->provider_id(); | |
1106 | |
1107 // Tell the network provider about which version to load. | |
1108 provider->SetServiceWorkerVersionId(service_worker_version_id_, | |
1109 embedded_worker_id_); | |
1110 | |
1111 // Blink is responsible for deleting the returned object. | 1101 // Blink is responsible for deleting the returned object. |
1112 return base::MakeUnique<WebServiceWorkerNetworkProviderImpl>( | 1102 return base::MakeUnique<WebServiceWorkerNetworkProviderImpl>( |
1113 std::move(provider)); | 1103 std::move(pending_network_provider_)); |
1114 } | 1104 } |
1115 | 1105 |
1116 std::unique_ptr<blink::WebWorkerFetchContext> | 1106 std::unique_ptr<blink::WebWorkerFetchContext> |
1117 ServiceWorkerContextClient::CreateServiceWorkerFetchContext() { | 1107 ServiceWorkerContextClient::CreateServiceWorkerFetchContext() { |
1118 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); | 1108 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); |
1119 DCHECK(base::FeatureList::IsEnabled(features::kOffMainThreadFetch)); | 1109 DCHECK(base::FeatureList::IsEnabled(features::kOffMainThreadFetch)); |
1120 mojom::WorkerURLLoaderFactoryProviderPtr worker_url_loader_factory_provider; | 1110 mojom::WorkerURLLoaderFactoryProviderPtr worker_url_loader_factory_provider; |
1121 RenderThreadImpl::current() | 1111 RenderThreadImpl::current() |
1122 ->blink_platform_impl() | 1112 ->blink_platform_impl() |
1123 ->GetInterfaceProvider() | 1113 ->GetInterfaceProvider() |
1124 ->GetInterface(mojo::MakeRequest(&worker_url_loader_factory_provider)); | 1114 ->GetInterface(mojo::MakeRequest(&worker_url_loader_factory_provider)); |
1125 | 1115 |
1126 // Blink is responsible for deleting the returned object. | 1116 // Blink is responsible for deleting the returned object. |
1127 return base::MakeUnique<ServiceWorkerFetchContextImpl>( | 1117 return base::MakeUnique<ServiceWorkerFetchContextImpl>( |
1128 script_url_, worker_url_loader_factory_provider.PassInterface(), | 1118 script_url_, worker_url_loader_factory_provider.PassInterface(), |
1129 network_provider_id_); | 1119 provider_context_->provider_id()); |
1130 } | 1120 } |
1131 | 1121 |
1132 std::unique_ptr<blink::WebServiceWorkerProvider> | 1122 std::unique_ptr<blink::WebServiceWorkerProvider> |
1133 ServiceWorkerContextClient::CreateServiceWorkerProvider() { | 1123 ServiceWorkerContextClient::CreateServiceWorkerProvider() { |
1134 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); | 1124 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); |
1135 DCHECK(provider_context_); | 1125 DCHECK(provider_context_); |
1136 | 1126 |
1137 // Blink is responsible for deleting the returned object. | 1127 // Blink is responsible for deleting the returned object. |
1138 return base::MakeUnique<WebServiceWorkerProviderImpl>( | 1128 return base::MakeUnique<WebServiceWorkerProviderImpl>( |
1139 sender_.get(), provider_context_.get()); | 1129 sender_.get(), provider_context_.get()); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1696 } | 1686 } |
1697 | 1687 |
1698 base::WeakPtr<ServiceWorkerContextClient> | 1688 base::WeakPtr<ServiceWorkerContextClient> |
1699 ServiceWorkerContextClient::GetWeakPtr() { | 1689 ServiceWorkerContextClient::GetWeakPtr() { |
1700 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence()); | 1690 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence()); |
1701 DCHECK(context_); | 1691 DCHECK(context_); |
1702 return context_->weak_factory.GetWeakPtr(); | 1692 return context_->weak_factory.GetWeakPtr(); |
1703 } | 1693 } |
1704 | 1694 |
1705 } // namespace content | 1695 } // namespace content |
OLD | NEW |