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" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 int64 service_worker_version_id, | 99 int64 service_worker_version_id, |
100 const GURL& service_worker_scope, | 100 const GURL& service_worker_scope, |
101 const GURL& script_url, | 101 const GURL& script_url, |
102 int worker_devtools_agent_route_id) | 102 int worker_devtools_agent_route_id) |
103 : embedded_worker_id_(embedded_worker_id), | 103 : embedded_worker_id_(embedded_worker_id), |
104 service_worker_version_id_(service_worker_version_id), | 104 service_worker_version_id_(service_worker_version_id), |
105 service_worker_scope_(service_worker_scope), | 105 service_worker_scope_(service_worker_scope), |
106 script_url_(script_url), | 106 script_url_(script_url), |
107 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), | 107 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), |
108 sender_(ChildThreadImpl::current()->thread_safe_sender()), | 108 sender_(ChildThreadImpl::current()->thread_safe_sender()), |
109 main_thread_proxy_(base::MessageLoopProxy::current()), | 109 main_thread_task_runner_(RenderThreadImpl::current()->GetTaskRunner()), |
110 weak_factory_(this) { | 110 weak_factory_(this) { |
111 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 111 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
112 "EmbeddedWorkerContextClient::StartingWorkerContext", | 112 "EmbeddedWorkerContextClient::StartingWorkerContext", |
113 this); | 113 this); |
114 TRACE_EVENT_ASYNC_STEP_INTO0( | 114 TRACE_EVENT_ASYNC_STEP_INTO0( |
115 "ServiceWorker", | 115 "ServiceWorker", |
116 "EmbeddedWorkerContextClient::StartingWorkerContext", | 116 "EmbeddedWorkerContextClient::StartingWorkerContext", |
117 this, | 117 this, |
118 "PrepareWorker"); | 118 "PrepareWorker"); |
119 } | 119 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 const blink::WebURL& url) { | 173 const blink::WebURL& url) { |
174 DCHECK(script_context_); | 174 DCHECK(script_context_); |
175 script_context_->ClearCachedMetadata(url); | 175 script_context_->ClearCachedMetadata(url); |
176 } | 176 } |
177 | 177 |
178 void EmbeddedWorkerContextClient::workerReadyForInspection() { | 178 void EmbeddedWorkerContextClient::workerReadyForInspection() { |
179 Send(new EmbeddedWorkerHostMsg_WorkerReadyForInspection(embedded_worker_id_)); | 179 Send(new EmbeddedWorkerHostMsg_WorkerReadyForInspection(embedded_worker_id_)); |
180 } | 180 } |
181 | 181 |
182 void EmbeddedWorkerContextClient::workerContextFailedToStart() { | 182 void EmbeddedWorkerContextClient::workerContextFailedToStart() { |
183 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread()); | 183 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
184 DCHECK(!script_context_); | 184 DCHECK(!script_context_); |
185 | 185 |
186 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoadFailed(embedded_worker_id_)); | 186 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoadFailed(embedded_worker_id_)); |
187 | 187 |
188 RenderThreadImpl::current()->embedded_worker_dispatcher()-> | 188 RenderThreadImpl::current()->embedded_worker_dispatcher()-> |
189 WorkerContextDestroyed(embedded_worker_id_); | 189 WorkerContextDestroyed(embedded_worker_id_); |
190 } | 190 } |
191 | 191 |
192 void EmbeddedWorkerContextClient::workerContextStarted( | 192 void EmbeddedWorkerContextClient::workerContextStarted( |
193 blink::WebServiceWorkerContextProxy* proxy) { | 193 blink::WebServiceWorkerContextProxy* proxy) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // This also lets the message filter stop dispatching messages to | 236 // This also lets the message filter stop dispatching messages to |
237 // this client. | 237 // this client. |
238 g_worker_client_tls.Pointer()->Set(NULL); | 238 g_worker_client_tls.Pointer()->Set(NULL); |
239 } | 239 } |
240 | 240 |
241 void EmbeddedWorkerContextClient::workerContextDestroyed() { | 241 void EmbeddedWorkerContextClient::workerContextDestroyed() { |
242 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); | 242 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); |
243 | 243 |
244 // Now we should be able to free the WebEmbeddedWorker container on the | 244 // Now we should be able to free the WebEmbeddedWorker container on the |
245 // main thread. | 245 // main thread. |
246 main_thread_proxy_->PostTask( | 246 main_thread_task_runner_->PostTask( |
247 FROM_HERE, | 247 FROM_HERE, |
248 base::Bind(&CallWorkerContextDestroyedOnMainThread, | 248 base::Bind(&CallWorkerContextDestroyedOnMainThread, |
249 embedded_worker_id_)); | 249 embedded_worker_id_)); |
250 } | 250 } |
251 | 251 |
252 void EmbeddedWorkerContextClient::reportException( | 252 void EmbeddedWorkerContextClient::reportException( |
253 const blink::WebString& error_message, | 253 const blink::WebString& error_message, |
254 int line_number, | 254 int line_number, |
255 int column_number, | 255 int column_number, |
256 const blink::WebString& source_url) { | 256 const blink::WebString& source_url) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 int request_id, | 348 int request_id, |
349 bool accept_connection) { | 349 bool accept_connection) { |
350 DCHECK(script_context_); | 350 DCHECK(script_context_); |
351 script_context_->DidHandleCrossOriginConnectEvent(request_id, | 351 script_context_->DidHandleCrossOriginConnectEvent(request_id, |
352 accept_connection); | 352 accept_connection); |
353 } | 353 } |
354 | 354 |
355 blink::WebServiceWorkerNetworkProvider* | 355 blink::WebServiceWorkerNetworkProvider* |
356 EmbeddedWorkerContextClient::createServiceWorkerNetworkProvider( | 356 EmbeddedWorkerContextClient::createServiceWorkerNetworkProvider( |
357 blink::WebDataSource* data_source) { | 357 blink::WebDataSource* data_source) { |
358 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread()); | 358 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
359 | 359 |
360 // Create a content::ServiceWorkerNetworkProvider for this data source so | 360 // Create a content::ServiceWorkerNetworkProvider for this data source so |
361 // we can observe its requests. | 361 // we can observe its requests. |
362 scoped_ptr<ServiceWorkerNetworkProvider> provider( | 362 scoped_ptr<ServiceWorkerNetworkProvider> provider( |
363 new ServiceWorkerNetworkProvider( | 363 new ServiceWorkerNetworkProvider( |
364 MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_CONTROLLER)); | 364 MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_CONTROLLER)); |
365 provider_context_ = provider->context(); | 365 provider_context_ = provider->context(); |
366 | 366 |
367 // Tell the network provider about which version to load. | 367 // Tell the network provider about which version to load. |
368 provider->SetServiceWorkerVersionId(service_worker_version_id_); | 368 provider->SetServiceWorkerVersionId(service_worker_version_id_); |
369 | 369 |
370 // The provider is kept around for the lifetime of the DataSource | 370 // The provider is kept around for the lifetime of the DataSource |
371 // and ownership is transferred to the DataSource. | 371 // and ownership is transferred to the DataSource. |
372 DataSourceExtraData* extra_data = new DataSourceExtraData(); | 372 DataSourceExtraData* extra_data = new DataSourceExtraData(); |
373 data_source->setExtraData(extra_data); | 373 data_source->setExtraData(extra_data); |
374 ServiceWorkerNetworkProvider::AttachToDocumentState( | 374 ServiceWorkerNetworkProvider::AttachToDocumentState( |
375 extra_data, provider.Pass()); | 375 extra_data, provider.Pass()); |
376 | 376 |
377 // Blink is responsible for deleting the returned object. | 377 // Blink is responsible for deleting the returned object. |
378 return new WebServiceWorkerNetworkProviderImpl(); | 378 return new WebServiceWorkerNetworkProviderImpl(); |
379 } | 379 } |
380 | 380 |
381 blink::WebServiceWorkerProvider* | 381 blink::WebServiceWorkerProvider* |
382 EmbeddedWorkerContextClient::createServiceWorkerProvider() { | 382 EmbeddedWorkerContextClient::createServiceWorkerProvider() { |
383 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread()); | 383 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
384 DCHECK(provider_context_); | 384 DCHECK(provider_context_); |
385 | 385 |
386 // Blink is responsible for deleting the returned object. | 386 // Blink is responsible for deleting the returned object. |
387 return new WebServiceWorkerProviderImpl( | 387 return new WebServiceWorkerProviderImpl( |
388 thread_safe_sender(), provider_context_.get()); | 388 thread_safe_sender(), provider_context_.get()); |
389 } | 389 } |
390 | 390 |
391 void EmbeddedWorkerContextClient::postMessageToClient( | 391 void EmbeddedWorkerContextClient::postMessageToClient( |
392 int client_id, | 392 int client_id, |
393 const blink::WebString& message, | 393 const blink::WebString& message, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 registration->SetWaiting( | 467 registration->SetWaiting( |
468 dispatcher->GetServiceWorker(attrs.waiting, false)); | 468 dispatcher->GetServiceWorker(attrs.waiting, false)); |
469 registration->SetActive( | 469 registration->SetActive( |
470 dispatcher->GetServiceWorker(attrs.active, false)); | 470 dispatcher->GetServiceWorker(attrs.active, false)); |
471 | 471 |
472 script_context_->SetRegistrationInServiceWorkerGlobalScope( | 472 script_context_->SetRegistrationInServiceWorkerGlobalScope( |
473 registration.Pass()); | 473 registration.Pass()); |
474 } | 474 } |
475 | 475 |
476 } // namespace content | 476 } // namespace content |
OLD | NEW |