| 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 "OnSetupOnUICompleted"); | 368 "OnSetupOnUICompleted"); |
| 369 | 369 |
| 370 // Notify the instance that it is registered to the devtools manager. | 370 // Notify the instance that it is registered to the devtools manager. |
| 371 instance_->OnRegisteredToDevToolsManager( | 371 instance_->OnRegisteredToDevToolsManager( |
| 372 is_new_process, worker_devtools_agent_route_id, wait_for_debugger); | 372 is_new_process, worker_devtools_agent_route_id, wait_for_debugger); |
| 373 | 373 |
| 374 params->worker_devtools_agent_route_id = worker_devtools_agent_route_id; | 374 params->worker_devtools_agent_route_id = worker_devtools_agent_route_id; |
| 375 params->wait_for_debugger = wait_for_debugger; | 375 params->wait_for_debugger = wait_for_debugger; |
| 376 | 376 |
| 377 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) | 377 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) |
| 378 instance_->SendMojoStartWorker(std::move(params)); | 378 SendMojoStartWorker(std::move(params)); |
| 379 else | 379 else |
| 380 SendStartWorker(std::move(params)); | 380 SendStartWorker(std::move(params)); |
| 381 } | 381 } |
| 382 | 382 |
| 383 void SendStartWorker(std::unique_ptr<EmbeddedWorkerStartParams> params) { | 383 void SendStartWorker(std::unique_ptr<EmbeddedWorkerStartParams> params) { |
| 384 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 384 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 385 ServiceWorkerStatusCode status = instance_->registry_->SendStartWorker( | 385 ServiceWorkerStatusCode status = instance_->registry_->SendStartWorker( |
| 386 std::move(params), instance_->process_id()); | 386 std::move(params), instance_->process_id()); |
| 387 TRACE_EVENT_ASYNC_STEP_PAST1( | 387 TRACE_EVENT_ASYNC_STEP_PAST1( |
| 388 "ServiceWorker", "EmbeddedWorkerInstance::Start", this, | 388 "ServiceWorker", "EmbeddedWorkerInstance::Start", this, |
| 389 "SendStartWorker", "Status", ServiceWorkerStatusToString(status)); | 389 "SendStartWorker", "Status", ServiceWorkerStatusToString(status)); |
| 390 if (status != SERVICE_WORKER_OK) { | 390 if (status != SERVICE_WORKER_OK) { |
| 391 StatusCallback callback = start_callback_; | 391 StatusCallback callback = start_callback_; |
| 392 start_callback_.Reset(); | 392 start_callback_.Reset(); |
| 393 instance_->OnStartFailed(callback, status); | 393 instance_->OnStartFailed(callback, status); |
| 394 // |this| may be destroyed. | 394 // |this| may be destroyed. |
| 395 return; | 395 return; |
| 396 } | 396 } |
| 397 instance_->OnStartWorkerMessageSent(); | 397 instance_->OnStartWorkerMessageSent(); |
| 398 | 398 |
| 399 // |start_callback_| will be called via RunStartCallback() when the script | 399 // |start_callback_| will be called via RunStartCallback() when the script |
| 400 // is evaluated. | 400 // is evaluated. |
| 401 } | 401 } |
| 402 | 402 |
| 403 void SendMojoStartWorker(std::unique_ptr<EmbeddedWorkerStartParams> params) { |
| 404 ServiceWorkerStatusCode status = |
| 405 instance_->SendMojoStartWorker(std::move(params)); |
| 406 if (status != SERVICE_WORKER_OK) { |
| 407 StatusCallback callback = start_callback_; |
| 408 start_callback_.Reset(); |
| 409 instance_->OnStartFailed(callback, status); |
| 410 // |this| may be destroyed. |
| 411 return; |
| 412 } |
| 413 } |
| 414 |
| 403 // |instance_| must outlive |this|. | 415 // |instance_| must outlive |this|. |
| 404 EmbeddedWorkerInstance* instance_; | 416 EmbeddedWorkerInstance* instance_; |
| 405 | 417 |
| 406 // Ownership is transferred by base::Passed() to a task after process | 418 // Ownership is transferred by base::Passed() to a task after process |
| 407 // allocation. | 419 // allocation. |
| 408 mojom::EmbeddedWorkerInstanceClientRequest request_; | 420 mojom::EmbeddedWorkerInstanceClientRequest request_; |
| 409 | 421 |
| 410 StatusCallback start_callback_; | 422 StatusCallback start_callback_; |
| 411 ProcessAllocationState state_; | 423 ProcessAllocationState state_; |
| 412 | 424 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 } | 606 } |
| 595 if (wait_for_debugger) { | 607 if (wait_for_debugger) { |
| 596 // We don't measure the start time when wait_for_debugger flag is set. So | 608 // We don't measure the start time when wait_for_debugger flag is set. So |
| 597 // we set the NULL time here. | 609 // we set the NULL time here. |
| 598 step_time_ = base::TimeTicks(); | 610 step_time_ = base::TimeTicks(); |
| 599 } | 611 } |
| 600 for (auto& observer : listener_list_) | 612 for (auto& observer : listener_list_) |
| 601 observer.OnRegisteredToDevToolsManager(); | 613 observer.OnRegisteredToDevToolsManager(); |
| 602 } | 614 } |
| 603 | 615 |
| 604 void EmbeddedWorkerInstance::SendMojoStartWorker( | 616 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMojoStartWorker( |
| 605 std::unique_ptr<EmbeddedWorkerStartParams> params) { | 617 std::unique_ptr<EmbeddedWorkerStartParams> params) { |
| 618 if (!context_) |
| 619 return SERVICE_WORKER_ERROR_ABORT; |
| 606 client_->StartWorker(*params); | 620 client_->StartWorker(*params); |
| 607 registry_->BindWorkerToProcess(process_id(), embedded_worker_id()); | 621 registry_->BindWorkerToProcess(process_id(), embedded_worker_id()); |
| 608 TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start", | 622 TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start", |
| 609 this, "SendStartWorker", "Status", "mojo"); | 623 this, "SendStartWorker", "Status", "mojo"); |
| 610 OnStartWorkerMessageSent(); | 624 OnStartWorkerMessageSent(); |
| 625 return SERVICE_WORKER_OK; |
| 611 } | 626 } |
| 612 | 627 |
| 613 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() { | 628 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() { |
| 614 if (!step_time_.is_null()) { | 629 if (!step_time_.is_null()) { |
| 615 base::TimeDelta duration = UpdateStepTime(); | 630 base::TimeDelta duration = UpdateStepTime(); |
| 616 if (inflight_start_task_->is_installed()) { | 631 if (inflight_start_task_->is_installed()) { |
| 617 ServiceWorkerMetrics::RecordTimeToSendStartWorker(duration, | 632 ServiceWorkerMetrics::RecordTimeToSendStartWorker(duration, |
| 618 start_situation_); | 633 start_situation_); |
| 619 } | 634 } |
| 620 } | 635 } |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 case SCRIPT_READ_FINISHED: | 953 case SCRIPT_READ_FINISHED: |
| 939 return "Script read finished"; | 954 return "Script read finished"; |
| 940 case STARTING_PHASE_MAX_VALUE: | 955 case STARTING_PHASE_MAX_VALUE: |
| 941 NOTREACHED(); | 956 NOTREACHED(); |
| 942 } | 957 } |
| 943 NOTREACHED() << phase; | 958 NOTREACHED() << phase; |
| 944 return std::string(); | 959 return std::string(); |
| 945 } | 960 } |
| 946 | 961 |
| 947 } // namespace content | 962 } // namespace content |
| OLD | NEW |