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

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: Rebase only Created 3 years, 8 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 318
317 private: 319 private:
318 void OnProcessAllocated(std::unique_ptr<EmbeddedWorkerStartParams> params, 320 void OnProcessAllocated(std::unique_ptr<EmbeddedWorkerStartParams> params,
319 ServiceWorkerStatusCode status, 321 ServiceWorkerStatusCode status,
320 int process_id, 322 int process_id,
321 bool is_new_process, 323 bool is_new_process,
322 const EmbeddedWorkerSettings& settings) { 324 const EmbeddedWorkerSettings& settings) {
323 DCHECK_CURRENTLY_ON(BrowserThread::IO); 325 DCHECK_CURRENTLY_ON(BrowserThread::IO);
324 326
325 if (status != SERVICE_WORKER_OK) { 327 if (status != SERVICE_WORKER_OK) {
326 TRACE_EVENT_ASYNC_STEP_PAST1( 328 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1("ServiceWorker", "OnProcessAllocated",
327 "ServiceWorker", "EmbeddedWorkerInstance::Start", this, 329 instance_, "Error",
328 "OnProcessAllocated", "Error", ServiceWorkerStatusToString(status)); 330 ServiceWorkerStatusToString(status));
331 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "OnProcessAllocated",
332 instance_);
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_BEGIN1("ServiceWorker", "OnProcessAllocated",
338 "ServiceWorker", "EmbeddedWorkerInstance::Start", this, 342 instance_, "Is New Process",
339 "OnProcessAllocated", "Is New Process", is_new_process); 343 is_new_process);
shimazu 2017/04/21 03:05:41 My explanation was bad, sorry. We want to track t
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
(...skipping 16 matching lines...) Expand all
366 const GURL& scope = params->scope; 370 const GURL& scope = params->scope;
367 GURL script_url(params->script_url); 371 GURL script_url(params->script_url);
368 BrowserThread::PostTask( 372 BrowserThread::PostTask(
369 BrowserThread::UI, FROM_HERE, 373 BrowserThread::UI, FROM_HERE,
370 base::Bind(&SetupOnUI, process_id, instance_->context_.get(), 374 base::Bind(&SetupOnUI, process_id, instance_->context_.get(),
371 instance_->context_, service_worker_version_id, script_url, 375 instance_->context_, service_worker_version_id, script_url,
372 scope, is_installed_, base::Passed(&request_), 376 scope, is_installed_, base::Passed(&request_),
373 base::Bind(&StartTask::OnSetupOnUICompleted, 377 base::Bind(&StartTask::OnSetupOnUICompleted,
374 weak_factory_.GetWeakPtr(), base::Passed(&params), 378 weak_factory_.GetWeakPtr(), base::Passed(&params),
375 is_new_process))); 379 is_new_process)));
380 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "OnProcessAllocated",
381 instance_);
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", 390 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "OnSetupOnUICompleted",
385 "EmbeddedWorkerInstance::Start", this, 391 instance_);
386 "OnSetupOnUICompleted");
387 392
388 params->worker_devtools_agent_route_id = devtools_proxy->agent_route_id(); 393 params->worker_devtools_agent_route_id = devtools_proxy->agent_route_id();
389 params->wait_for_debugger = wait_for_debugger; 394 params->wait_for_debugger = wait_for_debugger;
390 395
391 // Notify the instance that it is registered to the devtools manager. 396 // Notify the instance that it is registered to the devtools manager.
392 instance_->OnRegisteredToDevToolsManager( 397 instance_->OnRegisteredToDevToolsManager(
393 is_new_process, std::move(devtools_proxy), wait_for_debugger); 398 is_new_process, std::move(devtools_proxy), wait_for_debugger);
394 399
395 ServiceWorkerStatusCode status = 400 ServiceWorkerStatusCode status =
396 instance_->SendStartWorker(std::move(params)); 401 instance_->SendStartWorker(std::move(params));
402 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "OnSetupOnUICompleted",
403 instance_);
397 if (status != SERVICE_WORKER_OK) { 404 if (status != SERVICE_WORKER_OK) {
398 StatusCallback callback = start_callback_; 405 StatusCallback callback = start_callback_;
399 start_callback_.Reset(); 406 start_callback_.Reset();
400 instance_->OnStartFailed(callback, status); 407 instance_->OnStartFailed(callback, status);
401 // |this| may be destroyed. 408 // |this| may be destroyed.
402 } 409 }
403 } 410 }
404 411
405 // |instance_| must outlive |this|. 412 // |instance_| must outlive |this|.
406 EmbeddedWorkerInstance* instance_; 413 EmbeddedWorkerInstance* instance_;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 return SERVICE_WORKER_ERROR_ABORT; 594 return SERVICE_WORKER_ERROR_ABORT;
588 595
589 DCHECK(!instance_host_binding_.is_bound()); 596 DCHECK(!instance_host_binding_.is_bound());
590 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo host_ptr_info; 597 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo host_ptr_info;
591 instance_host_binding_.Bind(&host_ptr_info); 598 instance_host_binding_.Bind(&host_ptr_info);
592 599
593 DCHECK(pending_dispatcher_request_.is_pending()); 600 DCHECK(pending_dispatcher_request_.is_pending());
594 client_->StartWorker(*params, std::move(pending_dispatcher_request_), 601 client_->StartWorker(*params, std::move(pending_dispatcher_request_),
595 std::move(host_ptr_info)); 602 std::move(host_ptr_info));
596 registry_->BindWorkerToProcess(process_id(), embedded_worker_id()); 603 registry_->BindWorkerToProcess(process_id(), embedded_worker_id());
597 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", 604 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "SendStartWorker", this);
598 this, "SendStartWorker");
599 OnStartWorkerMessageSent(); 605 OnStartWorkerMessageSent();
606 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "SendStartWorker", this);
600 return SERVICE_WORKER_OK; 607 return SERVICE_WORKER_OK;
601 } 608 }
602 609
603 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() { 610 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() {
604 if (!step_time_.is_null()) { 611 if (!step_time_.is_null()) {
605 base::TimeDelta duration = UpdateStepTime(); 612 base::TimeDelta duration = UpdateStepTime();
606 if (inflight_start_task_->is_installed()) { 613 if (inflight_start_task_->is_installed()) {
607 ServiceWorkerMetrics::RecordTimeToSendStartWorker(duration, 614 ServiceWorkerMetrics::RecordTimeToSendStartWorker(duration,
608 start_situation_); 615 start_situation_);
609 } 616 }
610 } 617 }
611 618
612 starting_phase_ = SENT_START_WORKER; 619 starting_phase_ = SENT_START_WORKER;
613 for (auto& observer : listener_list_) 620 for (auto& observer : listener_list_)
614 observer.OnStartWorkerMessageSent(); 621 observer.OnStartWorkerMessageSent();
615 } 622 }
616 623
617 void EmbeddedWorkerInstance::OnReadyForInspection() { 624 void EmbeddedWorkerInstance::OnReadyForInspection() {
618 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnReadyForInspection"); 625 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "OnReadyForInspection",
626 this);
619 if (devtools_proxy_) 627 if (devtools_proxy_)
620 devtools_proxy_->NotifyWorkerReadyForInspection(); 628 devtools_proxy_->NotifyWorkerReadyForInspection();
629 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "OnReadyForInspection",
630 this);
621 } 631 }
622 632
623 void EmbeddedWorkerInstance::OnScriptReadStarted() { 633 void EmbeddedWorkerInstance::OnScriptReadStarted() {
624 starting_phase_ = SCRIPT_READ_STARTED; 634 starting_phase_ = SCRIPT_READ_STARTED;
625 } 635 }
626 636
627 void EmbeddedWorkerInstance::OnScriptReadFinished() { 637 void EmbeddedWorkerInstance::OnScriptReadFinished() {
628 starting_phase_ = SCRIPT_READ_FINISHED; 638 starting_phase_ = SCRIPT_READ_FINISHED;
629 } 639 }
630 640
631 void EmbeddedWorkerInstance::OnScriptLoaded() { 641 void EmbeddedWorkerInstance::OnScriptLoaded() {
632 using LoadSource = ServiceWorkerMetrics::LoadSource; 642 using LoadSource = ServiceWorkerMetrics::LoadSource;
633 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptLoaded");
634 643
635 if (!inflight_start_task_) 644 if (!inflight_start_task_)
636 return; 645 return;
637 LoadSource source; 646 LoadSource source;
638 if (network_accessed_for_script_) { 647 if (network_accessed_for_script_) {
639 DCHECK(!inflight_start_task_->is_installed()); 648 DCHECK(!inflight_start_task_->is_installed());
640 source = LoadSource::NETWORK; 649 source = LoadSource::NETWORK;
641 } else if (inflight_start_task_->is_installed()) { 650 } else if (inflight_start_task_->is_installed()) {
642 source = LoadSource::SERVICE_WORKER_STORAGE; 651 source = LoadSource::SERVICE_WORKER_STORAGE;
643 } else { 652 } else {
644 source = LoadSource::HTTP_CACHE; 653 source = LoadSource::HTTP_CACHE;
645 } 654 }
646 TRACE_EVENT_ASYNC_STEP_PAST1( 655 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
647 "ServiceWorker", "EmbeddedWorkerInstance::Start", 656 "ServiceWorker", "OnScriptLoaded", this, "Source",
648 inflight_start_task_.get(), "OnScriptLoaded", "Source",
649 ServiceWorkerMetrics::LoadSourceToString(source)); 657 ServiceWorkerMetrics::LoadSourceToString(source));
658 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "OnScriptLoaded", this);
650 659
651 if (!step_time_.is_null()) { 660 if (!step_time_.is_null()) {
652 base::TimeDelta duration = UpdateStepTime(); 661 base::TimeDelta duration = UpdateStepTime();
653 ServiceWorkerMetrics::RecordTimeToLoad(duration, source, start_situation_); 662 ServiceWorkerMetrics::RecordTimeToLoad(duration, source, start_situation_);
654 } 663 }
655 664
656 starting_phase_ = SCRIPT_LOADED; 665 starting_phase_ = SCRIPT_LOADED;
657 for (auto& observer : listener_list_) 666 for (auto& observer : listener_list_)
658 observer.OnScriptLoaded(); 667 observer.OnScriptLoaded();
659 // |this| may be destroyed by the callback. 668 // |this| may be destroyed by the callback.
660 } 669 }
661 670
662 void EmbeddedWorkerInstance::OnURLJobCreatedForMainScript() { 671 void EmbeddedWorkerInstance::OnURLJobCreatedForMainScript() {
663 if (!inflight_start_task_) 672 if (!inflight_start_task_)
664 return; 673 return;
665 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", 674 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "OnURLJobCreated", this);
666 inflight_start_task_.get(), "OnURLJobCreated"); 675
667 if (!step_time_.is_null()) { 676 if (!step_time_.is_null()) {
668 base::TimeDelta duration = UpdateStepTime(); 677 base::TimeDelta duration = UpdateStepTime();
669 if (inflight_start_task_->is_installed()) 678 if (inflight_start_task_->is_installed())
670 ServiceWorkerMetrics::RecordTimeToURLJob(duration, start_situation_); 679 ServiceWorkerMetrics::RecordTimeToURLJob(duration, start_situation_);
671 } 680 }
681 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "OnURLJobCreated", this);
672 } 682 }
673 683
674 void EmbeddedWorkerInstance::OnWorkerVersionInstalled() { 684 void EmbeddedWorkerInstance::OnWorkerVersionInstalled() {
675 if (devtools_proxy_) 685 if (devtools_proxy_)
676 devtools_proxy_->NotifyWorkerVersionInstalled(); 686 devtools_proxy_->NotifyWorkerVersionInstalled();
677 } 687 }
678 688
679 void EmbeddedWorkerInstance::OnWorkerVersionDoomed() { 689 void EmbeddedWorkerInstance::OnWorkerVersionDoomed() {
680 if (devtools_proxy_) 690 if (devtools_proxy_)
681 devtools_proxy_->NotifyWorkerVersionDoomed(); 691 devtools_proxy_->NotifyWorkerVersionDoomed();
682 } 692 }
683 693
684 void EmbeddedWorkerInstance::OnThreadStarted(int thread_id, int provider_id) { 694 void EmbeddedWorkerInstance::OnThreadStarted(int thread_id, int provider_id) {
685 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnThreadStarted"); 695 if (!inflight_start_task_)
696 return;
686 if (!context_) 697 if (!context_)
687 return; 698 return;
688 699
689 ServiceWorkerProviderHost* provider_host = 700 ServiceWorkerProviderHost* provider_host =
690 context_->GetProviderHost(process_id(), provider_id); 701 context_->GetProviderHost(process_id(), provider_id);
691 if (!provider_host) { 702 if (!provider_host) {
692 bad_message::ReceivedBadMessage( 703 bad_message::ReceivedBadMessage(
693 process_id(), bad_message::SWDH_WORKER_SCRIPT_LOAD_NO_HOST); 704 process_id(), bad_message::SWDH_WORKER_SCRIPT_LOAD_NO_HOST);
694 return; 705 return;
695 } 706 }
696 707
708 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "OnThreadStarted", this);
709
697 provider_host->SetReadyToSendMessagesToWorker(thread_id); 710 provider_host->SetReadyToSendMessagesToWorker(thread_id);
698 711
699 if (!inflight_start_task_)
700 return;
701 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start",
702 inflight_start_task_.get(), "OnThreadStarted");
703
704 starting_phase_ = THREAD_STARTED; 712 starting_phase_ = THREAD_STARTED;
705 if (!step_time_.is_null()) { 713 if (!step_time_.is_null()) {
706 base::TimeDelta duration = UpdateStepTime(); 714 base::TimeDelta duration = UpdateStepTime();
707 if (inflight_start_task_->is_installed()) 715 if (inflight_start_task_->is_installed())
708 ServiceWorkerMetrics::RecordTimeToStartThread(duration, start_situation_); 716 ServiceWorkerMetrics::RecordTimeToStartThread(duration, start_situation_);
709 } 717 }
710 718
711 thread_id_ = thread_id; 719 thread_id_ = thread_id;
712 for (auto& observer : listener_list_) 720 for (auto& observer : listener_list_)
713 observer.OnThreadStarted(); 721 observer.OnThreadStarted();
722 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "OnThreadStarted", this);
714 } 723 }
715 724
716 void EmbeddedWorkerInstance::OnScriptLoadFailed() { 725 void EmbeddedWorkerInstance::OnScriptLoadFailed() {
717 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptLoadFailed");
718 if (!inflight_start_task_) 726 if (!inflight_start_task_)
719 return; 727 return;
720 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", 728 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "OnScriptLoadFailed",
721 inflight_start_task_.get(), 729 this);
722 "OnScriptLoadFailed"); 730 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "OnScriptLoadFailed", this);
731
723 for (auto& observer : listener_list_) 732 for (auto& observer : listener_list_)
724 observer.OnScriptLoadFailed(); 733 observer.OnScriptLoadFailed();
725 } 734 }
726 735
727 void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) { 736 void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) {
728 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptEvaluated");
729 if (!inflight_start_task_) 737 if (!inflight_start_task_)
730 return; 738 return;
739 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1("ServiceWorker", "OnScriptEvaluated", this,
740 "Success", success);
741 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "OnScriptEvaluated", this);
742
731 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status_); 743 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status_);
732 744
733 TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start",
734 inflight_start_task_.get(), "OnScriptEvaluated",
735 "Success", success);
736 starting_phase_ = SCRIPT_EVALUATED; 745 starting_phase_ = SCRIPT_EVALUATED;
737 if (!step_time_.is_null()) { 746 if (!step_time_.is_null()) {
738 base::TimeDelta duration = UpdateStepTime(); 747 base::TimeDelta duration = UpdateStepTime();
739 if (success && inflight_start_task_->is_installed()) 748 if (success && inflight_start_task_->is_installed())
740 ServiceWorkerMetrics::RecordTimeToEvaluateScript(duration, 749 ServiceWorkerMetrics::RecordTimeToEvaluateScript(duration,
741 start_situation_); 750 start_situation_);
742 } 751 }
743 752
744 base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr(); 753 base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr();
745 StartTask::RunStartCallback( 754 StartTask::RunStartCallback(
746 inflight_start_task_.get(), 755 inflight_start_task_.get(),
747 success ? SERVICE_WORKER_OK 756 success ? SERVICE_WORKER_OK
748 : SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED); 757 : SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED);
749 // |this| may be destroyed by the callback. 758 // |this| may be destroyed by the callback.
750 } 759 }
751 760
752 void EmbeddedWorkerInstance::OnStarted() { 761 void EmbeddedWorkerInstance::OnStarted() {
753 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnStarted");
754 if (!registry_->OnWorkerStarted(process_id(), embedded_worker_id_)) 762 if (!registry_->OnWorkerStarted(process_id(), embedded_worker_id_))
755 return; 763 return;
756 // Stop is requested before OnStarted is sent back from the worker. 764 // Stop is requested before OnStarted is sent back from the worker.
757 if (status_ == EmbeddedWorkerStatus::STOPPING) 765 if (status_ == EmbeddedWorkerStatus::STOPPING)
758 return; 766 return;
767 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "OnStarted", this);
768
759 DCHECK(status_ == EmbeddedWorkerStatus::STARTING); 769 DCHECK(status_ == EmbeddedWorkerStatus::STARTING);
760 status_ = EmbeddedWorkerStatus::RUNNING; 770 status_ = EmbeddedWorkerStatus::RUNNING;
771 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "OnStarted", this);
761 inflight_start_task_.reset(); 772 inflight_start_task_.reset();
762 for (auto& observer : listener_list_) 773 for (auto& observer : listener_list_)
763 observer.OnStarted(); 774 observer.OnStarted();
764 } 775 }
765 776
766 void EmbeddedWorkerInstance::OnStopped() { 777 void EmbeddedWorkerInstance::OnStopped() {
767 registry_->OnWorkerStopped(process_id(), embedded_worker_id_); 778 registry_->OnWorkerStopped(process_id(), embedded_worker_id_);
768 779
769 EmbeddedWorkerStatus old_status = status_; 780 EmbeddedWorkerStatus old_status = status_;
770 ReleaseProcess(); 781 ReleaseProcess();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 case SCRIPT_READ_FINISHED: 950 case SCRIPT_READ_FINISHED:
940 return "Script read finished"; 951 return "Script read finished";
941 case STARTING_PHASE_MAX_VALUE: 952 case STARTING_PHASE_MAX_VALUE:
942 NOTREACHED(); 953 NOTREACHED();
943 } 954 }
944 NOTREACHED() << phase; 955 NOTREACHED() << phase;
945 return std::string(); 956 return std::string();
946 } 957 }
947 958
948 } // namespace content 959 } // 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