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

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

Issue 2873333004: Rename TaskRunner::RunsTasksOnCurrentThread() in //content (Closed)
Patch Set: Created 3 years, 7 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
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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 size_t size) { 643 size_t size) {
644 std::vector<char> copy(data, data + size); 644 std::vector<char> copy(data, data + size);
645 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url, copy)); 645 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url, copy));
646 } 646 }
647 647
648 void ServiceWorkerContextClient::ClearCachedMetadata(const blink::WebURL& url) { 648 void ServiceWorkerContextClient::ClearCachedMetadata(const blink::WebURL& url) {
649 Send(new ServiceWorkerHostMsg_ClearCachedMetadata(GetRoutingID(), url)); 649 Send(new ServiceWorkerHostMsg_ClearCachedMetadata(GetRoutingID(), url));
650 } 650 }
651 651
652 void ServiceWorkerContextClient::WorkerReadyForInspection() { 652 void ServiceWorkerContextClient::WorkerReadyForInspection() {
653 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); 653 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
654 (*instance_host_)->OnReadyForInspection(); 654 (*instance_host_)->OnReadyForInspection();
655 } 655 }
656 656
657 void ServiceWorkerContextClient::WorkerContextFailedToStart() { 657 void ServiceWorkerContextClient::WorkerContextFailedToStart() {
658 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); 658 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
659 DCHECK(!proxy_); 659 DCHECK(!proxy_);
660 660
661 (*instance_host_)->OnScriptLoadFailed(); 661 (*instance_host_)->OnScriptLoadFailed();
662 (*instance_host_)->OnStopped(); 662 (*instance_host_)->OnStopped();
663 663
664 DCHECK(embedded_worker_client_); 664 DCHECK(embedded_worker_client_);
665 embedded_worker_client_->WorkerContextDestroyed(); 665 embedded_worker_client_->WorkerContextDestroyed();
666 } 666 }
667 667
668 void ServiceWorkerContextClient::WorkerScriptLoaded() { 668 void ServiceWorkerContextClient::WorkerScriptLoaded() {
669 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); 669 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
670 DCHECK(!proxy_); 670 DCHECK(!proxy_);
671 671
672 (*instance_host_)->OnScriptLoaded(); 672 (*instance_host_)->OnScriptLoaded();
673 } 673 }
674 674
675 bool ServiceWorkerContextClient::HasAssociatedRegistration() { 675 bool ServiceWorkerContextClient::HasAssociatedRegistration() {
676 return provider_context_ && provider_context_->HasAssociatedRegistration(); 676 return provider_context_ && provider_context_->HasAssociatedRegistration();
677 } 677 }
678 678
679 void ServiceWorkerContextClient::WorkerContextStarted( 679 void ServiceWorkerContextClient::WorkerContextStarted(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 provider_context_->provider_id()); 712 provider_context_->provider_id());
713 713
714 TRACE_EVENT_ASYNC_STEP_INTO0( 714 TRACE_EVENT_ASYNC_STEP_INTO0(
715 "ServiceWorker", 715 "ServiceWorker",
716 "ServiceWorkerContextClient::StartingWorkerContext", 716 "ServiceWorkerContextClient::StartingWorkerContext",
717 this, 717 this,
718 "ExecuteScript"); 718 "ExecuteScript");
719 } 719 }
720 720
721 void ServiceWorkerContextClient::DidEvaluateWorkerScript(bool success) { 721 void ServiceWorkerContextClient::DidEvaluateWorkerScript(bool success) {
722 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 722 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence());
723 (*instance_host_)->OnScriptEvaluated(success); 723 (*instance_host_)->OnScriptEvaluated(success);
724 724
725 // Schedule a task to send back WorkerStarted asynchronously, 725 // Schedule a task to send back WorkerStarted asynchronously,
726 // so that at the time we send it we can be sure that the 726 // so that at the time we send it we can be sure that the
727 // worker run loop has been started. 727 // worker run loop has been started.
728 worker_task_runner_->PostTask( 728 worker_task_runner_->PostTask(
729 FROM_HERE, base::Bind(&ServiceWorkerContextClient::SendWorkerStarted, 729 FROM_HERE, base::Bind(&ServiceWorkerContextClient::SendWorkerStarted,
730 GetWeakPtr())); 730 GetWeakPtr()));
731 } 731 }
732 732
733 void ServiceWorkerContextClient::DidInitializeWorkerContext( 733 void ServiceWorkerContextClient::DidInitializeWorkerContext(
734 v8::Local<v8::Context> context) { 734 v8::Local<v8::Context> context) {
735 GetContentClient() 735 GetContentClient()
736 ->renderer() 736 ->renderer()
737 ->DidInitializeServiceWorkerContextOnWorkerThread( 737 ->DidInitializeServiceWorkerContextOnWorkerThread(
738 context, service_worker_version_id_, script_url_); 738 context, service_worker_version_id_, script_url_);
739 } 739 }
740 740
741 void ServiceWorkerContextClient::WillDestroyWorkerContext( 741 void ServiceWorkerContextClient::WillDestroyWorkerContext(
742 v8::Local<v8::Context> context) { 742 v8::Local<v8::Context> context) {
743 // At this point WillStopCurrentWorkerThread is already called, so 743 // At this point WillStopCurrentWorkerThread is already called, so
744 // worker_task_runner_->RunsTasksOnCurrentThread() returns false 744 // worker_task_runner_->RunsTasksInCurrentSequence() returns false
745 // (while we're still on the worker thread). 745 // (while we're still on the worker thread).
746 proxy_ = NULL; 746 proxy_ = NULL;
747 747
748 // Aborts all the pending events callbacks. 748 // Aborts all the pending events callbacks.
749 AbortPendingEventCallbacks(context_->install_event_callbacks, 749 AbortPendingEventCallbacks(context_->install_event_callbacks,
750 false /* has_fetch_handler */); 750 false /* has_fetch_handler */);
751 AbortPendingEventCallbacks(context_->activate_event_callbacks); 751 AbortPendingEventCallbacks(context_->activate_event_callbacks);
752 AbortPendingEventCallbacks(context_->background_fetch_abort_event_callbacks); 752 AbortPendingEventCallbacks(context_->background_fetch_abort_event_callbacks);
753 AbortPendingEventCallbacks(context_->background_fetch_click_event_callbacks); 753 AbortPendingEventCallbacks(context_->background_fetch_click_event_callbacks);
754 AbortPendingEventCallbacks(context_->background_fetch_fail_event_callbacks); 754 AbortPendingEventCallbacks(context_->background_fetch_fail_event_callbacks);
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 double event_dispatch_time) { 1076 double event_dispatch_time) {
1077 DispatchPaymentRequestEventCallback callback = 1077 DispatchPaymentRequestEventCallback callback =
1078 std::move(context_->payment_request_event_callbacks[payment_request_id]); 1078 std::move(context_->payment_request_event_callbacks[payment_request_id]);
1079 std::move(callback).Run(EventResultToStatus(result), 1079 std::move(callback).Run(EventResultToStatus(result),
1080 base::Time::FromDoubleT(event_dispatch_time)); 1080 base::Time::FromDoubleT(event_dispatch_time));
1081 context_->payment_request_event_callbacks.erase(payment_request_id); 1081 context_->payment_request_event_callbacks.erase(payment_request_id);
1082 } 1082 }
1083 1083
1084 std::unique_ptr<blink::WebServiceWorkerNetworkProvider> 1084 std::unique_ptr<blink::WebServiceWorkerNetworkProvider>
1085 ServiceWorkerContextClient::CreateServiceWorkerNetworkProvider() { 1085 ServiceWorkerContextClient::CreateServiceWorkerNetworkProvider() {
1086 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); 1086 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
1087 1087
1088 // Create a content::ServiceWorkerNetworkProvider for this data source so 1088 // Create a content::ServiceWorkerNetworkProvider for this data source so
1089 // we can observe its requests. 1089 // we can observe its requests.
1090 std::unique_ptr<ServiceWorkerNetworkProvider> provider = 1090 std::unique_ptr<ServiceWorkerNetworkProvider> provider =
1091 base::MakeUnique<ServiceWorkerNetworkProvider>( 1091 base::MakeUnique<ServiceWorkerNetworkProvider>(
1092 MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, 1092 MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_CONTROLLER,
1093 true /* is_parent_frame_secure */); 1093 true /* is_parent_frame_secure */);
1094 provider_context_ = provider->context(); 1094 provider_context_ = provider->context();
1095 network_provider_id_ = provider->provider_id(); 1095 network_provider_id_ = provider->provider_id();
1096 1096
1097 // Tell the network provider about which version to load. 1097 // Tell the network provider about which version to load.
1098 provider->SetServiceWorkerVersionId(service_worker_version_id_, 1098 provider->SetServiceWorkerVersionId(service_worker_version_id_,
1099 embedded_worker_id_); 1099 embedded_worker_id_);
1100 1100
1101 // Blink is responsible for deleting the returned object. 1101 // Blink is responsible for deleting the returned object.
1102 return base::MakeUnique<WebServiceWorkerNetworkProviderImpl>( 1102 return base::MakeUnique<WebServiceWorkerNetworkProviderImpl>(
1103 std::move(provider)); 1103 std::move(provider));
1104 } 1104 }
1105 1105
1106 std::unique_ptr<blink::WebWorkerFetchContext> 1106 std::unique_ptr<blink::WebWorkerFetchContext>
1107 ServiceWorkerContextClient::CreateServiceWorkerFetchContext() { 1107 ServiceWorkerContextClient::CreateServiceWorkerFetchContext() {
1108 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); 1108 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
1109 DCHECK(base::FeatureList::IsEnabled(features::kOffMainThreadFetch)); 1109 DCHECK(base::FeatureList::IsEnabled(features::kOffMainThreadFetch));
1110 mojom::WorkerURLLoaderFactoryProviderPtr worker_url_loader_factory_provider; 1110 mojom::WorkerURLLoaderFactoryProviderPtr worker_url_loader_factory_provider;
1111 RenderThreadImpl::current() 1111 RenderThreadImpl::current()
1112 ->blink_platform_impl() 1112 ->blink_platform_impl()
1113 ->GetInterfaceProvider() 1113 ->GetInterfaceProvider()
1114 ->GetInterface(mojo::MakeRequest(&worker_url_loader_factory_provider)); 1114 ->GetInterface(mojo::MakeRequest(&worker_url_loader_factory_provider));
1115 1115
1116 // Blink is responsible for deleting the returned object. 1116 // Blink is responsible for deleting the returned object.
1117 return base::MakeUnique<ServiceWorkerFetchContextImpl>( 1117 return base::MakeUnique<ServiceWorkerFetchContextImpl>(
1118 worker_url_loader_factory_provider.PassInterface(), network_provider_id_); 1118 worker_url_loader_factory_provider.PassInterface(), network_provider_id_);
1119 } 1119 }
1120 1120
1121 std::unique_ptr<blink::WebServiceWorkerProvider> 1121 std::unique_ptr<blink::WebServiceWorkerProvider>
1122 ServiceWorkerContextClient::CreateServiceWorkerProvider() { 1122 ServiceWorkerContextClient::CreateServiceWorkerProvider() {
1123 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); 1123 DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
1124 DCHECK(provider_context_); 1124 DCHECK(provider_context_);
1125 1125
1126 // Blink is responsible for deleting the returned object. 1126 // Blink is responsible for deleting the returned object.
1127 return base::MakeUnique<WebServiceWorkerProviderImpl>( 1127 return base::MakeUnique<WebServiceWorkerProviderImpl>(
1128 sender_.get(), provider_context_.get()); 1128 sender_.get(), provider_context_.get());
1129 } 1129 }
1130 1130
1131 void ServiceWorkerContextClient::PostMessageToClient( 1131 void ServiceWorkerContextClient::PostMessageToClient(
1132 const blink::WebString& uuid, 1132 const blink::WebString& uuid,
1133 const blink::WebString& message, 1133 const blink::WebString& message,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 blink::WebPaymentAppRequest webAppRequest = 1215 blink::WebPaymentAppRequest webAppRequest =
1216 mojo::ConvertTo<blink::WebPaymentAppRequest>(std::move(app_request)); 1216 mojo::ConvertTo<blink::WebPaymentAppRequest>(std::move(app_request));
1217 proxy_->DispatchPaymentRequestEvent(payment_request_id, webAppRequest); 1217 proxy_->DispatchPaymentRequestEvent(payment_request_id, webAppRequest);
1218 } 1218 }
1219 1219
1220 void ServiceWorkerContextClient::Send(IPC::Message* message) { 1220 void ServiceWorkerContextClient::Send(IPC::Message* message) {
1221 sender_->Send(message); 1221 sender_->Send(message);
1222 } 1222 }
1223 1223
1224 void ServiceWorkerContextClient::SendWorkerStarted() { 1224 void ServiceWorkerContextClient::SendWorkerStarted() {
1225 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1225 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence());
1226 TRACE_EVENT_ASYNC_END0("ServiceWorker", 1226 TRACE_EVENT_ASYNC_END0("ServiceWorker",
1227 "ServiceWorkerContextClient::StartingWorkerContext", 1227 "ServiceWorkerContextClient::StartingWorkerContext",
1228 this); 1228 this);
1229 (*instance_host_)->OnStarted(); 1229 (*instance_host_)->OnStarted();
1230 } 1230 }
1231 1231
1232 void ServiceWorkerContextClient::SetRegistrationInServiceWorkerGlobalScope( 1232 void ServiceWorkerContextClient::SetRegistrationInServiceWorkerGlobalScope(
1233 const ServiceWorkerRegistrationObjectInfo& info, 1233 const ServiceWorkerRegistrationObjectInfo& info,
1234 const ServiceWorkerVersionAttributes& attrs) { 1234 const ServiceWorkerVersionAttributes& attrs) {
1235 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1235 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence());
1236 ServiceWorkerDispatcher* dispatcher = 1236 ServiceWorkerDispatcher* dispatcher =
1237 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( 1237 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
1238 sender_.get(), main_thread_task_runner_.get()); 1238 sender_.get(), main_thread_task_runner_.get());
1239 1239
1240 // Register a registration and its version attributes with the dispatcher 1240 // Register a registration and its version attributes with the dispatcher
1241 // living on the worker thread. 1241 // living on the worker thread.
1242 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( 1242 scoped_refptr<WebServiceWorkerRegistrationImpl> registration(
1243 dispatcher->GetOrCreateRegistration(info, attrs)); 1243 dispatcher->GetOrCreateRegistration(info, attrs));
1244 1244
1245 proxy_->SetRegistration( 1245 proxy_->SetRegistration(
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 int64_t encoded_body_length, 1679 int64_t encoded_body_length,
1680 int64_t decoded_body_length) { 1680 int64_t decoded_body_length) {
1681 proxy_->OnNavigationPreloadComplete( 1681 proxy_->OnNavigationPreloadComplete(
1682 fetch_event_id, (completion_time - base::TimeTicks()).InSecondsF(), 1682 fetch_event_id, (completion_time - base::TimeTicks()).InSecondsF(),
1683 encoded_data_length, encoded_body_length, decoded_body_length); 1683 encoded_data_length, encoded_body_length, decoded_body_length);
1684 context_->preload_requests.Remove(fetch_event_id); 1684 context_->preload_requests.Remove(fetch_event_id);
1685 } 1685 }
1686 1686
1687 base::WeakPtr<ServiceWorkerContextClient> 1687 base::WeakPtr<ServiceWorkerContextClient>
1688 ServiceWorkerContextClient::GetWeakPtr() { 1688 ServiceWorkerContextClient::GetWeakPtr() {
1689 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1689 DCHECK(worker_task_runner_->RunsTasksInCurrentSequence());
1690 DCHECK(context_); 1690 DCHECK(context_);
1691 return context_->weak_factory.GetWeakPtr(); 1691 return context_->weak_factory.GetWeakPtr();
1692 } 1692 }
1693 1693
1694 } // namespace content 1694 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc/webrtc_audio_sink.cc ('k') | content/renderer/service_worker/worker_fetch_context_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698