OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/embedded_worker_context_client.h" | 5 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "base/threading/thread_local.h" | 16 #include "base/threading/thread_local.h" |
17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
18 #include "content/child/request_extra_data.h" | 18 #include "content/child/request_extra_data.h" |
19 #include "content/child/service_worker/service_worker_dispatcher.h" | 19 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 20 #include "content/child/service_worker/service_worker_message_sender.h" |
20 #include "content/child/service_worker/service_worker_network_provider.h" | 21 #include "content/child/service_worker/service_worker_network_provider.h" |
21 #include "content/child/service_worker/service_worker_provider_context.h" | 22 #include "content/child/service_worker/service_worker_provider_context.h" |
22 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 23 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
23 #include "content/child/service_worker/web_service_worker_impl.h" | 24 #include "content/child/service_worker/web_service_worker_impl.h" |
24 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 25 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
25 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 26 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
26 #include "content/child/thread_safe_sender.h" | 27 #include "content/child/thread_safe_sender.h" |
27 #include "content/child/worker_task_runner.h" | 28 #include "content/child/worker_task_runner.h" |
28 #include "content/common/devtools_messages.h" | 29 #include "content/common/devtools_messages.h" |
29 #include "content/common/service_worker/embedded_worker_messages.h" | 30 #include "content/common/service_worker/embedded_worker_messages.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 int embedded_worker_id, | 99 int embedded_worker_id, |
99 int64 service_worker_version_id, | 100 int64 service_worker_version_id, |
100 const GURL& service_worker_scope, | 101 const GURL& service_worker_scope, |
101 const GURL& script_url, | 102 const GURL& script_url, |
102 int worker_devtools_agent_route_id) | 103 int worker_devtools_agent_route_id) |
103 : embedded_worker_id_(embedded_worker_id), | 104 : embedded_worker_id_(embedded_worker_id), |
104 service_worker_version_id_(service_worker_version_id), | 105 service_worker_version_id_(service_worker_version_id), |
105 service_worker_scope_(service_worker_scope), | 106 service_worker_scope_(service_worker_scope), |
106 script_url_(script_url), | 107 script_url_(script_url), |
107 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), | 108 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), |
108 sender_(ChildThreadImpl::current()->thread_safe_sender()), | 109 sender_(new ServiceWorkerMessageSender( |
| 110 ChildThreadImpl::current()->thread_safe_sender())), |
109 main_thread_task_runner_(RenderThreadImpl::current()->GetTaskRunner()), | 111 main_thread_task_runner_(RenderThreadImpl::current()->GetTaskRunner()), |
110 weak_factory_(this) { | 112 weak_factory_(this) { |
111 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 113 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
112 "EmbeddedWorkerContextClient::StartingWorkerContext", | 114 "EmbeddedWorkerContextClient::StartingWorkerContext", |
113 this); | 115 this); |
114 TRACE_EVENT_ASYNC_STEP_INTO0( | 116 TRACE_EVENT_ASYNC_STEP_INTO0( |
115 "ServiceWorker", | 117 "ServiceWorker", |
116 "EmbeddedWorkerContextClient::StartingWorkerContext", | 118 "EmbeddedWorkerContextClient::StartingWorkerContext", |
117 this, | 119 this, |
118 "PrepareWorker"); | 120 "PrepareWorker"); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 277 |
276 Send(new EmbeddedWorkerHostMsg_ReportConsoleMessage( | 278 Send(new EmbeddedWorkerHostMsg_ReportConsoleMessage( |
277 embedded_worker_id_, params)); | 279 embedded_worker_id_, params)); |
278 } | 280 } |
279 | 281 |
280 void EmbeddedWorkerContextClient::sendDevToolsMessage( | 282 void EmbeddedWorkerContextClient::sendDevToolsMessage( |
281 int call_id, | 283 int call_id, |
282 const blink::WebString& message, | 284 const blink::WebString& message, |
283 const blink::WebString& state_cookie) { | 285 const blink::WebString& state_cookie) { |
284 DevToolsAgent::SendChunkedProtocolMessage( | 286 DevToolsAgent::SendChunkedProtocolMessage( |
285 sender_.get(), worker_devtools_agent_route_id_, | 287 sender_->thread_safe_sender(), worker_devtools_agent_route_id_, |
286 call_id, message.utf8(), state_cookie.utf8()); | 288 call_id, message.utf8(), state_cookie.utf8()); |
287 } | 289 } |
288 | 290 |
289 void EmbeddedWorkerContextClient::didHandleActivateEvent( | 291 void EmbeddedWorkerContextClient::didHandleActivateEvent( |
290 int request_id, | 292 int request_id, |
291 blink::WebServiceWorkerEventResult result) { | 293 blink::WebServiceWorkerEventResult result) { |
292 DCHECK(script_context_); | 294 DCHECK(script_context_); |
293 script_context_->DidHandleActivateEvent(request_id, result); | 295 script_context_->DidHandleActivateEvent(request_id, result); |
294 } | 296 } |
295 | 297 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 return new WebServiceWorkerNetworkProviderImpl(); | 381 return new WebServiceWorkerNetworkProviderImpl(); |
380 } | 382 } |
381 | 383 |
382 blink::WebServiceWorkerProvider* | 384 blink::WebServiceWorkerProvider* |
383 EmbeddedWorkerContextClient::createServiceWorkerProvider() { | 385 EmbeddedWorkerContextClient::createServiceWorkerProvider() { |
384 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 386 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
385 DCHECK(provider_context_); | 387 DCHECK(provider_context_); |
386 | 388 |
387 // Blink is responsible for deleting the returned object. | 389 // Blink is responsible for deleting the returned object. |
388 return new WebServiceWorkerProviderImpl( | 390 return new WebServiceWorkerProviderImpl( |
389 thread_safe_sender(), provider_context_.get()); | 391 sender()->thread_safe_sender(), provider_context_.get()); |
390 } | 392 } |
391 | 393 |
392 void EmbeddedWorkerContextClient::postMessageToClient( | 394 void EmbeddedWorkerContextClient::postMessageToClient( |
393 const blink::WebString& uuid, | 395 const blink::WebString& uuid, |
394 const blink::WebString& message, | 396 const blink::WebString& message, |
395 blink::WebMessagePortChannelArray* channels) { | 397 blink::WebMessagePortChannelArray* channels) { |
396 DCHECK(script_context_); | 398 DCHECK(script_context_); |
397 script_context_->PostMessageToClient( | 399 script_context_->PostMessageToClient( |
398 uuid, message, make_scoped_ptr(channels)); | 400 uuid, message, make_scoped_ptr(channels)); |
399 } | 401 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 DCHECK(script_context_); | 452 DCHECK(script_context_); |
451 | 453 |
452 ServiceWorkerRegistrationObjectInfo info; | 454 ServiceWorkerRegistrationObjectInfo info; |
453 ServiceWorkerVersionAttributes attrs; | 455 ServiceWorkerVersionAttributes attrs; |
454 bool found = | 456 bool found = |
455 provider_context_->GetRegistrationInfoAndVersionAttributes(&info, &attrs); | 457 provider_context_->GetRegistrationInfoAndVersionAttributes(&info, &attrs); |
456 if (!found) | 458 if (!found) |
457 return; // Cannot be associated with a registration in some tests. | 459 return; // Cannot be associated with a registration in some tests. |
458 | 460 |
459 ServiceWorkerDispatcher* dispatcher = | 461 ServiceWorkerDispatcher* dispatcher = |
460 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 462 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(sender()); |
461 thread_safe_sender()); | |
462 | 463 |
463 // Register a registration and its version attributes with the dispatcher | 464 // Register a registration and its version attributes with the dispatcher |
464 // living on the worker thread. | 465 // living on the worker thread. |
465 scoped_ptr<WebServiceWorkerRegistrationImpl> registration( | 466 scoped_ptr<WebServiceWorkerRegistrationImpl> registration( |
466 dispatcher->CreateServiceWorkerRegistration(info, false)); | 467 dispatcher->CreateServiceWorkerRegistration(info, false)); |
467 registration->SetInstalling( | 468 registration->SetInstalling( |
468 dispatcher->GetServiceWorker(attrs.installing, false)); | 469 dispatcher->GetServiceWorker(attrs.installing, false)); |
469 registration->SetWaiting( | 470 registration->SetWaiting( |
470 dispatcher->GetServiceWorker(attrs.waiting, false)); | 471 dispatcher->GetServiceWorker(attrs.waiting, false)); |
471 registration->SetActive( | 472 registration->SetActive( |
472 dispatcher->GetServiceWorker(attrs.active, false)); | 473 dispatcher->GetServiceWorker(attrs.active, false)); |
473 | 474 |
474 script_context_->SetRegistrationInServiceWorkerGlobalScope( | 475 script_context_->SetRegistrationInServiceWorkerGlobalScope( |
475 registration.Pass()); | 476 registration.Pass()); |
476 } | 477 } |
477 | 478 |
478 } // namespace content | 479 } // namespace content |
OLD | NEW |