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 <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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 | 233 |
234 StartTask(EmbeddedWorkerInstance* instance, | 234 StartTask(EmbeddedWorkerInstance* instance, |
235 const GURL& script_url, | 235 const GURL& script_url, |
236 mojom::EmbeddedWorkerInstanceClientRequest request) | 236 mojom::EmbeddedWorkerInstanceClientRequest request) |
237 : instance_(instance), | 237 : instance_(instance), |
238 request_(std::move(request)), | 238 request_(std::move(request)), |
239 state_(ProcessAllocationState::NOT_ALLOCATED), | 239 state_(ProcessAllocationState::NOT_ALLOCATED), |
240 is_installed_(false), | 240 is_installed_(false), |
241 started_during_browser_startup_(false), | 241 started_during_browser_startup_(false), |
242 weak_factory_(this) { | 242 weak_factory_(this) { |
243 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "EmbeddedWorkerInstance::Start", | 243 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1("ServiceWorker", |
leonhsl(Using Gerrit)
2017/04/19 03:43:43
I think using StartTask ctor/dtor to control "Embe
shimazu
2017/04/19 07:54:35
Thanks for explanation! It makes sense.
| |
244 this, "Script", script_url.spec()); | 244 "EmbeddedWorkerInstance::Start", |
245 instance_, "Script", script_url.spec()); | |
245 } | 246 } |
246 | 247 |
247 ~StartTask() { | 248 ~StartTask() { |
248 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 249 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
249 TRACE_EVENT_ASYNC_END0("ServiceWorker", "EmbeddedWorkerInstance::Start", | 250 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", |
250 this); | 251 "EmbeddedWorkerInstance::Start", instance_); |
251 | 252 |
252 if (!instance_->context_) | 253 if (!instance_->context_) |
253 return; | 254 return; |
254 | 255 |
255 switch (state_) { | 256 switch (state_) { |
256 case ProcessAllocationState::NOT_ALLOCATED: | 257 case ProcessAllocationState::NOT_ALLOCATED: |
257 // Not necessary to release a process. | 258 // Not necessary to release a process. |
258 break; | 259 break; |
259 case ProcessAllocationState::ALLOCATING: | 260 case ProcessAllocationState::ALLOCATING: |
260 // Abort half-baked process allocation on the UI thread. | 261 // Abort half-baked process allocation on the UI thread. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 | 314 |
314 private: | 315 private: |
315 void OnProcessAllocated(std::unique_ptr<EmbeddedWorkerStartParams> params, | 316 void OnProcessAllocated(std::unique_ptr<EmbeddedWorkerStartParams> params, |
316 ServiceWorkerStatusCode status, | 317 ServiceWorkerStatusCode status, |
317 int process_id, | 318 int process_id, |
318 bool is_new_process, | 319 bool is_new_process, |
319 const EmbeddedWorkerSettings& settings) { | 320 const EmbeddedWorkerSettings& settings) { |
320 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 321 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
321 | 322 |
322 if (status != SERVICE_WORKER_OK) { | 323 if (status != SERVICE_WORKER_OK) { |
323 TRACE_EVENT_ASYNC_STEP_PAST1( | 324 TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( |
324 "ServiceWorker", "EmbeddedWorkerInstance::Start", this, | 325 "ServiceWorker", "EmbeddedWorkerInstance::Start", instance_, "Step", |
shimazu
2017/04/19 07:54:35
Each INSTANT can have different name as long as yo
leonhsl(Using Gerrit)
2017/04/19 10:40:23
I'm not quite sure about this, instead of NESTABLE
shimazu
2017/04/20 04:51:46
Yes, exactly. According to the CL which introduces
leonhsl(Using Gerrit)
2017/04/21 02:46:29
Done.
| |
325 "OnProcessAllocated", "Error", ServiceWorkerStatusToString(status)); | 326 "OnProcessAllocated", "Error", ServiceWorkerStatusToString(status)); |
326 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, process_id); | 327 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, process_id); |
327 StatusCallback callback = start_callback_; | 328 StatusCallback callback = start_callback_; |
328 start_callback_.Reset(); | 329 start_callback_.Reset(); |
329 instance_->OnStartFailed(callback, status); | 330 instance_->OnStartFailed(callback, status); |
330 // |this| may be destroyed. | 331 // |this| may be destroyed. |
331 return; | 332 return; |
332 } | 333 } |
333 | 334 |
334 TRACE_EVENT_ASYNC_STEP_PAST1( | 335 TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( |
335 "ServiceWorker", "EmbeddedWorkerInstance::Start", this, | 336 "ServiceWorker", "EmbeddedWorkerInstance::Start", instance_, "Step", |
336 "OnProcessAllocated", "Is New Process", is_new_process); | 337 "OnProcessAllocated", "Is New Process", is_new_process); |
337 if (is_installed_) | 338 if (is_installed_) |
338 ServiceWorkerMetrics::RecordProcessCreated(is_new_process); | 339 ServiceWorkerMetrics::RecordProcessCreated(is_new_process); |
339 | 340 |
340 ServiceWorkerMetrics::StartSituation start_situation = | 341 ServiceWorkerMetrics::StartSituation start_situation = |
341 ServiceWorkerMetrics::StartSituation::UNKNOWN; | 342 ServiceWorkerMetrics::StartSituation::UNKNOWN; |
342 if (started_during_browser_startup_) | 343 if (started_during_browser_startup_) |
343 start_situation = ServiceWorkerMetrics::StartSituation::DURING_STARTUP; | 344 start_situation = ServiceWorkerMetrics::StartSituation::DURING_STARTUP; |
344 else if (is_new_process) | 345 else if (is_new_process) |
345 start_situation = ServiceWorkerMetrics::StartSituation::NEW_PROCESS; | 346 start_situation = ServiceWorkerMetrics::StartSituation::NEW_PROCESS; |
(...skipping 24 matching lines...) Expand all Loading... | |
370 base::Bind(&StartTask::OnSetupOnUICompleted, | 371 base::Bind(&StartTask::OnSetupOnUICompleted, |
371 weak_factory_.GetWeakPtr(), base::Passed(¶ms), | 372 weak_factory_.GetWeakPtr(), base::Passed(¶ms), |
372 is_new_process))); | 373 is_new_process))); |
373 } | 374 } |
374 | 375 |
375 void OnSetupOnUICompleted(std::unique_ptr<EmbeddedWorkerStartParams> params, | 376 void OnSetupOnUICompleted(std::unique_ptr<EmbeddedWorkerStartParams> params, |
376 bool is_new_process, | 377 bool is_new_process, |
377 int worker_devtools_agent_route_id, | 378 int worker_devtools_agent_route_id, |
378 bool wait_for_debugger) { | 379 bool wait_for_debugger) { |
379 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 380 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
380 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", | 381 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1( |
381 "EmbeddedWorkerInstance::Start", this, | 382 "ServiceWorker", "EmbeddedWorkerInstance::Start", instance_, "Step", |
382 "OnSetupOnUICompleted"); | 383 "OnSetupOnUICompleted"); |
383 | 384 |
384 // Notify the instance that it is registered to the devtools manager. | 385 // Notify the instance that it is registered to the devtools manager. |
385 instance_->OnRegisteredToDevToolsManager( | 386 instance_->OnRegisteredToDevToolsManager( |
386 is_new_process, worker_devtools_agent_route_id, wait_for_debugger); | 387 is_new_process, worker_devtools_agent_route_id, wait_for_debugger); |
387 | 388 |
388 params->worker_devtools_agent_route_id = worker_devtools_agent_route_id; | 389 params->worker_devtools_agent_route_id = worker_devtools_agent_route_id; |
389 params->wait_for_debugger = wait_for_debugger; | 390 params->wait_for_debugger = wait_for_debugger; |
390 | 391 |
391 ServiceWorkerStatusCode status = | 392 ServiceWorkerStatusCode status = |
392 instance_->SendStartWorker(std::move(params)); | 393 instance_->SendStartWorker(std::move(params)); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 return SERVICE_WORKER_ERROR_ABORT; | 585 return SERVICE_WORKER_ERROR_ABORT; |
585 | 586 |
586 DCHECK(!instance_host_binding_.is_bound()); | 587 DCHECK(!instance_host_binding_.is_bound()); |
587 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo host_ptr_info; | 588 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo host_ptr_info; |
588 instance_host_binding_.Bind(&host_ptr_info); | 589 instance_host_binding_.Bind(&host_ptr_info); |
589 | 590 |
590 DCHECK(pending_dispatcher_request_.is_pending()); | 591 DCHECK(pending_dispatcher_request_.is_pending()); |
591 client_->StartWorker(*params, std::move(pending_dispatcher_request_), | 592 client_->StartWorker(*params, std::move(pending_dispatcher_request_), |
592 std::move(host_ptr_info)); | 593 std::move(host_ptr_info)); |
593 registry_->BindWorkerToProcess(process_id(), embedded_worker_id()); | 594 registry_->BindWorkerToProcess(process_id(), embedded_worker_id()); |
594 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", | 595 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("ServiceWorker", |
595 this, "SendStartWorker"); | 596 "EmbeddedWorkerInstance::Start", this, |
597 "Step", "SendStartWorker"); | |
596 OnStartWorkerMessageSent(); | 598 OnStartWorkerMessageSent(); |
597 return SERVICE_WORKER_OK; | 599 return SERVICE_WORKER_OK; |
598 } | 600 } |
599 | 601 |
600 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() { | 602 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() { |
601 if (!step_time_.is_null()) { | 603 if (!step_time_.is_null()) { |
602 base::TimeDelta duration = UpdateStepTime(); | 604 base::TimeDelta duration = UpdateStepTime(); |
603 if (inflight_start_task_->is_installed()) { | 605 if (inflight_start_task_->is_installed()) { |
604 ServiceWorkerMetrics::RecordTimeToSendStartWorker(duration, | 606 ServiceWorkerMetrics::RecordTimeToSendStartWorker(duration, |
605 start_situation_); | 607 start_situation_); |
606 } | 608 } |
607 } | 609 } |
608 | 610 |
609 starting_phase_ = SENT_START_WORKER; | 611 starting_phase_ = SENT_START_WORKER; |
610 for (auto& observer : listener_list_) | 612 for (auto& observer : listener_list_) |
611 observer.OnStartWorkerMessageSent(); | 613 observer.OnStartWorkerMessageSent(); |
612 } | 614 } |
613 | 615 |
614 void EmbeddedWorkerInstance::OnReadyForInspection() { | 616 void EmbeddedWorkerInstance::OnReadyForInspection() { |
615 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnReadyForInspection"); | 617 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("ServiceWorker", |
618 "EmbeddedWorkerInstance::Start", this, | |
619 "Step", "OnReadyForInspection"); | |
616 if (devtools_proxy_) | 620 if (devtools_proxy_) |
617 devtools_proxy_->NotifyWorkerReadyForInspection(); | 621 devtools_proxy_->NotifyWorkerReadyForInspection(); |
618 } | 622 } |
619 | 623 |
620 void EmbeddedWorkerInstance::OnScriptReadStarted() { | 624 void EmbeddedWorkerInstance::OnScriptReadStarted() { |
621 starting_phase_ = SCRIPT_READ_STARTED; | 625 starting_phase_ = SCRIPT_READ_STARTED; |
622 } | 626 } |
623 | 627 |
624 void EmbeddedWorkerInstance::OnScriptReadFinished() { | 628 void EmbeddedWorkerInstance::OnScriptReadFinished() { |
625 starting_phase_ = SCRIPT_READ_FINISHED; | 629 starting_phase_ = SCRIPT_READ_FINISHED; |
626 } | 630 } |
627 | 631 |
628 void EmbeddedWorkerInstance::OnScriptLoaded() { | 632 void EmbeddedWorkerInstance::OnScriptLoaded() { |
629 using LoadSource = ServiceWorkerMetrics::LoadSource; | 633 using LoadSource = ServiceWorkerMetrics::LoadSource; |
630 | 634 |
631 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptLoaded"); | |
632 | |
633 if (!inflight_start_task_) | 635 if (!inflight_start_task_) |
634 return; | 636 return; |
635 LoadSource source; | 637 LoadSource source; |
636 if (network_accessed_for_script_) { | 638 if (network_accessed_for_script_) { |
637 DCHECK(!inflight_start_task_->is_installed()); | 639 DCHECK(!inflight_start_task_->is_installed()); |
638 source = LoadSource::NETWORK; | 640 source = LoadSource::NETWORK; |
639 } else if (inflight_start_task_->is_installed()) { | 641 } else if (inflight_start_task_->is_installed()) { |
640 source = LoadSource::SERVICE_WORKER_STORAGE; | 642 source = LoadSource::SERVICE_WORKER_STORAGE; |
641 } else { | 643 } else { |
642 source = LoadSource::HTTP_CACHE; | 644 source = LoadSource::HTTP_CACHE; |
643 } | 645 } |
644 TRACE_EVENT_ASYNC_STEP_PAST1( | 646 TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( |
645 "ServiceWorker", "EmbeddedWorkerInstance::Start", | 647 "ServiceWorker", "EmbeddedWorkerInstance::Start", this, "Step", |
646 inflight_start_task_.get(), "OnScriptLoaded", "Source", | 648 "OnScriptLoaded", "Source", |
647 ServiceWorkerMetrics::LoadSourceToString(source)); | 649 ServiceWorkerMetrics::LoadSourceToString(source)); |
648 | 650 |
649 if (!step_time_.is_null()) { | 651 if (!step_time_.is_null()) { |
650 base::TimeDelta duration = UpdateStepTime(); | 652 base::TimeDelta duration = UpdateStepTime(); |
651 ServiceWorkerMetrics::RecordTimeToLoad(duration, source, start_situation_); | 653 ServiceWorkerMetrics::RecordTimeToLoad(duration, source, start_situation_); |
652 } | 654 } |
653 | 655 |
654 starting_phase_ = SCRIPT_LOADED; | 656 starting_phase_ = SCRIPT_LOADED; |
655 for (auto& observer : listener_list_) | 657 for (auto& observer : listener_list_) |
656 observer.OnScriptLoaded(); | 658 observer.OnScriptLoaded(); |
657 // |this| may be destroyed by the callback. | 659 // |this| may be destroyed by the callback. |
658 } | 660 } |
659 | 661 |
660 void EmbeddedWorkerInstance::OnURLJobCreatedForMainScript() { | 662 void EmbeddedWorkerInstance::OnURLJobCreatedForMainScript() { |
661 if (!inflight_start_task_) | 663 if (!inflight_start_task_) |
662 return; | 664 return; |
663 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", | 665 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("ServiceWorker", |
664 inflight_start_task_.get(), "OnURLJobCreated"); | 666 "EmbeddedWorkerInstance::Start", this, |
667 "Step", "OnURLJobCreated"); | |
668 | |
665 if (!step_time_.is_null()) { | 669 if (!step_time_.is_null()) { |
666 base::TimeDelta duration = UpdateStepTime(); | 670 base::TimeDelta duration = UpdateStepTime(); |
667 if (inflight_start_task_->is_installed()) | 671 if (inflight_start_task_->is_installed()) |
668 ServiceWorkerMetrics::RecordTimeToURLJob(duration, start_situation_); | 672 ServiceWorkerMetrics::RecordTimeToURLJob(duration, start_situation_); |
669 } | 673 } |
670 } | 674 } |
671 | 675 |
672 void EmbeddedWorkerInstance::OnWorkerVersionInstalled() { | 676 void EmbeddedWorkerInstance::OnWorkerVersionInstalled() { |
673 if (devtools_proxy_) | 677 if (devtools_proxy_) |
674 devtools_proxy_->NotifyWorkerVersionInstalled(); | 678 devtools_proxy_->NotifyWorkerVersionInstalled(); |
675 } | 679 } |
676 | 680 |
677 void EmbeddedWorkerInstance::OnWorkerVersionDoomed() { | 681 void EmbeddedWorkerInstance::OnWorkerVersionDoomed() { |
678 if (devtools_proxy_) | 682 if (devtools_proxy_) |
679 devtools_proxy_->NotifyWorkerVersionDoomed(); | 683 devtools_proxy_->NotifyWorkerVersionDoomed(); |
680 } | 684 } |
681 | 685 |
682 void EmbeddedWorkerInstance::OnThreadStarted(int thread_id, int provider_id) { | 686 void EmbeddedWorkerInstance::OnThreadStarted(int thread_id, int provider_id) { |
683 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnThreadStarted"); | 687 if (!inflight_start_task_) |
688 return; | |
689 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("ServiceWorker", | |
690 "EmbeddedWorkerInstance::Start", this, | |
691 "Step", "OnThreadStarted"); | |
692 | |
684 if (!context_) | 693 if (!context_) |
685 return; | 694 return; |
686 | 695 |
687 ServiceWorkerProviderHost* provider_host = | 696 ServiceWorkerProviderHost* provider_host = |
688 context_->GetProviderHost(process_id(), provider_id); | 697 context_->GetProviderHost(process_id(), provider_id); |
689 if (!provider_host) { | 698 if (!provider_host) { |
690 bad_message::ReceivedBadMessage( | 699 bad_message::ReceivedBadMessage( |
691 process_id(), bad_message::SWDH_WORKER_SCRIPT_LOAD_NO_HOST); | 700 process_id(), bad_message::SWDH_WORKER_SCRIPT_LOAD_NO_HOST); |
692 return; | 701 return; |
693 } | 702 } |
694 | 703 |
695 provider_host->SetReadyToSendMessagesToWorker(thread_id); | 704 provider_host->SetReadyToSendMessagesToWorker(thread_id); |
696 | 705 |
697 if (!inflight_start_task_) | |
698 return; | |
699 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", | |
700 inflight_start_task_.get(), "OnThreadStarted"); | |
701 | |
702 starting_phase_ = THREAD_STARTED; | 706 starting_phase_ = THREAD_STARTED; |
703 if (!step_time_.is_null()) { | 707 if (!step_time_.is_null()) { |
704 base::TimeDelta duration = UpdateStepTime(); | 708 base::TimeDelta duration = UpdateStepTime(); |
705 if (inflight_start_task_->is_installed()) | 709 if (inflight_start_task_->is_installed()) |
706 ServiceWorkerMetrics::RecordTimeToStartThread(duration, start_situation_); | 710 ServiceWorkerMetrics::RecordTimeToStartThread(duration, start_situation_); |
707 } | 711 } |
708 | 712 |
709 thread_id_ = thread_id; | 713 thread_id_ = thread_id; |
710 for (auto& observer : listener_list_) | 714 for (auto& observer : listener_list_) |
711 observer.OnThreadStarted(); | 715 observer.OnThreadStarted(); |
712 } | 716 } |
713 | 717 |
714 void EmbeddedWorkerInstance::OnScriptLoadFailed() { | 718 void EmbeddedWorkerInstance::OnScriptLoadFailed() { |
715 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptLoadFailed"); | |
716 if (!inflight_start_task_) | 719 if (!inflight_start_task_) |
717 return; | 720 return; |
718 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", | 721 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("ServiceWorker", |
719 inflight_start_task_.get(), | 722 "EmbeddedWorkerInstance::Start", this, |
720 "OnScriptLoadFailed"); | 723 "Step", "OnScriptLoadFailed"); |
724 | |
721 for (auto& observer : listener_list_) | 725 for (auto& observer : listener_list_) |
722 observer.OnScriptLoadFailed(); | 726 observer.OnScriptLoadFailed(); |
723 } | 727 } |
724 | 728 |
725 void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) { | 729 void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) { |
726 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptEvaluated"); | |
727 if (!inflight_start_task_) | 730 if (!inflight_start_task_) |
728 return; | 731 return; |
732 TRACE_EVENT_NESTABLE_ASYNC_INSTANT2( | |
733 "ServiceWorker", "EmbeddedWorkerInstance::Start", this, "Step", | |
734 "OnScriptEvaluated", "Success", success); | |
735 | |
729 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status_); | 736 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status_); |
730 | 737 |
731 TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start", | |
732 inflight_start_task_.get(), "OnScriptEvaluated", | |
733 "Success", success); | |
734 starting_phase_ = SCRIPT_EVALUATED; | 738 starting_phase_ = SCRIPT_EVALUATED; |
735 if (!step_time_.is_null()) { | 739 if (!step_time_.is_null()) { |
736 base::TimeDelta duration = UpdateStepTime(); | 740 base::TimeDelta duration = UpdateStepTime(); |
737 if (success && inflight_start_task_->is_installed()) | 741 if (success && inflight_start_task_->is_installed()) |
738 ServiceWorkerMetrics::RecordTimeToEvaluateScript(duration, | 742 ServiceWorkerMetrics::RecordTimeToEvaluateScript(duration, |
739 start_situation_); | 743 start_situation_); |
740 } | 744 } |
741 | 745 |
742 base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr(); | 746 base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr(); |
743 StartTask::RunStartCallback( | 747 StartTask::RunStartCallback( |
744 inflight_start_task_.get(), | 748 inflight_start_task_.get(), |
745 success ? SERVICE_WORKER_OK | 749 success ? SERVICE_WORKER_OK |
746 : SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED); | 750 : SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED); |
747 // |this| may be destroyed by the callback. | 751 // |this| may be destroyed by the callback. |
748 } | 752 } |
749 | 753 |
750 void EmbeddedWorkerInstance::OnStarted() { | 754 void EmbeddedWorkerInstance::OnStarted() { |
751 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnStarted"); | |
752 if (!registry_->OnWorkerStarted(process_id(), embedded_worker_id_)) | 755 if (!registry_->OnWorkerStarted(process_id(), embedded_worker_id_)) |
753 return; | 756 return; |
754 // Stop is requested before OnStarted is sent back from the worker. | 757 // Stop is requested before OnStarted is sent back from the worker. |
755 if (status_ == EmbeddedWorkerStatus::STOPPING) | 758 if (status_ == EmbeddedWorkerStatus::STOPPING) |
756 return; | 759 return; |
760 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("ServiceWorker", | |
761 "EmbeddedWorkerInstance::Start", this, | |
762 "Step", "OnStarted"); | |
763 | |
757 DCHECK(status_ == EmbeddedWorkerStatus::STARTING); | 764 DCHECK(status_ == EmbeddedWorkerStatus::STARTING); |
758 status_ = EmbeddedWorkerStatus::RUNNING; | 765 status_ = EmbeddedWorkerStatus::RUNNING; |
759 inflight_start_task_.reset(); | 766 inflight_start_task_.reset(); |
760 for (auto& observer : listener_list_) | 767 for (auto& observer : listener_list_) |
761 observer.OnStarted(); | 768 observer.OnStarted(); |
762 } | 769 } |
763 | 770 |
764 void EmbeddedWorkerInstance::OnStopped() { | 771 void EmbeddedWorkerInstance::OnStopped() { |
765 registry_->OnWorkerStopped(process_id(), embedded_worker_id_); | 772 registry_->OnWorkerStopped(process_id(), embedded_worker_id_); |
766 | 773 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
937 case SCRIPT_READ_FINISHED: | 944 case SCRIPT_READ_FINISHED: |
938 return "Script read finished"; | 945 return "Script read finished"; |
939 case STARTING_PHASE_MAX_VALUE: | 946 case STARTING_PHASE_MAX_VALUE: |
940 NOTREACHED(); | 947 NOTREACHED(); |
941 } | 948 } |
942 NOTREACHED() << phase; | 949 NOTREACHED() << phase; |
943 return std::string(); | 950 return std::string(); |
944 } | 951 } |
945 | 952 |
946 } // namespace content | 953 } // namespace content |
OLD | NEW |