Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2936623002: Implement dumb URLLoader{Factory} for ServiceWorker script loading (for try)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 // Blink calls this method for each request starting with the main script, 94 // Blink calls this method for each request starting with the main script,
95 // we tag them with the provider id. 95 // we tag them with the provider id.
96 void WillSendRequest(blink::WebURLRequest& request) override { 96 void WillSendRequest(blink::WebURLRequest& request) override {
97 std::unique_ptr<RequestExtraData> extra_data(new RequestExtraData); 97 std::unique_ptr<RequestExtraData> extra_data(new RequestExtraData);
98 extra_data->set_service_worker_provider_id(provider_->provider_id()); 98 extra_data->set_service_worker_provider_id(provider_->provider_id());
99 extra_data->set_originated_from_service_worker(true); 99 extra_data->set_originated_from_service_worker(true);
100 // Service workers are only available in secure contexts, so all requests 100 // Service workers are only available in secure contexts, so all requests
101 // are initiated in a secure context. 101 // are initiated in a secure context.
102 extra_data->set_initiated_in_secure_context(true); 102 extra_data->set_initiated_in_secure_context(true);
103 extra_data->set_url_loader_factory_override(
104 provider_->script_loader_factory());
103 request.SetExtraData(extra_data.release()); 105 request.SetExtraData(extra_data.release());
104 } 106 }
105 107
106 int GetProviderID() const override { return provider_->provider_id(); } 108 int GetProviderID() const override { return provider_->provider_id(); }
107 109
108 private: 110 private:
109 std::unique_ptr<ServiceWorkerNetworkProvider> provider_; 111 std::unique_ptr<ServiceWorkerNetworkProvider> provider_;
110 }; 112 };
111 113
112 class StreamHandleListener 114 class StreamHandleListener
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 return g_worker_client_tls.Pointer()->Get(); 549 return g_worker_client_tls.Pointer()->Get();
548 } 550 }
549 551
550 ServiceWorkerContextClient::ServiceWorkerContextClient( 552 ServiceWorkerContextClient::ServiceWorkerContextClient(
551 int embedded_worker_id, 553 int embedded_worker_id,
552 int64_t service_worker_version_id, 554 int64_t service_worker_version_id,
553 const GURL& service_worker_scope, 555 const GURL& service_worker_scope,
554 const GURL& script_url, 556 const GURL& script_url,
555 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, 557 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request,
556 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, 558 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
559 mojom::ServiceWorkerProviderClientInfoPtr provider_client_info,
557 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client) 560 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client)
558 : embedded_worker_id_(embedded_worker_id), 561 : embedded_worker_id_(embedded_worker_id),
559 service_worker_version_id_(service_worker_version_id), 562 service_worker_version_id_(service_worker_version_id),
560 service_worker_scope_(service_worker_scope), 563 service_worker_scope_(service_worker_scope),
561 script_url_(script_url), 564 script_url_(script_url),
562 sender_(ChildThreadImpl::current()->thread_safe_sender()), 565 sender_(ChildThreadImpl::current()->thread_safe_sender()),
563 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 566 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
564 proxy_(nullptr), 567 proxy_(nullptr),
565 pending_dispatcher_request_(std::move(dispatcher_request)), 568 pending_dispatcher_request_(std::move(dispatcher_request)),
566 embedded_worker_client_(std::move(embedded_worker_client)) { 569 embedded_worker_client_(std::move(embedded_worker_client)) {
567 instance_host_ = 570 instance_host_ =
568 mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr::Create( 571 mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr::Create(
569 std::move(instance_host), main_thread_task_runner_); 572 std::move(instance_host), main_thread_task_runner_);
570 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", 573 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker",
571 "ServiceWorkerContextClient::StartingWorkerContext", 574 "ServiceWorkerContextClient::StartingWorkerContext",
572 this); 575 this);
573 TRACE_EVENT_ASYNC_STEP_INTO0( 576 TRACE_EVENT_ASYNC_STEP_INTO0(
574 "ServiceWorker", 577 "ServiceWorker",
575 "ServiceWorkerContextClient::StartingWorkerContext", 578 "ServiceWorkerContextClient::StartingWorkerContext",
576 this, 579 this,
577 "PrepareWorker"); 580 "PrepareWorker");
581 // Create a content::ServiceWorkerNetworkProvider for this data source so
582 // we can observe its requests.
583 pending_network_provider_ = base::MakeUnique<ServiceWorkerNetworkProvider>(
584 std::move(provider_client_info));
585 provider_context_ = pending_network_provider_->context();
578 } 586 }
579 587
580 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} 588 ServiceWorkerContextClient::~ServiceWorkerContextClient() {}
581 589
582 void ServiceWorkerContextClient::OnMessageReceived( 590 void ServiceWorkerContextClient::OnMessageReceived(
583 int thread_id, 591 int thread_id,
584 int embedded_worker_id, 592 int embedded_worker_id,
585 const IPC::Message& message) { 593 const IPC::Message& message) {
586 CHECK_EQ(embedded_worker_id_, embedded_worker_id); 594 CHECK_EQ(embedded_worker_id_, embedded_worker_id);
587 bool handled = true; 595 bool handled = true;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 DCHECK_NE(registration_info.registration_id, 717 DCHECK_NE(registration_info.registration_id,
710 kInvalidServiceWorkerRegistrationId); 718 kInvalidServiceWorkerRegistrationId);
711 719
712 DCHECK(pending_dispatcher_request_.is_pending()); 720 DCHECK(pending_dispatcher_request_.is_pending());
713 DCHECK(!context_->event_dispatcher_binding.is_bound()); 721 DCHECK(!context_->event_dispatcher_binding.is_bound());
714 context_->event_dispatcher_binding.Bind( 722 context_->event_dispatcher_binding.Bind(
715 std::move(pending_dispatcher_request_)); 723 std::move(pending_dispatcher_request_));
716 724
717 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs); 725 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs);
718 726
719 (*instance_host_) 727 (*instance_host_)->OnThreadStarted(WorkerThread::GetCurrentId());
720 ->OnThreadStarted(WorkerThread::GetCurrentId(),
721 provider_context_->provider_id());
722 728
723 TRACE_EVENT_ASYNC_STEP_INTO0( 729 TRACE_EVENT_ASYNC_STEP_INTO0(
724 "ServiceWorker", 730 "ServiceWorker",
725 "ServiceWorkerContextClient::StartingWorkerContext", 731 "ServiceWorkerContextClient::StartingWorkerContext",
726 this, 732 this,
727 "ExecuteScript"); 733 "ExecuteScript");
728 } 734 }
729 735
730 void ServiceWorkerContextClient::DidEvaluateWorkerScript(bool success) { 736 void ServiceWorkerContextClient::DidEvaluateWorkerScript(bool success) {
731 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence()); 737 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence());
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 DispatchPaymentRequestEventCallback callback = 1093 DispatchPaymentRequestEventCallback callback =
1088 std::move(context_->payment_request_event_callbacks[payment_request_id]); 1094 std::move(context_->payment_request_event_callbacks[payment_request_id]);
1089 std::move(callback).Run(EventResultToStatus(result), 1095 std::move(callback).Run(EventResultToStatus(result),
1090 base::Time::FromDoubleT(event_dispatch_time)); 1096 base::Time::FromDoubleT(event_dispatch_time));
1091 context_->payment_request_event_callbacks.erase(payment_request_id); 1097 context_->payment_request_event_callbacks.erase(payment_request_id);
1092 } 1098 }
1093 1099
1094 std::unique_ptr<blink::WebServiceWorkerNetworkProvider> 1100 std::unique_ptr<blink::WebServiceWorkerNetworkProvider>
1095 ServiceWorkerContextClient::CreateServiceWorkerNetworkProvider() { 1101 ServiceWorkerContextClient::CreateServiceWorkerNetworkProvider() {
1096 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); 1102 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. 1103 // Blink is responsible for deleting the returned object.
1112 return base::MakeUnique<WebServiceWorkerNetworkProviderImpl>( 1104 return base::MakeUnique<WebServiceWorkerNetworkProviderImpl>(
1113 std::move(provider)); 1105 std::move(pending_network_provider_));
1114 } 1106 }
1115 1107
1116 std::unique_ptr<blink::WebWorkerFetchContext> 1108 std::unique_ptr<blink::WebWorkerFetchContext>
1117 ServiceWorkerContextClient::CreateServiceWorkerFetchContext() { 1109 ServiceWorkerContextClient::CreateServiceWorkerFetchContext() {
1118 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); 1110 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
1119 DCHECK(base::FeatureList::IsEnabled(features::kOffMainThreadFetch)); 1111 DCHECK(base::FeatureList::IsEnabled(features::kOffMainThreadFetch));
1120 mojom::WorkerURLLoaderFactoryProviderPtr worker_url_loader_factory_provider; 1112 mojom::WorkerURLLoaderFactoryProviderPtr worker_url_loader_factory_provider;
1121 RenderThreadImpl::current() 1113 RenderThreadImpl::current()
1122 ->blink_platform_impl() 1114 ->blink_platform_impl()
1123 ->GetInterfaceProvider() 1115 ->GetInterfaceProvider()
1124 ->GetInterface(mojo::MakeRequest(&worker_url_loader_factory_provider)); 1116 ->GetInterface(mojo::MakeRequest(&worker_url_loader_factory_provider));
1125 1117
1126 // Blink is responsible for deleting the returned object. 1118 // Blink is responsible for deleting the returned object.
1127 return base::MakeUnique<ServiceWorkerFetchContextImpl>( 1119 return base::MakeUnique<ServiceWorkerFetchContextImpl>(
1128 script_url_, worker_url_loader_factory_provider.PassInterface(), 1120 script_url_, worker_url_loader_factory_provider.PassInterface(),
1129 network_provider_id_); 1121 provider_context_->provider_id());
1130 } 1122 }
1131 1123
1132 std::unique_ptr<blink::WebServiceWorkerProvider> 1124 std::unique_ptr<blink::WebServiceWorkerProvider>
1133 ServiceWorkerContextClient::CreateServiceWorkerProvider() { 1125 ServiceWorkerContextClient::CreateServiceWorkerProvider() {
1134 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); 1126 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
1135 DCHECK(provider_context_); 1127 DCHECK(provider_context_);
1136 1128
1137 // Blink is responsible for deleting the returned object. 1129 // Blink is responsible for deleting the returned object.
1138 return base::MakeUnique<WebServiceWorkerProviderImpl>( 1130 return base::MakeUnique<WebServiceWorkerProviderImpl>(
1139 sender_.get(), provider_context_.get()); 1131 sender_.get(), provider_context_.get());
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 } 1688 }
1697 1689
1698 base::WeakPtr<ServiceWorkerContextClient> 1690 base::WeakPtr<ServiceWorkerContextClient>
1699 ServiceWorkerContextClient::GetWeakPtr() { 1691 ServiceWorkerContextClient::GetWeakPtr() {
1700 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence()); 1692 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence());
1701 DCHECK(context_); 1693 DCHECK(context_);
1702 return context_->weak_factory.GetWeakPtr(); 1694 return context_->weak_factory.GetWeakPtr();
1703 } 1695 }
1704 1696
1705 } // namespace content 1697 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698