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

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

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