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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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(¶ms))); | 307 base::Passed(¶ms))); |
304 } | 308 } |
305 | 309 |
(...skipping 10 matching lines...) Expand all Loading... | |
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(¶ms), | 380 weak_factory_.GetWeakPtr(), base::Passed(¶ms), |
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 Loading... | |
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 recieved, 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 // starting_phase_ may be SCRIPT_READ_FINISHED in case of reading from cache. |
shimazu
2017/04/25 01:34:50
nit: an extra space
leonhsl(Using Gerrit)
2017/04/25 02:34:06
Done.
| |
647 "ServiceWorker", "EmbeddedWorkerInstance::Start", | 655 if (starting_phase_ == SCRIPT_DOWNLOADING) { |
648 inflight_start_task_.get(), "OnScriptLoaded", "Source", | 656 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "SCRIPT_DOWNLOADING", |
657 this); | |
658 } | |
659 TRACE_EVENT_NESTABLE_ASYNC_END1( | |
660 "ServiceWorker", "SCRIPT_LOADING", this, "Source", | |
649 ServiceWorkerMetrics::LoadSourceToString(source)); | 661 ServiceWorkerMetrics::LoadSourceToString(source)); |
650 | 662 |
651 if (!step_time_.is_null()) { | 663 if (!step_time_.is_null()) { |
652 base::TimeDelta duration = UpdateStepTime(); | 664 base::TimeDelta duration = UpdateStepTime(); |
653 ServiceWorkerMetrics::RecordTimeToLoad(duration, source, start_situation_); | 665 ServiceWorkerMetrics::RecordTimeToLoad(duration, source, start_situation_); |
654 } | 666 } |
655 | 667 |
668 // Renderer side has started to launch the worker thread. | |
669 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "LAUNCHING_WORKER_THREAD", | |
670 this); | |
656 starting_phase_ = SCRIPT_LOADED; | 671 starting_phase_ = SCRIPT_LOADED; |
657 for (auto& observer : listener_list_) | 672 for (auto& observer : listener_list_) |
658 observer.OnScriptLoaded(); | 673 observer.OnScriptLoaded(); |
659 // |this| may be destroyed by the callback. | 674 // |this| may be destroyed by the callback. |
660 } | 675 } |
661 | 676 |
662 void EmbeddedWorkerInstance::OnURLJobCreatedForMainScript() { | 677 void EmbeddedWorkerInstance::OnURLJobCreatedForMainScript() { |
leonhsl(Using Gerrit)
2017/04/24 08:23:58
I found that this function is always called when t
shimazu
2017/04/25 01:34:50
Yeah, looks good.
| |
678 // Indicates that the shadow page has been created in renderer side and starts | |
679 // to get the worker script. | |
680 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "PREPARING_SCRIPT_LOAD", | |
681 this); | |
682 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "SCRIPT_LOADING", this); | |
663 if (!inflight_start_task_) | 683 if (!inflight_start_task_) |
664 return; | 684 return; |
665 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", | 685 |
666 inflight_start_task_.get(), "OnURLJobCreated"); | |
667 if (!step_time_.is_null()) { | 686 if (!step_time_.is_null()) { |
668 base::TimeDelta duration = UpdateStepTime(); | 687 base::TimeDelta duration = UpdateStepTime(); |
669 if (inflight_start_task_->is_installed()) | 688 if (inflight_start_task_->is_installed()) |
670 ServiceWorkerMetrics::RecordTimeToURLJob(duration, start_situation_); | 689 ServiceWorkerMetrics::RecordTimeToURLJob(duration, start_situation_); |
671 } | 690 } |
672 } | 691 } |
673 | 692 |
674 void EmbeddedWorkerInstance::OnWorkerVersionInstalled() { | 693 void EmbeddedWorkerInstance::OnWorkerVersionInstalled() { |
675 if (devtools_proxy_) | 694 if (devtools_proxy_) |
676 devtools_proxy_->NotifyWorkerVersionInstalled(); | 695 devtools_proxy_->NotifyWorkerVersionInstalled(); |
677 } | 696 } |
678 | 697 |
679 void EmbeddedWorkerInstance::OnWorkerVersionDoomed() { | 698 void EmbeddedWorkerInstance::OnWorkerVersionDoomed() { |
680 if (devtools_proxy_) | 699 if (devtools_proxy_) |
681 devtools_proxy_->NotifyWorkerVersionDoomed(); | 700 devtools_proxy_->NotifyWorkerVersionDoomed(); |
682 } | 701 } |
683 | 702 |
684 void EmbeddedWorkerInstance::OnThreadStarted(int thread_id, int provider_id) { | 703 void EmbeddedWorkerInstance::OnThreadStarted(int thread_id, int provider_id) { |
685 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnThreadStarted"); | 704 if (!inflight_start_task_) |
705 return; | |
686 if (!context_) | 706 if (!context_) |
shimazu
2017/04/25 01:34:50
It's not necessary to separate these two if clause
leonhsl(Using Gerrit)
2017/04/25 02:34:06
Done.
| |
687 return; | 707 return; |
688 | 708 |
689 ServiceWorkerProviderHost* provider_host = | 709 ServiceWorkerProviderHost* provider_host = |
690 context_->GetProviderHost(process_id(), provider_id); | 710 context_->GetProviderHost(process_id(), provider_id); |
691 if (!provider_host) { | 711 if (!provider_host) { |
692 bad_message::ReceivedBadMessage( | 712 bad_message::ReceivedBadMessage( |
693 process_id(), bad_message::SWDH_WORKER_SCRIPT_LOAD_NO_HOST); | 713 process_id(), bad_message::SWDH_WORKER_SCRIPT_LOAD_NO_HOST); |
694 return; | 714 return; |
695 } | 715 } |
696 | 716 |
697 provider_host->SetReadyToSendMessagesToWorker(thread_id); | 717 provider_host->SetReadyToSendMessagesToWorker(thread_id); |
698 | 718 |
699 if (!inflight_start_task_) | 719 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "LAUNCHING_WORKER_THREAD", |
700 return; | 720 this); |
701 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", | 721 // Renderer side has started to evaluate the loaded worker script. |
702 inflight_start_task_.get(), "OnThreadStarted"); | 722 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "EVALUATING_SCRIPT", this); |
703 | |
704 starting_phase_ = THREAD_STARTED; | 723 starting_phase_ = THREAD_STARTED; |
705 if (!step_time_.is_null()) { | 724 if (!step_time_.is_null()) { |
706 base::TimeDelta duration = UpdateStepTime(); | 725 base::TimeDelta duration = UpdateStepTime(); |
707 if (inflight_start_task_->is_installed()) | 726 if (inflight_start_task_->is_installed()) |
708 ServiceWorkerMetrics::RecordTimeToStartThread(duration, start_situation_); | 727 ServiceWorkerMetrics::RecordTimeToStartThread(duration, start_situation_); |
709 } | 728 } |
710 | 729 |
711 thread_id_ = thread_id; | 730 thread_id_ = thread_id; |
712 for (auto& observer : listener_list_) | 731 for (auto& observer : listener_list_) |
713 observer.OnThreadStarted(); | 732 observer.OnThreadStarted(); |
714 } | 733 } |
715 | 734 |
716 void EmbeddedWorkerInstance::OnScriptLoadFailed() { | 735 void EmbeddedWorkerInstance::OnScriptLoadFailed() { |
717 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptLoadFailed"); | |
718 if (!inflight_start_task_) | 736 if (!inflight_start_task_) |
719 return; | 737 return; |
720 TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker", "EmbeddedWorkerInstance::Start", | 738 |
721 inflight_start_task_.get(), | 739 // starting_phase_ may be SCRIPT_READ_FINISHED in case of reading from cache. |
722 "OnScriptLoadFailed"); | 740 if (starting_phase_ == SCRIPT_DOWNLOADING) { |
741 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "SCRIPT_DOWNLOADING", | |
742 this); | |
743 } | |
744 TRACE_EVENT_NESTABLE_ASYNC_END1("ServiceWorker", "SCRIPT_LOADING", this, | |
745 "Error", "Script load failed."); | |
746 | |
723 for (auto& observer : listener_list_) | 747 for (auto& observer : listener_list_) |
724 observer.OnScriptLoadFailed(); | 748 observer.OnScriptLoadFailed(); |
725 } | 749 } |
726 | 750 |
727 void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) { | 751 void EmbeddedWorkerInstance::OnScriptEvaluated(bool success) { |
728 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnScriptEvaluated"); | |
729 if (!inflight_start_task_) | 752 if (!inflight_start_task_) |
730 return; | 753 return; |
754 | |
731 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status_); | 755 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, status_); |
732 | 756 |
733 TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start", | 757 // Renderer side has completed evaluating the loaded worker script. |
734 inflight_start_task_.get(), "OnScriptEvaluated", | 758 TRACE_EVENT_NESTABLE_ASYNC_END1("ServiceWorker", "EVALUATING_SCRIPT", this, |
735 "Success", success); | 759 "Success", success); |
736 starting_phase_ = SCRIPT_EVALUATED; | 760 starting_phase_ = SCRIPT_EVALUATED; |
737 if (!step_time_.is_null()) { | 761 if (!step_time_.is_null()) { |
738 base::TimeDelta duration = UpdateStepTime(); | 762 base::TimeDelta duration = UpdateStepTime(); |
739 if (success && inflight_start_task_->is_installed()) | 763 if (success && inflight_start_task_->is_installed()) |
740 ServiceWorkerMetrics::RecordTimeToEvaluateScript(duration, | 764 ServiceWorkerMetrics::RecordTimeToEvaluateScript(duration, |
741 start_situation_); | 765 start_situation_); |
742 } | 766 } |
743 | 767 |
768 if (success) { | |
769 // Renderer side has started the final preparations to complete the start | |
770 // process. | |
771 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", | |
772 "WAITING_FOR_START_COMPLETE", this); | |
773 } | |
744 base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr(); | 774 base::WeakPtr<EmbeddedWorkerInstance> weak_this = weak_factory_.GetWeakPtr(); |
745 StartTask::RunStartCallback( | 775 StartTask::RunStartCallback( |
746 inflight_start_task_.get(), | 776 inflight_start_task_.get(), |
747 success ? SERVICE_WORKER_OK | 777 success ? SERVICE_WORKER_OK |
748 : SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED); | 778 : SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED); |
749 // |this| may be destroyed by the callback. | 779 // |this| may be destroyed by the callback. |
750 } | 780 } |
751 | 781 |
752 void EmbeddedWorkerInstance::OnStarted() { | 782 void EmbeddedWorkerInstance::OnStarted() { |
753 TRACE_EVENT0("ServiceWorker", "EmbeddedWorkerInstance::OnStarted"); | |
754 if (!registry_->OnWorkerStarted(process_id(), embedded_worker_id_)) | 783 if (!registry_->OnWorkerStarted(process_id(), embedded_worker_id_)) |
755 return; | 784 return; |
756 // Stop is requested before OnStarted is sent back from the worker. | 785 // Stop is requested before OnStarted is sent back from the worker. |
757 if (status_ == EmbeddedWorkerStatus::STOPPING) | 786 if (status_ == EmbeddedWorkerStatus::STOPPING) |
758 return; | 787 return; |
788 | |
789 TRACE_EVENT_NESTABLE_ASYNC_END0("ServiceWorker", "WAITING_FOR_START_COMPLETE", | |
790 this); | |
759 DCHECK(status_ == EmbeddedWorkerStatus::STARTING); | 791 DCHECK(status_ == EmbeddedWorkerStatus::STARTING); |
760 status_ = EmbeddedWorkerStatus::RUNNING; | 792 status_ = EmbeddedWorkerStatus::RUNNING; |
761 inflight_start_task_.reset(); | 793 inflight_start_task_.reset(); |
762 for (auto& observer : listener_list_) | 794 for (auto& observer : listener_list_) |
763 observer.OnStarted(); | 795 observer.OnStarted(); |
764 } | 796 } |
765 | 797 |
766 void EmbeddedWorkerInstance::OnStopped() { | 798 void EmbeddedWorkerInstance::OnStopped() { |
767 registry_->OnWorkerStopped(process_id(), embedded_worker_id_); | 799 registry_->OnWorkerStopped(process_id(), embedded_worker_id_); |
768 | 800 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
844 listener_list_.RemoveObserver(listener); | 876 listener_list_.RemoveObserver(listener); |
845 } | 877 } |
846 | 878 |
847 void EmbeddedWorkerInstance::SetDevToolsAttached(bool attached) { | 879 void EmbeddedWorkerInstance::SetDevToolsAttached(bool attached) { |
848 devtools_attached_ = attached; | 880 devtools_attached_ = attached; |
849 if (attached) | 881 if (attached) |
850 registry_->OnDevToolsAttached(embedded_worker_id_); | 882 registry_->OnDevToolsAttached(embedded_worker_id_); |
851 } | 883 } |
852 | 884 |
853 void EmbeddedWorkerInstance::OnNetworkAccessedForScriptLoad() { | 885 void EmbeddedWorkerInstance::OnNetworkAccessedForScriptLoad() { |
886 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ServiceWorker", "SCRIPT_DOWNLOADING", | |
887 this); | |
854 starting_phase_ = SCRIPT_DOWNLOADING; | 888 starting_phase_ = SCRIPT_DOWNLOADING; |
855 network_accessed_for_script_ = true; | 889 network_accessed_for_script_ = true; |
856 } | 890 } |
857 | 891 |
858 void EmbeddedWorkerInstance::ReleaseProcess() { | 892 void EmbeddedWorkerInstance::ReleaseProcess() { |
859 // Abort an inflight start task. | 893 // Abort an inflight start task. |
860 inflight_start_task_.reset(); | 894 inflight_start_task_.reset(); |
861 | 895 |
862 client_.reset(); | 896 client_.reset(); |
863 instance_host_binding_.Close(); | 897 instance_host_binding_.Close(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
939 case SCRIPT_READ_FINISHED: | 973 case SCRIPT_READ_FINISHED: |
940 return "Script read finished"; | 974 return "Script read finished"; |
941 case STARTING_PHASE_MAX_VALUE: | 975 case STARTING_PHASE_MAX_VALUE: |
942 NOTREACHED(); | 976 NOTREACHED(); |
943 } | 977 } |
944 NOTREACHED() << phase; | 978 NOTREACHED() << phase; |
945 return std::string(); | 979 return std::string(); |
946 } | 980 } |
947 | 981 |
948 } // namespace content | 982 } // namespace content |
OLD | NEW |