| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 27 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
| 28 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 28 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 29 #include "content/child/thread_safe_sender.h" | 29 #include "content/child/thread_safe_sender.h" |
| 30 #include "content/child/webmessageportchannel_impl.h" | 30 #include "content/child/webmessageportchannel_impl.h" |
| 31 #include "content/common/devtools_messages.h" | 31 #include "content/common/devtools_messages.h" |
| 32 #include "content/common/message_port_messages.h" | 32 #include "content/common/message_port_messages.h" |
| 33 #include "content/common/service_worker/embedded_worker_messages.h" | 33 #include "content/common/service_worker/embedded_worker_messages.h" |
| 34 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h" | 34 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h" |
| 35 #include "content/common/service_worker/service_worker_messages.h" | 35 #include "content/common/service_worker/service_worker_messages.h" |
| 36 #include "content/common/service_worker/service_worker_status_code.h" | 36 #include "content/common/service_worker/service_worker_status_code.h" |
| 37 #include "content/common/service_worker/service_worker_utils.h" |
| 37 #include "content/public/common/push_event_payload.h" | 38 #include "content/public/common/push_event_payload.h" |
| 38 #include "content/public/common/referrer.h" | 39 #include "content/public/common/referrer.h" |
| 39 #include "content/public/renderer/content_renderer_client.h" | 40 #include "content/public/renderer/content_renderer_client.h" |
| 40 #include "content/public/renderer/document_state.h" | 41 #include "content/public/renderer/document_state.h" |
| 41 #include "content/renderer/background_sync/background_sync_client_impl.h" | 42 #include "content/renderer/background_sync/background_sync_client_impl.h" |
| 42 #include "content/renderer/devtools/devtools_agent.h" | 43 #include "content/renderer/devtools/devtools_agent.h" |
| 43 #include "content/renderer/render_thread_impl.h" | 44 #include "content/renderer/render_thread_impl.h" |
| 44 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" | 45 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
| 46 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h
" |
| 45 #include "content/renderer/service_worker/service_worker_type_util.h" | 47 #include "content/renderer/service_worker/service_worker_type_util.h" |
| 46 #include "ipc/ipc_message.h" | 48 #include "ipc/ipc_message.h" |
| 47 #include "ipc/ipc_message_macros.h" | 49 #include "ipc/ipc_message_macros.h" |
| 48 #include "mojo/public/cpp/bindings/interface_request.h" | 50 #include "mojo/public/cpp/bindings/interface_request.h" |
| 49 #include "mojo/public/cpp/bindings/strong_binding.h" | 51 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 50 #include "services/shell/public/cpp/interface_provider.h" | 52 #include "services/shell/public/cpp/interface_provider.h" |
| 51 #include "services/shell/public/cpp/interface_registry.h" | 53 #include "services/shell/public/cpp/interface_registry.h" |
| 52 #include "third_party/WebKit/public/platform/URLConversion.h" | 54 #include "third_party/WebKit/public/platform/URLConversion.h" |
| 53 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 55 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 54 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 56 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 ServiceWorkerContextClient* | 254 ServiceWorkerContextClient* |
| 253 ServiceWorkerContextClient::ThreadSpecificInstance() { | 255 ServiceWorkerContextClient::ThreadSpecificInstance() { |
| 254 return g_worker_client_tls.Pointer()->Get(); | 256 return g_worker_client_tls.Pointer()->Get(); |
| 255 } | 257 } |
| 256 | 258 |
| 257 ServiceWorkerContextClient::ServiceWorkerContextClient( | 259 ServiceWorkerContextClient::ServiceWorkerContextClient( |
| 258 int embedded_worker_id, | 260 int embedded_worker_id, |
| 259 int64_t service_worker_version_id, | 261 int64_t service_worker_version_id, |
| 260 const GURL& service_worker_scope, | 262 const GURL& service_worker_scope, |
| 261 const GURL& script_url, | 263 const GURL& script_url, |
| 262 int worker_devtools_agent_route_id) | 264 int worker_devtools_agent_route_id, |
| 265 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client) |
| 263 : embedded_worker_id_(embedded_worker_id), | 266 : embedded_worker_id_(embedded_worker_id), |
| 264 service_worker_version_id_(service_worker_version_id), | 267 service_worker_version_id_(service_worker_version_id), |
| 265 service_worker_scope_(service_worker_scope), | 268 service_worker_scope_(service_worker_scope), |
| 266 script_url_(script_url), | 269 script_url_(script_url), |
| 267 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), | 270 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), |
| 268 sender_(ChildThreadImpl::current()->thread_safe_sender()), | 271 sender_(ChildThreadImpl::current()->thread_safe_sender()), |
| 269 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 272 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 270 proxy_(nullptr) { | 273 proxy_(nullptr), |
| 274 embedded_worker_client_(std::move(embedded_worker_client)) { |
| 271 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 275 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
| 272 "ServiceWorkerContextClient::StartingWorkerContext", | 276 "ServiceWorkerContextClient::StartingWorkerContext", |
| 273 this); | 277 this); |
| 274 TRACE_EVENT_ASYNC_STEP_INTO0( | 278 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 275 "ServiceWorker", | 279 "ServiceWorker", |
| 276 "ServiceWorkerContextClient::StartingWorkerContext", | 280 "ServiceWorkerContextClient::StartingWorkerContext", |
| 277 this, | 281 this, |
| 278 "PrepareWorker"); | 282 "PrepareWorker"); |
| 279 } | 283 } |
| 280 | 284 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // this client. | 477 // this client. |
| 474 g_worker_client_tls.Pointer()->Set(NULL); | 478 g_worker_client_tls.Pointer()->Set(NULL); |
| 475 | 479 |
| 476 GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread( | 480 GetContentClient()->renderer()->WillDestroyServiceWorkerContextOnWorkerThread( |
| 477 context, embedded_worker_id_, script_url_); | 481 context, embedded_worker_id_, script_url_); |
| 478 } | 482 } |
| 479 | 483 |
| 480 void ServiceWorkerContextClient::workerContextDestroyed() { | 484 void ServiceWorkerContextClient::workerContextDestroyed() { |
| 481 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); | 485 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); |
| 482 | 486 |
| 487 // Check if mojo is enabled |
| 488 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { |
| 489 DCHECK(embedded_worker_client_); |
| 490 main_thread_task_runner_->PostTask( |
| 491 FROM_HERE, |
| 492 base::Bind(&EmbeddedWorkerInstanceClientImpl::StopWorkerCompleted, |
| 493 base::Passed(&embedded_worker_client_))); |
| 494 return; |
| 495 } |
| 496 |
| 483 // Now we should be able to free the WebEmbeddedWorker container on the | 497 // Now we should be able to free the WebEmbeddedWorker container on the |
| 484 // main thread. | 498 // main thread. |
| 485 main_thread_task_runner_->PostTask( | 499 main_thread_task_runner_->PostTask( |
| 486 FROM_HERE, | 500 FROM_HERE, |
| 487 base::Bind(&CallWorkerContextDestroyedOnMainThread, | 501 base::Bind(&CallWorkerContextDestroyedOnMainThread, |
| 488 embedded_worker_id_)); | 502 embedded_worker_id_)); |
| 489 } | 503 } |
| 490 | 504 |
| 491 void ServiceWorkerContextClient::reportException( | 505 void ServiceWorkerContextClient::reportException( |
| 492 const blink::WebString& error_message, | 506 const blink::WebString& error_message, |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 } | 1118 } |
| 1105 | 1119 |
| 1106 base::WeakPtr<ServiceWorkerContextClient> | 1120 base::WeakPtr<ServiceWorkerContextClient> |
| 1107 ServiceWorkerContextClient::GetWeakPtr() { | 1121 ServiceWorkerContextClient::GetWeakPtr() { |
| 1108 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1122 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1109 DCHECK(context_); | 1123 DCHECK(context_); |
| 1110 return context_->weak_factory.GetWeakPtr(); | 1124 return context_->weak_factory.GetWeakPtr(); |
| 1111 } | 1125 } |
| 1112 | 1126 |
| 1113 } // namespace content | 1127 } // namespace content |
| OLD | NEW |