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

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

Issue 2821253002: [ServiceWorker] Integrate trace events in embedded worker instance (Closed)
Patch Set: Address nits Created 3 years, 7 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 StartTask(EmbeddedWorkerInstance* instance, 238 StartTask(EmbeddedWorkerInstance* instance,
239 const GURL& script_url, 239 const GURL& script_url,
240 mojom::EmbeddedWorkerInstanceClientRequest request) 240 mojom::EmbeddedWorkerInstanceClientRequest request)
241 : instance_(instance), 241 : instance_(instance),
242 request_(std::move(request)), 242 request_(std::move(request)),
243 state_(ProcessAllocationState::NOT_ALLOCATED), 243 state_(ProcessAllocationState::NOT_ALLOCATED),
244 is_installed_(false), 244 is_installed_(false),
245 started_during_browser_startup_(false), 245 started_during_browser_startup_(false),
246 weak_factory_(this) { 246 weak_factory_(this) {
247 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "EmbeddedWorkerInstance::Start", 247 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1("ServiceWorker",
248 this, "Script", script_url.spec()); 248 "EmbeddedWorkerInstance::Start",
249 instance_, "Script", script_url.spec());
249 } 250 }
250 251
251 ~StartTask() { 252 ~StartTask() {
252 DCHECK_CURRENTLY_ON(BrowserThread::IO); 253 DCHECK_CURRENTLY_ON(BrowserThread::IO);
253 TRACE_EVENT_ASYNC_END0("ServiceWorker", "EmbeddedWorkerInstance::Start", 254 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker",
254 this); 255 "EmbeddedWorkerInstance::Start", instance_);
256
255 if (!instance_->context_) 257 if (!instance_->context_)
256 return; 258 return;
257 259
258 switch (state_) { 260 switch (state_) {
259 case ProcessAllocationState::NOT_ALLOCATED: 261 case ProcessAllocationState::NOT_ALLOCATED:
260 // Not necessary to release a process. 262 // Not necessary to release a process.
261 break; 263 break;
262 case ProcessAllocationState::ALLOCATING: 264 case ProcessAllocationState::ALLOCATING:
263 // Abort half-baked process allocation on the UI thread. 265 // Abort half-baked process allocation on the UI thread.
264 instance_->context_->process_manager()->ReleaseWorkerProcess( 266 instance_->context_->process_manager()->ReleaseWorkerProcess(
(...skipping 21 matching lines...) Expand all
286 state_ = ProcessAllocationState::ALLOCATING; 288 state_ = ProcessAllocationState::ALLOCATING;
287 start_callback_ = callback; 289 start_callback_ = callback;
288 is_installed_ = params->is_installed; 290 is_installed_ = params->is_installed;
289 291
290 if (!GetContentClient()->browser()->IsBrowserStartupComplete()) 292 if (!GetContentClient()->browser()->IsBrowserStartupComplete())
291 started_during_browser_startup_ = true; 293 started_during_browser_startup_ = true;
292 294
293 GURL scope(params->scope); 295 GURL scope(params->scope);
294 GURL script_url(params->script_url); 296 GURL script_url(params->script_url);
295 297
298 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "ALLOCATING_PROCESS",
299 instance_);
296 bool can_use_existing_process = 300 bool can_use_existing_process =
297 instance_->context_->GetVersionFailureCount( 301 instance_->context_->GetVersionFailureCount(
298 params->service_worker_version_id) < kMaxSameProcessFailureCount; 302 params->service_worker_version_id) < kMaxSameProcessFailureCount;
299 instance_->context_->process_manager()->AllocateWorkerProcess( 303 instance_->context_->process_manager()->AllocateWorkerProcess(
300 instance_->embedded_worker_id_, scope, script_url, 304 instance_->embedded_worker_id_, scope, script_url,
301 can_use_existing_process, 305 can_use_existing_process,
302 base::Bind(&StartTask::OnProcessAllocated, weak_factory_.GetWeakPtr(), 306 base::Bind(&StartTask::OnProcessAllocated, weak_factory_.GetWeakPtr(),
303 base::Passed(&params))); 307 base::Passed(&params)));
304 } 308 }
305 309
(...skipping 10 matching lines...) Expand all
316 320
317 private: 321 private:
318 void OnProcessAllocated(std::unique_ptr<EmbeddedWorkerStartParams> params, 322 void OnProcessAllocated(std::unique_ptr<EmbeddedWorkerStartParams> params,
319 ServiceWorkerStatusCode status, 323 ServiceWorkerStatusCode status,
320 int process_id, 324 int process_id,
321 bool is_new_process, 325 bool is_new_process,
322 const EmbeddedWorkerSettings& settings) { 326 const EmbeddedWorkerSettings& settings) {
323 DCHECK_CURRENTLY_ON(BrowserThread::IO); 327 DCHECK_CURRENTLY_ON(BrowserThread::IO);
324 328
325 if (status != SERVICE_WORKER_OK) { 329 if (status != SERVICE_WORKER_OK) {
326 TRACE_EVENT_ASYNC_STEP_PAST1( 330 TRACE_EVENT_NESTABLE_ASYNC_END1("ServiceWorker", "ALLOCATING_PROCESS",
327 "ServiceWorker", "EmbeddedWorkerInstance::Start", this, 331 instance_, "Error",
328 "OnProcessAllocated", "Error", ServiceWorkerStatusToString(status)); 332 ServiceWorkerStatusToString(status));
329 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, process_id); 333 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, process_id);
330 StatusCallback callback = start_callback_; 334 StatusCallback callback = start_callback_;
331 start_callback_.Reset(); 335 start_callback_.Reset();
332 instance_->OnStartFailed(callback, status); 336 instance_->OnStartFailed(callback, status);
333 // |this| may be destroyed. 337 // |this| may be destroyed.
334 return; 338 return;
335 } 339 }
336 340
337 TRACE_EVENT_ASYNC_STEP_PAST1( 341 TRACE_EVENT_NESTABLE_ASYNC_END1("ServiceWorker", "ALLOCATING_PROCESS",
338 "ServiceWorker", "EmbeddedWorkerInstance::Start", this, 342 instance_, "Is New Process",
339 "OnProcessAllocated", "Is New Process", is_new_process); 343 is_new_process);
340 if (is_installed_) 344 if (is_installed_)
341 ServiceWorkerMetrics::RecordProcessCreated(is_new_process); 345 ServiceWorkerMetrics::RecordProcessCreated(is_new_process);
342 346
343 ServiceWorkerMetrics::StartSituation start_situation = 347 ServiceWorkerMetrics::StartSituation start_situation =
344 ServiceWorkerMetrics::StartSituation::UNKNOWN; 348 ServiceWorkerMetrics::StartSituation::UNKNOWN;
345 if (started_during_browser_startup_) 349 if (started_during_browser_startup_)
346 start_situation = ServiceWorkerMetrics::StartSituation::DURING_STARTUP; 350 start_situation = ServiceWorkerMetrics::StartSituation::DURING_STARTUP;
347 else if (is_new_process) 351 else if (is_new_process)
348 start_situation = ServiceWorkerMetrics::StartSituation::NEW_PROCESS; 352 start_situation = ServiceWorkerMetrics::StartSituation::NEW_PROCESS;
349 else 353 else
350 start_situation = ServiceWorkerMetrics::StartSituation::EXISTING_PROCESS; 354 start_situation = ServiceWorkerMetrics::StartSituation::EXISTING_PROCESS;
351 355
352 // Notify the instance that a process is allocated. 356 // Notify the instance that a process is allocated.
353 state_ = ProcessAllocationState::ALLOCATED; 357 state_ = ProcessAllocationState::ALLOCATED;
354 instance_->OnProcessAllocated( 358 instance_->OnProcessAllocated(
355 base::MakeUnique<WorkerProcessHandle>(instance_->context_, 359 base::MakeUnique<WorkerProcessHandle>(instance_->context_,
356 instance_->embedded_worker_id(), 360 instance_->embedded_worker_id(),
357 process_id, is_new_process), 361 process_id, is_new_process),
358 start_situation); 362 start_situation);
359 363
360 // TODO(bengr): Support changes to this setting while the worker 364 // TODO(bengr): Support changes to this setting while the worker
361 // is running. 365 // is running.
362 params->settings.data_saver_enabled = settings.data_saver_enabled; 366 params->settings.data_saver_enabled = settings.data_saver_enabled;
363 367
368 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker",
369 "REGISTERING_TO_DEVTOOLS", instance_);
364 // Register the instance to DevToolsManager on UI thread. 370 // Register the instance to DevToolsManager on UI thread.
365 const int64_t service_worker_version_id = params->service_worker_version_id; 371 const int64_t service_worker_version_id = params->service_worker_version_id;
366 const GURL& scope = params->scope; 372 const GURL& scope = params->scope;
367 GURL script_url(params->script_url); 373 GURL script_url(params->script_url);
368 BrowserThread::PostTask( 374 BrowserThread::PostTask(
369 BrowserThread::UI, FROM_HERE, 375 BrowserThread::UI, FROM_HERE,
370 base::Bind(&SetupOnUI, process_id, instance_->context_.get(), 376 base::Bind(&SetupOnUI, process_id, instance_->context_.get(),
371 instance_->context_, service_worker_version_id, script_url, 377 instance_->context_, service_worker_version_id, script_url,
372 scope, is_installed_, base::Passed(&request_), 378 scope, is_installed_, base::Passed(&request_),
373 base::Bind(&StartTask::OnSetupOnUICompleted, 379 base::Bind(&StartTask::OnSetupOnUICompleted,
374 weak_factory_.GetWeakPtr(), base::Passed(&params), 380 weak_factory_.GetWeakPtr(), base::Passed(&params),
375 is_new_process))); 381 is_new_process)));
376 } 382 }
377 383
378 void OnSetupOnUICompleted( 384 void OnSetupOnUICompleted(
379 std::unique_ptr<EmbeddedWorkerStartParams> params, 385 std::unique_ptr<EmbeddedWorkerStartParams> params,
380 bool is_new_process, 386 bool is_new_process,
381 std::unique_ptr<EmbeddedWorkerInstance::DevToolsProxy> devtools_proxy, 387 std::unique_ptr<EmbeddedWorkerInstance::DevToolsProxy> devtools_proxy,
382 bool wait_for_debugger) { 388 bool wait_for_debugger) {
383 DCHECK_CURRENTLY_ON(BrowserThread::IO); 389 DCHECK_CURRENTLY_ON(BrowserThread::IO);
384 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker",
385 "EmbeddedWorkerInstance::Start", this,
386 "OnSetupOnUICompleted");
387
388 params->worker_devtools_agent_route_id = devtools_proxy->agent_route_id(); 390 params->worker_devtools_agent_route_id = devtools_proxy->agent_route_id();
389 params->wait_for_debugger = wait_for_debugger; 391 params->wait_for_debugger = wait_for_debugger;
390 392
391 // Notify the instance that it is registered to the devtools manager. 393 // Notify the instance that it is registered to the devtools manager.
392 instance_->OnRegisteredToDevToolsManager( 394 instance_->OnRegisteredToDevToolsManager(
393 is_new_process, std::move(devtools_proxy), wait_for_debugger); 395 is_new_process, std::move(devtools_proxy), wait_for_debugger);
396 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "REGISTERING_TO_DEVTOOLS",
397 instance_);
394 398
395 ServiceWorkerStatusCode status = 399 ServiceWorkerStatusCode status =
396 instance_->SendStartWorker(std::move(params)); 400 instance_->SendStartWorker(std::move(params));
397 if (status != SERVICE_WORKER_OK) { 401 if (status != SERVICE_WORKER_OK) {
398 StatusCallback callback = start_callback_; 402 StatusCallback callback = start_callback_;
399 start_callback_.Reset(); 403 start_callback_.Reset();
400 instance_->OnStartFailed(callback, status); 404 instance_->OnStartFailed(callback, status);
401 // |this| may be destroyed. 405 // |this| may be destroyed.
402 } 406 }
403 } 407 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 return SERVICE_WORKER_ERROR_ABORT; 591 return SERVICE_WORKER_ERROR_ABORT;
588 592
589 DCHECK(!instance_host_binding_.is_bound()); 593 DCHECK(!instance_host_binding_.is_bound());
590 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo host_ptr_info; 594 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo host_ptr_info;
591 instance_host_binding_.Bind(&host_ptr_info); 595 instance_host_binding_.Bind(&host_ptr_info);
592 596
593 DCHECK(pending_dispatcher_request_.is_pending()); 597 DCHECK(pending_dispatcher_request_.is_pending());
594 client_->StartWorker(*params, std::move(pending_dispatcher_request_), 598 client_->StartWorker(*params, std::move(pending_dispatcher_request_),
595 std::move(host_ptr_info)); 599 std::move(host_ptr_info));
596 registry_->BindWorkerToProcess(process_id(), embedded_worker_id()); 600 registry_->BindWorkerToProcess(process_id(), embedded_worker_id());
597 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start",
598 this, "SendStartWorker");
599 OnStartWorkerMessageSent(); 601 OnStartWorkerMessageSent();
602 // Once the start worker message is received, renderer side will prepare a
603 // shadow page for getting worker script.
604 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "PREPARING_SCRIPT_LOAD",
605 this);
600 return SERVICE_WORKER_OK; 606 return SERVICE_WORKER_OK;
601 } 607 }
602 608
603 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() { 609 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() {
604 if (!step_time_.is_null()) { 610 if (!step_time_.is_null()) {
605 base::TimeDelta duration = UpdateStepTime(); 611 base::TimeDelta duration = UpdateStepTime();
606 if (inflight_start_task_->is_installed()) { 612 if (inflight_start_task_->is_installed()) {
607 ServiceWorkerMetrics::RecordTimeToSendStartWorker(duration, 613 ServiceWorkerMetrics::RecordTimeToSendStartWorker(duration,
608 start_situation_); 614 start_situation_);
609 } 615 }
610 } 616 }
611 617
612 starting_phase_ = SENT_START_WORKER; 618 starting_phase_ = SENT_START_WORKER;
613 for (auto& observer : listener_list_) 619 for (auto& observer : listener_list_)
614 observer.OnStartWorkerMessageSent(); 620 observer.OnStartWorkerMessageSent();
615 } 621 }
616 622
617 void EmbeddedWorkerInstance::OnReadyForInspection() { 623 void EmbeddedWorkerInstance::OnReadyForInspection() {
618 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnReadyForInspection");
619 if (devtools_proxy_) 624 if (devtools_proxy_)
620 devtools_proxy_->NotifyWorkerReadyForInspection(); 625 devtools_proxy_->NotifyWorkerReadyForInspection();
621 } 626 }
622 627
623 void EmbeddedWorkerInstance::OnScriptReadStarted() { 628 void EmbeddedWorkerInstance::OnScriptReadStarted() {
629 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "SCRIPT_READING_CACHE",
630 this);
624 starting_phase_ = SCRIPT_READ_STARTED; 631 starting_phase_ = SCRIPT_READ_STARTED;
625 } 632 }
626 633
627 void EmbeddedWorkerInstance::OnScriptReadFinished() { 634 void EmbeddedWorkerInstance::OnScriptReadFinished() {
635 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "SCRIPT_READING_CACHE",
636 this);
628 starting_phase_ = SCRIPT_READ_FINISHED; 637 starting_phase_ = SCRIPT_READ_FINISHED;
629 } 638 }
630 639
631 void EmbeddedWorkerInstance::OnScriptLoaded() { 640 void EmbeddedWorkerInstance::OnScriptLoaded() {
632 using LoadSource = ServiceWorkerMetrics::LoadSource; 641 using LoadSource = ServiceWorkerMetrics::LoadSource;
633 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptLoaded");
634 642
635 if (!inflight_start_task_) 643 if (!inflight_start_task_)
636 return; 644 return;
637 LoadSource source; 645 LoadSource source;
638 if (network_accessed_for_script_) { 646 if (network_accessed_for_script_) {
639 DCHECK(!inflight_start_task_->is_installed()); 647 DCHECK(!inflight_start_task_->is_installed());
640 source = LoadSource::NETWORK; 648 source = LoadSource::NETWORK;
641 } else if (inflight_start_task_->is_installed()) { 649 } else if (inflight_start_task_->is_installed()) {
642 source = LoadSource::SERVICE_WORKER_STORAGE; 650 source = LoadSource::SERVICE_WORKER_STORAGE;
643 } else { 651 } else {
644 source = LoadSource::HTTP_CACHE; 652 source = LoadSource::HTTP_CACHE;
645 } 653 }
646 TRACE_EVENT_ASYNC_STEP_PAST1( 654
647 "ServiceWorker", "EmbeddedWorkerInstance::Start", 655 // starting_phase_ may be SCRIPT_READ_FINISHED in case of reading from cache.
648 inflight_start_task_.get(), "OnScriptLoaded", "Source", 656 if (starting_phase_ == SCRIPT_DOWNLOADING) {
657 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "SCRIPT_DOWNLOADING",
658 this);
659 }
660 TRACE_EVENT_NESTABLE_ASYNC_END1(
661 "ServiceWorker", "SCRIPT_LOADING", this, "Source",
649 ServiceWorkerMetrics::LoadSourceToString(source)); 662 ServiceWorkerMetrics::LoadSourceToString(source));
650 663
651 if (!step_time_.is_null()) { 664 if (!step_time_.is_null()) {
652 base::TimeDelta duration = UpdateStepTime(); 665 base::TimeDelta duration = UpdateStepTime();
653 ServiceWorkerMetrics::RecordTimeToLoad(duration, source, start_situation_); 666 ServiceWorkerMetrics::RecordTimeToLoad(duration, source, start_situation_);
654 } 667 }
655 668
669 // Renderer side has started to launch the worker thread.
670 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "LAUNCHING_WORKER_THREAD",
671 this);
656 starting_phase_ = SCRIPT_LOADED; 672 starting_phase_ = SCRIPT_LOADED;
657 for (auto& observer : listener_list_) 673 for (auto& observer : listener_list_)
658 observer.OnScriptLoaded(); 674 observer.OnScriptLoaded();
659 // |this| may be destroyed by the callback. 675 // |this| may be destroyed by the callback.
660 } 676 }
661 677
662 void EmbeddedWorkerInstance::OnURLJobCreatedForMainScript() { 678 void EmbeddedWorkerInstance::OnURLJobCreatedForMainScript() {
679 // Indicates that the shadow page has been created in renderer side and starts
680 // to get the worker script.
681 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "PREPARING_SCRIPT_LOAD",
682 this);
683 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "SCRIPT_LOADING", this);
663 if (!inflight_start_task_) 684 if (!inflight_start_task_)
664 return; 685 return;
665 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", 686
666 inflight_start_task_.get(), "OnURLJobCreated");
667 if (!step_time_.is_null()) { 687 if (!step_time_.is_null()) {
668 base::TimeDelta duration = UpdateStepTime(); 688 base::TimeDelta duration = UpdateStepTime();
669 if (inflight_start_task_->is_installed()) 689 if (inflight_start_task_->is_installed())
670 ServiceWorkerMetrics::RecordTimeToURLJob(duration, start_situation_); 690 ServiceWorkerMetrics::RecordTimeToURLJob(duration, start_situation_);
671 } 691 }
672 } 692 }
673 693
674 void EmbeddedWorkerInstance::OnWorkerVersionInstalled() { 694 void EmbeddedWorkerInstance::OnWorkerVersionInstalled() {
675 if (devtools_proxy_) 695 if (devtools_proxy_)
676 devtools_proxy_->NotifyWorkerVersionInstalled(); 696 devtools_proxy_->NotifyWorkerVersionInstalled();
677 } 697 }
678 698
679 void EmbeddedWorkerInstance::OnWorkerVersionDoomed() { 699 void EmbeddedWorkerInstance::OnWorkerVersionDoomed() {
680 if (devtools_proxy_) 700 if (devtools_proxy_)
681 devtools_proxy_->NotifyWorkerVersionDoomed(); 701 devtools_proxy_->NotifyWorkerVersionDoomed();
682 } 702 }
683 703
684 void EmbeddedWorkerInstance::OnThreadStarted(int thread_id, int provider_id) { 704 void EmbeddedWorkerInstance::OnThreadStarted(int thread_id, int provider_id) {
685 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnThreadStarted"); 705 if (!context_ || !inflight_start_task_)
686 if (!context_)
687 return; 706 return;
688 707
689 ServiceWorkerProviderHost* provider_host = 708 ServiceWorkerProviderHost* provider_host =
690 context_->GetProviderHost(process_id(), provider_id); 709 context_->GetProviderHost(process_id(), provider_id);
691 if (!provider_host) { 710 if (!provider_host) {
692 bad_message::ReceivedBadMessage( 711 bad_message::ReceivedBadMessage(
693 process_id(), bad_message::SWDH_WORKER_SCRIPT_LOAD_NO_HOST); 712 process_id(), bad_message::SWDH_WORKER_SCRIPT_LOAD_NO_HOST);
694 return; 713 return;
695 } 714 }
696 715
697 provider_host->SetReadyToSendMessagesToWorker(thread_id); 716 provider_host->SetReadyToSendMessagesToWorker(thread_id);
698 717
699 if (!inflight_start_task_) 718 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "LAUNCHING_WORKER_THREAD",
700 return; 719 this);
701 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", 720 // Renderer side has started to evaluate the loaded worker script.
702 inflight_start_task_.get(), "OnThreadStarted"); 721 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "EVALUATING_SCRIPT", this);
703
704 starting_phase_ = THREAD_STARTED; 722 starting_phase_ = THREAD_STARTED;
705 if (!step_time_.is_null()) { 723 if (!step_time_.is_null()) {
706 base::TimeDelta duration = UpdateStepTime(); 724 base::TimeDelta duration = UpdateStepTime();
707 if (inflight_start_task_->is_installed()) 725 if (inflight_start_task_->is_installed())
708 ServiceWorkerMetrics::RecordTimeToStartThread(duration, start_situation_); 726 ServiceWorkerMetrics::RecordTimeToStartThread(duration, start_situation_);
709 } 727 }
710 728
711 thread_id_ = thread_id; 729 thread_id_ = thread_id;
712 for (auto& observer : listener_list_) 730 for (auto& observer : listener_list_)
713 observer.OnThreadStarted(); 731 observer.OnThreadStarted();
714 } 732 }
715 733
716 void EmbeddedWorkerInstance::OnScriptLoadFailed() { 734 void EmbeddedWorkerInstance::OnScriptLoadFailed() {
717 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptLoadFailed");
718 if (!inflight_start_task_) 735 if (!inflight_start_task_)
719 return; 736 return;
720 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", 737
721 inflight_start_task_.get(), 738 // starting_phase_ may be SCRIPT_READ_FINISHED in case of reading from cache.
722 "OnScriptLoadFailed"); 739 if (starting_phase_ == SCRIPT_DOWNLOADING) {
740 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "SCRIPT_DOWNLOADING",
741 this);
742 }
743 TRACE_EVENT_NESTABLE_ASYNC_END1("ServiceWorker", "SCRIPT_LOADING", this,
744 "Error", "Script load failed.");
745
723 for (auto& observer : listener_list_) 746 for (auto& observer : listener_list_)
724 observer.OnScriptLoadFailed(); 747 observer.OnScriptLoadFailed();
725 } 748 }
726 749
727 void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) { 750 void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) {
728 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptEvaluated");
729 if (!inflight_start_task_) 751 if (!inflight_start_task_)
730 return; 752 return;
753
731 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status_); 754 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status_);
732 755
733 TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start", 756 // Renderer side has completed evaluating the loaded worker script.
734 inflight_start_task_.get(), "OnScriptEvaluated", 757 TRACE_EVENT_NESTABLE_ASYNC_END1("ServiceWorker", "EVALUATING_SCRIPT", this,
735 "Success", success); 758 "Success", success);
736 starting_phase_ = SCRIPT_EVALUATED; 759 starting_phase_ = SCRIPT_EVALUATED;
737 if (!step_time_.is_null()) { 760 if (!step_time_.is_null()) {
738 base::TimeDelta duration = UpdateStepTime(); 761 base::TimeDelta duration = UpdateStepTime();
739 if (success && inflight_start_task_->is_installed()) 762 if (success && inflight_start_task_->is_installed())
740 ServiceWorkerMetrics::RecordTimeToEvaluateScript(duration, 763 ServiceWorkerMetrics::RecordTimeToEvaluateScript(duration,
741 start_situation_); 764 start_situation_);
742 } 765 }
743 766
767 if (success) {
768 // Renderer side has started the final preparations to complete the start
769 // process.
770 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker",
771 "WAITING_FOR_START_COMPLETE", this);
772 }
744 base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr(); 773 base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr();
745 StartTask::RunStartCallback( 774 StartTask::RunStartCallback(
746 inflight_start_task_.get(), 775 inflight_start_task_.get(),
747 success ? SERVICE_WORKER_OK 776 success ? SERVICE_WORKER_OK
748 : SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED); 777 : SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED);
749 // |this| may be destroyed by the callback. 778 // |this| may be destroyed by the callback.
750 } 779 }
751 780
752 void EmbeddedWorkerInstance::OnStarted() { 781 void EmbeddedWorkerInstance::OnStarted() {
753 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnStarted");
754 if (!registry_->OnWorkerStarted(process_id(), embedded_worker_id_)) 782 if (!registry_->OnWorkerStarted(process_id(), embedded_worker_id_))
755 return; 783 return;
756 // Stop is requested before OnStarted is sent back from the worker. 784 // Stop is requested before OnStarted is sent back from the worker.
757 if (status_ == EmbeddedWorkerStatus::STOPPING) 785 if (status_ == EmbeddedWorkerStatus::STOPPING)
758 return; 786 return;
787
788 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "WAITING_FOR_START_COMPLETE",
789 this);
759 DCHECK(status_ == EmbeddedWorkerStatus::STARTING); 790 DCHECK(status_ == EmbeddedWorkerStatus::STARTING);
760 status_ = EmbeddedWorkerStatus::RUNNING; 791 status_ = EmbeddedWorkerStatus::RUNNING;
761 inflight_start_task_.reset(); 792 inflight_start_task_.reset();
762 for (auto& observer : listener_list_) 793 for (auto& observer : listener_list_)
763 observer.OnStarted(); 794 observer.OnStarted();
764 } 795 }
765 796
766 void EmbeddedWorkerInstance::OnStopped() { 797 void EmbeddedWorkerInstance::OnStopped() {
767 registry_->OnWorkerStopped(process_id(), embedded_worker_id_); 798 registry_->OnWorkerStopped(process_id(), embedded_worker_id_);
768 799
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 listener_list_.RemoveObserver(listener); 875 listener_list_.RemoveObserver(listener);
845 } 876 }
846 877
847 void EmbeddedWorkerInstance::SetDevToolsAttached(bool attached) { 878 void EmbeddedWorkerInstance::SetDevToolsAttached(bool attached) {
848 devtools_attached_ = attached; 879 devtools_attached_ = attached;
849 if (attached) 880 if (attached)
850 registry_->OnDevToolsAttached(embedded_worker_id_); 881 registry_->OnDevToolsAttached(embedded_worker_id_);
851 } 882 }
852 883
853 void EmbeddedWorkerInstance::OnNetworkAccessedForScriptLoad() { 884 void EmbeddedWorkerInstance::OnNetworkAccessedForScriptLoad() {
885 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "SCRIPT_DOWNLOADING",
886 this);
854 starting_phase_ = SCRIPT_DOWNLOADING; 887 starting_phase_ = SCRIPT_DOWNLOADING;
855 network_accessed_for_script_ = true; 888 network_accessed_for_script_ = true;
856 } 889 }
857 890
858 void EmbeddedWorkerInstance::ReleaseProcess() { 891 void EmbeddedWorkerInstance::ReleaseProcess() {
859 // Abort an inflight start task. 892 // Abort an inflight start task.
860 inflight_start_task_.reset(); 893 inflight_start_task_.reset();
861 894
862 client_.reset(); 895 client_.reset();
863 instance_host_binding_.Close(); 896 instance_host_binding_.Close();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 case SCRIPT_READ_FINISHED: 972 case SCRIPT_READ_FINISHED:
940 return "Script read finished"; 973 return "Script read finished";
941 case STARTING_PHASE_MAX_VALUE: 974 case STARTING_PHASE_MAX_VALUE:
942 NOTREACHED(); 975 NOTREACHED();
943 } 976 }
944 NOTREACHED() << phase; 977 NOTREACHED() << phase;
945 return std::string(); 978 return std::string();
946 } 979 }
947 980
948 } // namespace content 981 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698