Chromium Code Reviews| 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/browser/service_worker/embedded_worker_instance.h" | 5 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "content/browser/devtools/service_worker_devtools_manager.h" | 14 #include "content/browser/devtools/service_worker_devtools_manager.h" |
| 15 #include "content/browser/service_worker/embedded_worker_registry.h" | 15 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 16 #include "content/browser/service_worker/service_worker_context_core.h" | 16 #include "content/browser/service_worker/service_worker_context_core.h" |
| 17 #include "content/common/content_switches_internal.h" | 17 #include "content/common/content_switches_internal.h" |
| 18 #include "content/common/mojo/service_registry_impl.h" | |
| 18 #include "content/common/service_worker/embedded_worker_messages.h" | 19 #include "content/common/service_worker/embedded_worker_messages.h" |
| 20 #include "content/common/service_worker/embedded_worker_setup.mojom.h" | |
| 19 #include "content/common/service_worker/service_worker_types.h" | 21 #include "content/common/service_worker/service_worker_types.h" |
| 20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 22 #include "ipc/ipc_message.h" | 24 #include "ipc/ipc_message.h" |
| 23 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 24 | 26 |
| 25 namespace content { | 27 namespace content { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 service_worker_context_weak, | 78 service_worker_context_weak, |
| 77 service_worker_version_id, | 79 service_worker_version_id, |
| 78 url)); | 80 url)); |
| 79 } | 81 } |
| 80 BrowserThread::PostTask( | 82 BrowserThread::PostTask( |
| 81 BrowserThread::IO, | 83 BrowserThread::IO, |
| 82 FROM_HERE, | 84 FROM_HERE, |
| 83 base::Bind(callback, worker_devtools_agent_route_id, wait_for_debugger)); | 85 base::Bind(callback, worker_devtools_agent_route_id, wait_for_debugger)); |
| 84 } | 86 } |
| 85 | 87 |
| 88 void SetupMojoOnUIThread(int process_id, | |
| 89 int thread_id, | |
| 90 mojo::InterfaceRequest<mojo::ServiceProvider> services, | |
| 91 mojo::ServiceProviderPtr exposed_services) { | |
| 92 RenderProcessHost* rph = RenderProcessHost::FromID(process_id); | |
| 93 // |rph| may be NULL in unit tests. | |
| 94 if (!rph) | |
| 95 return; | |
| 96 EmbeddedWorkerSetupPtr setup; | |
| 97 rph->GetServiceRegistry()->ConnectToRemoteService(mojo::GetProxy(&setup)); | |
| 98 setup->ExchangeServiceProviders(thread_id, services.Pass(), | |
|
michaeln
2015/07/07 22:15:09
I'm not familiar enough to know what happens at ru
| |
| 99 exposed_services.Pass()); | |
| 100 } | |
| 101 | |
| 86 } // namespace | 102 } // namespace |
| 87 | 103 |
| 88 // Lives on IO thread, proxies notifications to DevToolsManager that lives on | 104 // Lives on IO thread, proxies notifications to DevToolsManager that lives on |
| 89 // UI thread. Owned by EmbeddedWorkerInstance. | 105 // UI thread. Owned by EmbeddedWorkerInstance. |
| 90 class EmbeddedWorkerInstance::DevToolsProxy : public base::NonThreadSafe { | 106 class EmbeddedWorkerInstance::DevToolsProxy : public base::NonThreadSafe { |
| 91 public: | 107 public: |
| 92 DevToolsProxy(int process_id, int agent_route_id) | 108 DevToolsProxy(int process_id, int agent_route_id) |
| 93 : process_id_(process_id), | 109 : process_id_(process_id), |
| 94 agent_route_id_(agent_route_id) {} | 110 agent_route_id_(agent_route_id) {} |
| 95 | 111 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( | 220 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( |
| 205 const IPC::Message& message) { | 221 const IPC::Message& message) { |
| 206 DCHECK_NE(kInvalidEmbeddedWorkerThreadId, thread_id_); | 222 DCHECK_NE(kInvalidEmbeddedWorkerThreadId, thread_id_); |
| 207 if (status_ != RUNNING && status_ != STARTING) | 223 if (status_ != RUNNING && status_ != STARTING) |
| 208 return SERVICE_WORKER_ERROR_IPC_FAILED; | 224 return SERVICE_WORKER_ERROR_IPC_FAILED; |
| 209 return registry_->Send(process_id_, | 225 return registry_->Send(process_id_, |
| 210 new EmbeddedWorkerContextMsg_MessageToWorker( | 226 new EmbeddedWorkerContextMsg_MessageToWorker( |
| 211 thread_id_, embedded_worker_id_, message)); | 227 thread_id_, embedded_worker_id_, message)); |
| 212 } | 228 } |
| 213 | 229 |
| 230 ServiceRegistry* EmbeddedWorkerInstance::GetServiceRegistry() { | |
| 231 return service_registry_.get(); | |
| 232 } | |
| 233 | |
| 214 EmbeddedWorkerInstance::EmbeddedWorkerInstance( | 234 EmbeddedWorkerInstance::EmbeddedWorkerInstance( |
| 215 base::WeakPtr<ServiceWorkerContextCore> context, | 235 base::WeakPtr<ServiceWorkerContextCore> context, |
| 216 int embedded_worker_id) | 236 int embedded_worker_id) |
| 217 : context_(context), | 237 : context_(context), |
| 218 registry_(context->embedded_worker_registry()), | 238 registry_(context->embedded_worker_registry()), |
| 219 embedded_worker_id_(embedded_worker_id), | 239 embedded_worker_id_(embedded_worker_id), |
| 220 status_(STOPPED), | 240 status_(STOPPED), |
| 221 starting_phase_(NOT_STARTING), | 241 starting_phase_(NOT_STARTING), |
| 222 process_id_(-1), | 242 process_id_(-1), |
| 223 thread_id_(kInvalidEmbeddedWorkerThreadId), | 243 thread_id_(kInvalidEmbeddedWorkerThreadId), |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 UMA_HISTOGRAM_TIMES( | 366 UMA_HISTOGRAM_TIMES( |
| 347 "EmbeddedWorkerInstance.ScriptLoadWithoutNetworkAccess", | 367 "EmbeddedWorkerInstance.ScriptLoadWithoutNetworkAccess", |
| 348 base::TimeTicks::Now() - start_timing_); | 368 base::TimeTicks::Now() - start_timing_); |
| 349 } | 369 } |
| 350 // Reset |start_timing_| to measure the time excluding the process | 370 // Reset |start_timing_| to measure the time excluding the process |
| 351 // allocation time and the script loading time. | 371 // allocation time and the script loading time. |
| 352 start_timing_ = base::TimeTicks::Now(); | 372 start_timing_ = base::TimeTicks::Now(); |
| 353 } | 373 } |
| 354 thread_id_ = thread_id; | 374 thread_id_ = thread_id; |
| 355 FOR_EACH_OBSERVER(Listener, listener_list_, OnScriptLoaded()); | 375 FOR_EACH_OBSERVER(Listener, listener_list_, OnScriptLoaded()); |
| 376 | |
| 377 service_registry_.reset(new ServiceRegistryImpl()); | |
| 378 mojo::ServiceProviderPtr exposed_services; | |
| 379 service_registry_->Bind(GetProxy(&exposed_services)); | |
| 380 mojo::ServiceProviderPtr services; | |
| 381 mojo::InterfaceRequest<mojo::ServiceProvider> services_request = | |
| 382 GetProxy(&services); | |
| 383 BrowserThread::PostTask( | |
| 384 BrowserThread::UI, FROM_HERE, | |
| 385 base::Bind(SetupMojoOnUIThread, process_id_, thread_id_, | |
| 386 base::Passed(&services_request), | |
| 387 base::Passed(&exposed_services))); | |
| 388 service_registry_->BindRemoteServiceProvider(services.Pass()); | |
| 356 } | 389 } |
| 357 | 390 |
| 358 void EmbeddedWorkerInstance::OnScriptLoadFailed() { | 391 void EmbeddedWorkerInstance::OnScriptLoadFailed() { |
| 359 } | 392 } |
| 360 | 393 |
| 361 void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) { | 394 void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) { |
| 362 starting_phase_ = SCRIPT_EVALUATED; | 395 starting_phase_ = SCRIPT_EVALUATED; |
| 363 if (start_callback_.is_null()) { | 396 if (start_callback_.is_null()) { |
| 364 DVLOG(1) << "Received unexpected OnScriptEvaluated message."; | 397 DVLOG(1) << "Received unexpected OnScriptEvaluated message."; |
| 365 return; | 398 return; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 378 if (status_ == STOPPING) | 411 if (status_ == STOPPING) |
| 379 return; | 412 return; |
| 380 DCHECK(status_ == STARTING); | 413 DCHECK(status_ == STARTING); |
| 381 status_ = RUNNING; | 414 status_ = RUNNING; |
| 382 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); | 415 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); |
| 383 } | 416 } |
| 384 | 417 |
| 385 void EmbeddedWorkerInstance::OnStopped() { | 418 void EmbeddedWorkerInstance::OnStopped() { |
| 386 Status old_status = status_; | 419 Status old_status = status_; |
| 387 ReleaseProcess(); | 420 ReleaseProcess(); |
| 421 service_registry_.reset(); | |
| 388 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped(old_status)); | 422 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped(old_status)); |
| 389 } | 423 } |
| 390 | 424 |
| 391 void EmbeddedWorkerInstance::OnDetached() { | 425 void EmbeddedWorkerInstance::OnDetached() { |
| 392 Status old_status = status_; | 426 Status old_status = status_; |
| 393 ReleaseProcess(); | 427 ReleaseProcess(); |
| 394 FOR_EACH_OBSERVER(Listener, listener_list_, OnDetached(old_status)); | 428 FOR_EACH_OBSERVER(Listener, listener_list_, OnDetached(old_status)); |
| 395 } | 429 } |
| 396 | 430 |
| 397 void EmbeddedWorkerInstance::OnPausedAfterDownload() { | 431 void EmbeddedWorkerInstance::OnPausedAfterDownload() { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 case SCRIPT_EVALUATED: | 537 case SCRIPT_EVALUATED: |
| 504 return "Script evaluated"; | 538 return "Script evaluated"; |
| 505 case STARTING_PHASE_MAX_VALUE: | 539 case STARTING_PHASE_MAX_VALUE: |
| 506 NOTREACHED(); | 540 NOTREACHED(); |
| 507 } | 541 } |
| 508 NOTREACHED() << phase; | 542 NOTREACHED() << phase; |
| 509 return std::string(); | 543 return std::string(); |
| 510 } | 544 } |
| 511 | 545 |
| 512 } // namespace content | 546 } // namespace content |
| OLD | NEW |