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

Side by Side Diff: content/browser/service_worker/embedded_worker_instance.cc

Issue 2490623005: Remove InterfaceRegistry/Provider from service workers (Closed)
Patch Set: Created 4 years, 1 month 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 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/common/service_worker/embedded_worker_setup.mojom.h" 22 #include "content/common/service_worker/embedded_worker_setup.mojom.h"
23 #include "content/common/service_worker/embedded_worker_start_params.h" 23 #include "content/common/service_worker/embedded_worker_start_params.h"
24 #include "content/common/service_worker/service_worker_types.h" 24 #include "content/common/service_worker/service_worker_types.h"
25 #include "content/common/service_worker/service_worker_utils.h" 25 #include "content/common/service_worker/service_worker_utils.h"
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/content_browser_client.h" 27 #include "content/public/browser/content_browser_client.h"
28 #include "content/public/browser/render_process_host.h" 28 #include "content/public/browser/render_process_host.h"
29 #include "content/public/common/child_process_host.h" 29 #include "content/public/common/child_process_host.h"
30 #include "content/public/common/content_switches.h" 30 #include "content/public/common/content_switches.h"
31 #include "ipc/ipc_message.h" 31 #include "ipc/ipc_message.h"
32 #include "services/service_manager/public/cpp/interface_provider.h"
33 #include "services/service_manager/public/cpp/interface_registry.h"
34 #include "url/gurl.h" 32 #include "url/gurl.h"
35 33
36 namespace content { 34 namespace content {
37 35
38 namespace { 36 namespace {
39 37
40 // When a service worker version's failure count exceeds 38 // When a service worker version's failure count exceeds
41 // |kMaxSameProcessFailureCount|, the embedded worker is forced to start in a 39 // |kMaxSameProcessFailureCount|, the embedded worker is forced to start in a
42 // new process. 40 // new process.
43 const int kMaxSameProcessFailureCount = 2; 41 const int kMaxSameProcessFailureCount = 2;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 is_installed); 96 is_installed);
99 if (request.is_pending()) 97 if (request.is_pending())
100 rph->GetRemoteInterfaces()->GetInterface(std::move(request)); 98 rph->GetRemoteInterfaces()->GetInterface(std::move(request));
101 } 99 }
102 BrowserThread::PostTask( 100 BrowserThread::PostTask(
103 BrowserThread::IO, 101 BrowserThread::IO,
104 FROM_HERE, 102 FROM_HERE,
105 base::Bind(callback, worker_devtools_agent_route_id, wait_for_debugger)); 103 base::Bind(callback, worker_devtools_agent_route_id, wait_for_debugger));
106 } 104 }
107 105
108 void SetupMojoOnUIThread( 106 void SetupEventDispatcherOnUIThread(
109 int process_id, 107 int process_id,
110 int thread_id, 108 int thread_id,
111 service_manager::mojom::InterfaceProviderRequest remote_interfaces, 109 mojom::ServiceWorkerEventDispatcherRequest request) {
112 service_manager::mojom::InterfaceProviderPtrInfo exposed_interfaces) { 110 DCHECK(!ServiceWorkerUtils::IsMojoForServiceWorkerEnabled());
113 RenderProcessHost* rph = RenderProcessHost::FromID(process_id); 111 RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
114 // |rph| or its InterfaceProvider may be NULL in unit tests. 112 // |rph| or its InterfaceProvider may be NULL in unit tests.
115 if (!rph || !rph->GetRemoteInterfaces()) 113 if (!rph || !rph->GetRemoteInterfaces())
116 return; 114 return;
117 mojom::EmbeddedWorkerSetupPtr setup; 115 mojom::EmbeddedWorkerSetupPtr setup;
118 rph->GetRemoteInterfaces()->GetInterface(&setup); 116 rph->GetRemoteInterfaces()->GetInterface(&setup);
119 setup->ExchangeInterfaceProviders( 117 setup->AttachServiceWorkerEventDispatcher(thread_id, std::move(request));
120 thread_id, std::move(remote_interfaces),
121 mojo::MakeProxy(std::move(exposed_interfaces)));
122 } 118 }
123 119
124 void CallDetach(EmbeddedWorkerInstance* instance) { 120 void CallDetach(EmbeddedWorkerInstance* instance) {
125 // This could be called on the UI thread if |client_| still be valid when the 121 // This could be called on the UI thread if |client_| still be valid when the
126 // message loop on the UI thread gets destructed. 122 // message loop on the UI thread gets destructed.
127 // TODO(shimazu): Remove this after https://crbug.com/604762 is fixed 123 // TODO(shimazu): Remove this after https://crbug.com/604762 is fixed
128 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 124 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
129 DCHECK(ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()); 125 DCHECK(ServiceWorkerUtils::IsMojoForServiceWorkerEnabled());
130 return; 126 return;
131 } 127 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // requests in the queue. See ServiceWorkerVersion::OnStoppedInternal() for 268 // requests in the queue. See ServiceWorkerVersion::OnStoppedInternal() for
273 // details. 269 // details.
274 // TODO(nhiroki): Reconsider this bizarre layering. 270 // TODO(nhiroki): Reconsider this bizarre layering.
275 } 271 }
276 272
277 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, 273 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params,
278 const StatusCallback& callback) { 274 const StatusCallback& callback) {
279 DCHECK_CURRENTLY_ON(BrowserThread::IO); 275 DCHECK_CURRENTLY_ON(BrowserThread::IO);
280 state_ = ProcessAllocationState::ALLOCATING; 276 state_ = ProcessAllocationState::ALLOCATING;
281 start_callback_ = callback; 277 start_callback_ = callback;
282 is_installed_ = params->is_installed; 278 is_installed_ = params->internal.is_installed;
283 279
284 if (!GetContentClient()->browser()->IsBrowserStartupComplete()) 280 if (!GetContentClient()->browser()->IsBrowserStartupComplete())
285 started_during_browser_startup_ = true; 281 started_during_browser_startup_ = true;
286 282
287 GURL scope(params->scope); 283 GURL scope(params->internal.scope);
288 GURL script_url(params->script_url); 284 GURL script_url(params->internal.script_url);
289 285
290 bool can_use_existing_process = 286 bool can_use_existing_process =
291 instance_->context_->GetVersionFailureCount( 287 instance_->context_->GetVersionFailureCount(
292 params->service_worker_version_id) < kMaxSameProcessFailureCount; 288 params->internal.service_worker_version_id) <
289 kMaxSameProcessFailureCount;
293 instance_->context_->process_manager()->AllocateWorkerProcess( 290 instance_->context_->process_manager()->AllocateWorkerProcess(
294 instance_->embedded_worker_id_, scope, script_url, 291 instance_->embedded_worker_id_, scope, script_url,
295 can_use_existing_process, 292 can_use_existing_process,
296 base::Bind(&StartTask::OnProcessAllocated, weak_factory_.GetWeakPtr(), 293 base::Bind(&StartTask::OnProcessAllocated, weak_factory_.GetWeakPtr(),
297 base::Passed(&params))); 294 base::Passed(&params)));
298 } 295 }
299 296
300 static void RunStartCallback(StartTask* task, 297 static void RunStartCallback(StartTask* task,
301 ServiceWorkerStatusCode status) { 298 ServiceWorkerStatusCode status) {
302 DCHECK_CURRENTLY_ON(BrowserThread::IO); 299 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 // Notify the instance that a process is allocated. 343 // Notify the instance that a process is allocated.
347 state_ = ProcessAllocationState::ALLOCATED; 344 state_ = ProcessAllocationState::ALLOCATED;
348 instance_->OnProcessAllocated( 345 instance_->OnProcessAllocated(
349 base::MakeUnique<WorkerProcessHandle>(instance_->context_, 346 base::MakeUnique<WorkerProcessHandle>(instance_->context_,
350 instance_->embedded_worker_id(), 347 instance_->embedded_worker_id(),
351 process_id, is_new_process), 348 process_id, is_new_process),
352 start_situation); 349 start_situation);
353 350
354 // TODO(bengr): Support changes to this setting while the worker 351 // TODO(bengr): Support changes to this setting while the worker
355 // is running. 352 // is running.
356 params->settings.data_saver_enabled = settings.data_saver_enabled; 353 params->internal.settings.data_saver_enabled = settings.data_saver_enabled;
357 354
358 // Register the instance to DevToolsManager on UI thread. 355 // Register the instance to DevToolsManager on UI thread.
359 const int64_t service_worker_version_id = params->service_worker_version_id; 356 const int64_t service_worker_version_id =
360 const GURL& scope = params->scope; 357 params->internal.service_worker_version_id;
361 GURL script_url(params->script_url); 358 const GURL& scope = params->internal.scope;
359 GURL script_url(params->internal.script_url);
362 BrowserThread::PostTask( 360 BrowserThread::PostTask(
363 BrowserThread::UI, FROM_HERE, 361 BrowserThread::UI, FROM_HERE,
364 base::Bind(&SetupOnUI, process_id, instance_->context_.get(), 362 base::Bind(&SetupOnUI, process_id, instance_->context_.get(),
365 instance_->context_, service_worker_version_id, script_url, 363 instance_->context_, service_worker_version_id, script_url,
366 scope, is_installed_, base::Passed(&request_), 364 scope, is_installed_, base::Passed(&request_),
367 base::Bind(&StartTask::OnSetupOnUICompleted, 365 base::Bind(&StartTask::OnSetupOnUICompleted,
368 weak_factory_.GetWeakPtr(), base::Passed(&params), 366 weak_factory_.GetWeakPtr(), base::Passed(&params),
369 is_new_process))); 367 is_new_process)));
370 } 368 }
371 369
372 void OnSetupOnUICompleted(std::unique_ptr<EmbeddedWorkerStartParams> params, 370 void OnSetupOnUICompleted(std::unique_ptr<EmbeddedWorkerStartParams> params,
373 bool is_new_process, 371 bool is_new_process,
374 int worker_devtools_agent_route_id, 372 int worker_devtools_agent_route_id,
375 bool wait_for_debugger) { 373 bool wait_for_debugger) {
376 DCHECK_CURRENTLY_ON(BrowserThread::IO); 374 DCHECK_CURRENTLY_ON(BrowserThread::IO);
377 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", 375 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker",
378 "EmbeddedWorkerInstance::Start", this, 376 "EmbeddedWorkerInstance::Start", this,
379 "OnSetupOnUICompleted"); 377 "OnSetupOnUICompleted");
380 378
381 // Notify the instance that it is registered to the devtools manager. 379 // Notify the instance that it is registered to the devtools manager.
382 instance_->OnRegisteredToDevToolsManager( 380 instance_->OnRegisteredToDevToolsManager(
383 is_new_process, worker_devtools_agent_route_id, wait_for_debugger); 381 is_new_process, worker_devtools_agent_route_id, wait_for_debugger);
384 382
385 params->worker_devtools_agent_route_id = worker_devtools_agent_route_id; 383 params->internal.worker_devtools_agent_route_id =
386 params->wait_for_debugger = wait_for_debugger; 384 worker_devtools_agent_route_id;
385 params->internal.wait_for_debugger = wait_for_debugger;
387 386
388 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) 387 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled())
389 SendMojoStartWorker(std::move(params)); 388 SendMojoStartWorker(std::move(params));
390 else 389 else
391 SendStartWorker(std::move(params)); 390 SendStartWorker(std::move(params));
392 } 391 }
393 392
394 void SendStartWorker(std::unique_ptr<EmbeddedWorkerStartParams> params) { 393 void SendStartWorker(std::unique_ptr<EmbeddedWorkerStartParams> params) {
395 DCHECK_CURRENTLY_ON(BrowserThread::IO); 394 DCHECK_CURRENTLY_ON(BrowserThread::IO);
396 ServiceWorkerStatusCode status = instance_->registry_->SendStartWorker( 395 ServiceWorkerStatusCode status = instance_->registry_->SendStartWorker(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() { 449 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() {
451 DCHECK(status_ == EmbeddedWorkerStatus::STOPPING || 450 DCHECK(status_ == EmbeddedWorkerStatus::STOPPING ||
452 status_ == EmbeddedWorkerStatus::STOPPED) 451 status_ == EmbeddedWorkerStatus::STOPPED)
453 << static_cast<int>(status_); 452 << static_cast<int>(status_);
454 devtools_proxy_.reset(); 453 devtools_proxy_.reset();
455 if (registry_->GetWorker(embedded_worker_id_)) 454 if (registry_->GetWorker(embedded_worker_id_))
456 registry_->RemoveWorker(process_id(), embedded_worker_id_); 455 registry_->RemoveWorker(process_id(), embedded_worker_id_);
457 process_handle_.reset(); 456 process_handle_.reset();
458 } 457 }
459 458
460 void EmbeddedWorkerInstance::Start( 459 void EmbeddedWorkerInstance::Start(
horo 2016/11/11 02:17:27 I think this approach is a bit confusing. "Embedde
shimazu 2016/11/17 22:23:38 Done.
461 std::unique_ptr<EmbeddedWorkerStartParams> params, 460 std::unique_ptr<EmbeddedWorkerStartParams> params,
462 const StatusCallback& callback) { 461 const StatusCallback& callback) {
463 if (!context_) { 462 if (!context_) {
464 callback.Run(SERVICE_WORKER_ERROR_ABORT); 463 callback.Run(SERVICE_WORKER_ERROR_ABORT);
465 // |this| may be destroyed by the callback. 464 // |this| may be destroyed by the callback.
466 return; 465 return;
467 } 466 }
468 DCHECK(status_ == EmbeddedWorkerStatus::STOPPED); 467 DCHECK(status_ == EmbeddedWorkerStatus::STOPPED);
469 468
470 DCHECK(!params->pause_after_download || !params->is_installed); 469 EmbeddedWorkerStartParamsInternal* internal = &params->internal;
471 DCHECK_NE(kInvalidServiceWorkerVersionId, params->service_worker_version_id); 470 DCHECK(!internal->pause_after_download || !internal->is_installed);
471 DCHECK_NE(kInvalidServiceWorkerVersionId,
472 internal->service_worker_version_id);
472 step_time_ = base::TimeTicks::Now(); 473 step_time_ = base::TimeTicks::Now();
473 status_ = EmbeddedWorkerStatus::STARTING; 474 status_ = EmbeddedWorkerStatus::STARTING;
474 starting_phase_ = ALLOCATING_PROCESS; 475 starting_phase_ = ALLOCATING_PROCESS;
475 network_accessed_for_script_ = false; 476 network_accessed_for_script_ = false;
476 interface_registry_ =
477 base::MakeUnique<service_manager::InterfaceRegistry>(std::string());
478 remote_interfaces_.reset(new service_manager::InterfaceProvider);
479 for (auto& observer : listener_list_) 477 for (auto& observer : listener_list_)
480 observer.OnStarting(); 478 observer.OnStarting();
481 479
482 params->embedded_worker_id = embedded_worker_id_; 480 internal->embedded_worker_id = embedded_worker_id_;
483 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE; 481 internal->worker_devtools_agent_route_id = MSG_ROUTING_NONE;
484 params->wait_for_debugger = false; 482 internal->wait_for_debugger = false;
485 params->settings.v8_cache_options = GetV8CacheOptions(); 483 internal->settings.v8_cache_options = GetV8CacheOptions();
486 484
487 mojom::EmbeddedWorkerInstanceClientRequest request; 485 mojom::EmbeddedWorkerInstanceClientRequest request;
488 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { 486 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) {
489 request = mojo::GetProxy(&client_); 487 request = mojo::GetProxy(&client_);
490 client_.set_connection_error_handler( 488 client_.set_connection_error_handler(
491 base::Bind(&CallDetach, base::Unretained(this))); 489 base::Bind(&CallDetach, base::Unretained(this)));
492 } 490 }
493 491
492 if (!ServiceWorkerUtils::IsMojoForServiceWorkerEnabled())
493 pending_dispatcher_request_ = std::move(params->dispatcher_request);
494
494 inflight_start_task_.reset( 495 inflight_start_task_.reset(
495 new StartTask(this, params->script_url, std::move(request))); 496 new StartTask(this, internal->script_url, std::move(request)));
496 inflight_start_task_->Start(std::move(params), callback); 497 inflight_start_task_->Start(std::move(params), callback);
497 } 498 }
498 499
499 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { 500 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() {
500 DCHECK(status_ == EmbeddedWorkerStatus::STARTING || 501 DCHECK(status_ == EmbeddedWorkerStatus::STARTING ||
501 status_ == EmbeddedWorkerStatus::RUNNING) 502 status_ == EmbeddedWorkerStatus::RUNNING)
502 << static_cast<int>(status_); 503 << static_cast<int>(status_);
503 504
504 // Abort an inflight start task. 505 // Abort an inflight start task.
505 inflight_start_task_.reset(); 506 inflight_start_task_.reset();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 559
559 void EmbeddedWorkerInstance::ResumeAfterDownload() { 560 void EmbeddedWorkerInstance::ResumeAfterDownload() {
560 if (process_id() == ChildProcessHost::kInvalidUniqueID || 561 if (process_id() == ChildProcessHost::kInvalidUniqueID ||
561 status_ != EmbeddedWorkerStatus::STARTING) { 562 status_ != EmbeddedWorkerStatus::STARTING) {
562 return; 563 return;
563 } 564 }
564 registry_->Send(process_id(), new EmbeddedWorkerMsg_ResumeAfterDownload( 565 registry_->Send(process_id(), new EmbeddedWorkerMsg_ResumeAfterDownload(
565 embedded_worker_id_)); 566 embedded_worker_id_));
566 } 567 }
567 568
568 service_manager::InterfaceRegistry*
569 EmbeddedWorkerInstance::GetInterfaceRegistry() {
570 DCHECK(status_ == EmbeddedWorkerStatus::STARTING ||
571 status_ == EmbeddedWorkerStatus::RUNNING)
572 << static_cast<int>(status_);
573 return interface_registry_.get();
574 }
575
576 service_manager::InterfaceProvider*
577 EmbeddedWorkerInstance::GetRemoteInterfaces() {
578 DCHECK(status_ == EmbeddedWorkerStatus::STARTING ||
579 status_ == EmbeddedWorkerStatus::RUNNING)
580 << static_cast<int>(status_);
581 return remote_interfaces_.get();
582 }
583
584 EmbeddedWorkerInstance::EmbeddedWorkerInstance( 569 EmbeddedWorkerInstance::EmbeddedWorkerInstance(
585 base::WeakPtr<ServiceWorkerContextCore> context, 570 base::WeakPtr<ServiceWorkerContextCore> context,
586 int embedded_worker_id) 571 int embedded_worker_id)
587 : context_(context), 572 : context_(context),
588 registry_(context->embedded_worker_registry()), 573 registry_(context->embedded_worker_registry()),
589 embedded_worker_id_(embedded_worker_id), 574 embedded_worker_id_(embedded_worker_id),
590 status_(EmbeddedWorkerStatus::STOPPED), 575 status_(EmbeddedWorkerStatus::STOPPED),
591 starting_phase_(NOT_STARTING), 576 starting_phase_(NOT_STARTING),
592 thread_id_(kInvalidEmbeddedWorkerThreadId), 577 thread_id_(kInvalidEmbeddedWorkerThreadId),
593 devtools_attached_(false), 578 devtools_attached_(false),
(...skipping 28 matching lines...) Expand all
622 step_time_ = base::TimeTicks(); 607 step_time_ = base::TimeTicks();
623 } 608 }
624 for (auto& observer : listener_list_) 609 for (auto& observer : listener_list_)
625 observer.OnRegisteredToDevToolsManager(); 610 observer.OnRegisteredToDevToolsManager();
626 } 611 }
627 612
628 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMojoStartWorker( 613 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMojoStartWorker(
629 std::unique_ptr<EmbeddedWorkerStartParams> params) { 614 std::unique_ptr<EmbeddedWorkerStartParams> params) {
630 if (!context_) 615 if (!context_)
631 return SERVICE_WORKER_ERROR_ABORT; 616 return SERVICE_WORKER_ERROR_ABORT;
632 service_manager::mojom::InterfaceProviderPtr remote_interfaces; 617 client_->StartWorker(params->internal, std::move(params->dispatcher_request));
633 service_manager::mojom::InterfaceProviderRequest request =
634 mojo::GetProxy(&remote_interfaces);
635 remote_interfaces_->Bind(std::move(remote_interfaces));
636 service_manager::mojom::InterfaceProviderPtr exposed_interfaces;
637 interface_registry_->Bind(
638 mojo::GetProxy(&exposed_interfaces), service_manager::Identity(),
639 service_manager::InterfaceProviderSpec(), service_manager::Identity(),
640 service_manager::InterfaceProviderSpec());
641 client_->StartWorker(*params, std::move(exposed_interfaces),
642 std::move(request));
643 registry_->BindWorkerToProcess(process_id(), embedded_worker_id()); 618 registry_->BindWorkerToProcess(process_id(), embedded_worker_id());
644 TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start", 619 TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start",
645 this, "SendStartWorker", "Status", "mojo"); 620 this, "SendStartWorker", "Status", "mojo");
646 OnStartWorkerMessageSent(); 621 OnStartWorkerMessageSent();
647 return SERVICE_WORKER_OK; 622 return SERVICE_WORKER_OK;
648 } 623 }
649 624
650 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() { 625 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() {
651 if (!step_time_.is_null()) { 626 if (!step_time_.is_null()) {
652 base::TimeDelta duration = UpdateStepTime(); 627 base::TimeDelta duration = UpdateStepTime();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 if (!step_time_.is_null()) { 711 if (!step_time_.is_null()) {
737 base::TimeDelta duration = UpdateStepTime(); 712 base::TimeDelta duration = UpdateStepTime();
738 if (inflight_start_task_->is_installed()) 713 if (inflight_start_task_->is_installed())
739 ServiceWorkerMetrics::RecordTimeToStartThread(duration, start_situation_); 714 ServiceWorkerMetrics::RecordTimeToStartThread(duration, start_situation_);
740 } 715 }
741 716
742 thread_id_ = thread_id; 717 thread_id_ = thread_id;
743 for (auto& observer : listener_list_) 718 for (auto& observer : listener_list_)
744 observer.OnThreadStarted(); 719 observer.OnThreadStarted();
745 720
746 // This code is for BackgroundSync and FetchEvent, which have been already 721 // The pending request is sent at StartWorker if mojo for the service worker
747 // mojofied. Interfaces are exchanged at StartWorker when mojo for the service 722 // is enabled.
748 // worker is enabled, so this code isn't necessary when the flag is enabled.
749 if (!ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { 723 if (!ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) {
750 service_manager::mojom::InterfaceProviderPtr exposed_interfaces; 724 DCHECK(pending_dispatcher_request_.is_pending());
751 interface_registry_->Bind(
752 mojo::GetProxy(&exposed_interfaces), service_manager::Identity(),
753 service_manager::InterfaceProviderSpec(), service_manager::Identity(),
754 service_manager::InterfaceProviderSpec());
755 service_manager::mojom::InterfaceProviderPtr remote_interfaces;
756 service_manager::mojom::InterfaceProviderRequest request =
757 mojo::GetProxy(&remote_interfaces);
758 remote_interfaces_->Bind(std::move(remote_interfaces));
759 BrowserThread::PostTask( 725 BrowserThread::PostTask(
760 BrowserThread::UI, FROM_HERE, 726 BrowserThread::UI, FROM_HERE,
761 base::Bind(SetupMojoOnUIThread, process_id(), thread_id_, 727 base::Bind(SetupEventDispatcherOnUIThread, process_id(), thread_id_,
762 base::Passed(&request), 728 base::Passed(&pending_dispatcher_request_)));
763 base::Passed(exposed_interfaces.PassInterface())));
764 } 729 }
765 } 730 }
766 731
767 void EmbeddedWorkerInstance::OnScriptLoadFailed() { 732 void EmbeddedWorkerInstance::OnScriptLoadFailed() {
768 if (!inflight_start_task_) 733 if (!inflight_start_task_)
769 return; 734 return;
770 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", 735 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start",
771 inflight_start_task_.get(), 736 inflight_start_task_.get(),
772 "OnScriptLoadFailed"); 737 "OnScriptLoadFailed");
773 for (auto& observer : listener_list_) 738 for (auto& observer : listener_list_)
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 865
901 void EmbeddedWorkerInstance::ReleaseProcess() { 866 void EmbeddedWorkerInstance::ReleaseProcess() {
902 // Abort an inflight start task. 867 // Abort an inflight start task.
903 inflight_start_task_.reset(); 868 inflight_start_task_.reset();
904 869
905 client_.reset(); 870 client_.reset();
906 devtools_proxy_.reset(); 871 devtools_proxy_.reset();
907 process_handle_.reset(); 872 process_handle_.reset();
908 status_ = EmbeddedWorkerStatus::STOPPED; 873 status_ = EmbeddedWorkerStatus::STOPPED;
909 thread_id_ = kInvalidEmbeddedWorkerThreadId; 874 thread_id_ = kInvalidEmbeddedWorkerThreadId;
910 interface_registry_.reset();
911 remote_interfaces_.reset();
912 } 875 }
913 876
914 void EmbeddedWorkerInstance::OnStartFailed(const StatusCallback& callback, 877 void EmbeddedWorkerInstance::OnStartFailed(const StatusCallback& callback,
915 ServiceWorkerStatusCode status) { 878 ServiceWorkerStatusCode status) {
916 EmbeddedWorkerStatus old_status = status_; 879 EmbeddedWorkerStatus old_status = status_;
917 ReleaseProcess(); 880 ReleaseProcess();
918 base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr(); 881 base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr();
919 callback.Run(status); 882 callback.Run(status);
920 if (weak_this && old_status != EmbeddedWorkerStatus::STOPPED) { 883 if (weak_this && old_status != EmbeddedWorkerStatus::STOPPED) {
921 for (auto& observer : weak_this->listener_list_) 884 for (auto& observer : weak_this->listener_list_)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 case SCRIPT_READ_FINISHED: 946 case SCRIPT_READ_FINISHED:
984 return "Script read finished"; 947 return "Script read finished";
985 case STARTING_PHASE_MAX_VALUE: 948 case STARTING_PHASE_MAX_VALUE:
986 NOTREACHED(); 949 NOTREACHED();
987 } 950 }
988 NOTREACHED() << phase; 951 NOTREACHED() << phase;
989 return std::string(); 952 return std::string();
990 } 953 }
991 954
992 } // namespace content 955 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698