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

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

Issue 2429753003: Mojofy unittests: ServiceWorkerJobTest (Closed)
Patch Set: Check if mojo is enabled when creating a mock interface Created 4 years, 2 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
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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 service_manager::mojom::InterfaceProviderPtr remote_interfaces; 620 service_manager::mojom::InterfaceProviderPtr remote_interfaces;
607 service_manager::mojom::InterfaceProviderRequest request = 621 service_manager::mojom::InterfaceProviderRequest request =
608 mojo::GetProxy(&remote_interfaces); 622 mojo::GetProxy(&remote_interfaces);
609 remote_interfaces_->Bind(std::move(remote_interfaces)); 623 remote_interfaces_->Bind(std::move(remote_interfaces));
610 service_manager::mojom::InterfaceProviderPtr exposed_interfaces; 624 service_manager::mojom::InterfaceProviderPtr exposed_interfaces;
611 interface_registry_->Bind(mojo::GetProxy(&exposed_interfaces)); 625 interface_registry_->Bind(mojo::GetProxy(&exposed_interfaces));
612 client_->StartWorker(*params, std::move(exposed_interfaces), 626 client_->StartWorker(*params, std::move(exposed_interfaces),
613 std::move(request)); 627 std::move(request));
614 registry_->BindWorkerToProcess(process_id(), embedded_worker_id()); 628 registry_->BindWorkerToProcess(process_id(), embedded_worker_id());
615 TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start", 629 TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start",
616 this, "SendStartWorker", "Status", "mojo"); 630 this, "SendStartWorker", "Status", "mojo");
617 OnStartWorkerMessageSent(); 631 OnStartWorkerMessageSent();
632 return SERVICE_WORKER_OK;
618 } 633 }
619 634
620 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() { 635 void EmbeddedWorkerInstance::OnStartWorkerMessageSent() {
621 if (!step_time_.is_null()) { 636 if (!step_time_.is_null()) {
622 base::TimeDelta duration = UpdateStepTime(); 637 base::TimeDelta duration = UpdateStepTime();
623 if (inflight_start_task_->is_installed()) { 638 if (inflight_start_task_->is_installed()) {
624 ServiceWorkerMetrics::RecordTimeToSendStartWorker(duration, 639 ServiceWorkerMetrics::RecordTimeToSendStartWorker(duration,
625 start_situation_); 640 start_situation_);
626 } 641 }
627 } 642 }
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 case SCRIPT_READ_FINISHED: 965 case SCRIPT_READ_FINISHED:
951 return "Script read finished"; 966 return "Script read finished";
952 case STARTING_PHASE_MAX_VALUE: 967 case STARTING_PHASE_MAX_VALUE:
953 NOTREACHED(); 968 NOTREACHED();
954 } 969 }
955 NOTREACHED() << phase; 970 NOTREACHED() << phase;
956 return std::string(); 971 return std::string();
957 } 972 }
958 973
959 } // namespace content 974 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698