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

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

Issue 2779763004: Create ServiceWorkerProviderHost before starting worker (Closed)
Patch Set: Pass the param of BindWithProviderInfo by value instead of pointer Created 3 years, 6 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/service_worker_version.h" 5 #include "content/browser/service_worker/service_worker_version.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // renderer shutdown like crash. 193 // renderer shutdown like crash.
194 embedded_worker->Detach(); 194 embedded_worker->Detach();
195 break; 195 break;
196 case EmbeddedWorkerStatus::STOPPING: 196 case EmbeddedWorkerStatus::STOPPING:
197 case EmbeddedWorkerStatus::STOPPED: 197 case EmbeddedWorkerStatus::STOPPED:
198 // Do nothing 198 // Do nothing
199 break; 199 break;
200 } 200 }
201 } 201 }
202 202
203 mojom::ServiceWorkerProviderInfoForStartWorkerPtr
204 CompleteProviderHostPreparation(
205 ServiceWorkerVersion* version,
206 std::unique_ptr<ServiceWorkerProviderHost> provider_host,
207 base::WeakPtr<ServiceWorkerContextCore> context,
208 int process_id) {
209 // Caller should ensure |context| is alive when completing StartWorker
210 // preparation.
211 DCHECK(context);
212 auto info =
213 provider_host->CompleteStartWorkerPreparation(process_id, version);
214 context->AddProviderHost(std::move(provider_host));
215 return info;
216 }
217
203 } // namespace 218 } // namespace
204 219
205 const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 30; 220 const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 30;
206 const int ServiceWorkerVersion::kStartInstalledWorkerTimeoutSeconds = 60; 221 const int ServiceWorkerVersion::kStartInstalledWorkerTimeoutSeconds = 60;
207 const int ServiceWorkerVersion::kStartNewWorkerTimeoutMinutes = 5; 222 const int ServiceWorkerVersion::kStartNewWorkerTimeoutMinutes = 5;
208 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5; 223 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5;
209 const int ServiceWorkerVersion::kStopWorkerTimeoutSeconds = 5; 224 const int ServiceWorkerVersion::kStopWorkerTimeoutSeconds = 5;
210 225
211 void ServiceWorkerVersion::RestartTick(base::TimeTicks* time) const { 226 void ServiceWorkerVersion::RestartTick(base::TimeTicks* time) const {
212 *time = tick_clock_->NowTicks(); 227 *time = tick_clock_->NowTicks();
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 ServiceWorkerMetrics::EventType event_type) 855 ServiceWorkerMetrics::EventType event_type)
841 : error_callback(callback), 856 : error_callback(callback),
842 start_time(time), 857 start_time(time),
843 start_time_ticks(time_ticks), 858 start_time_ticks(time_ticks),
844 event_type(event_type) {} 859 event_type(event_type) {}
845 860
846 ServiceWorkerVersion::PendingRequest::~PendingRequest() {} 861 ServiceWorkerVersion::PendingRequest::~PendingRequest() {}
847 862
848 void ServiceWorkerVersion::OnThreadStarted() { 863 void ServiceWorkerVersion::OnThreadStarted() {
849 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, running_status()); 864 DCHECK_EQ(EmbeddedWorkerStatus::STARTING, running_status());
865 DCHECK(provider_host_);
866 provider_host_->SetReadyToSendMessagesToWorker(
867 embedded_worker()->thread_id());
850 // Activate ping/pong now that JavaScript execution will start. 868 // Activate ping/pong now that JavaScript execution will start.
851 ping_controller_->Activate(); 869 ping_controller_->Activate();
852 } 870 }
853 871
854 void ServiceWorkerVersion::OnStarting() { 872 void ServiceWorkerVersion::OnStarting() {
855 for (auto& observer : listeners_) 873 for (auto& observer : listeners_)
856 observer.OnRunningStateChanged(this); 874 observer.OnRunningStateChanged(this);
857 } 875 }
858 876
859 void ServiceWorkerVersion::OnStarted() { 877 void ServiceWorkerVersion::OnStarted() {
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 DCHECK_EQ(EmbeddedWorkerStatus::STOPPED, running_status()); 1477 DCHECK_EQ(EmbeddedWorkerStatus::STOPPED, running_status());
1460 1478
1461 if (!ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)) { 1479 if (!ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(site_for_uma_)) {
1462 DCHECK(!event_recorder_); 1480 DCHECK(!event_recorder_);
1463 event_recorder_ = 1481 event_recorder_ =
1464 base::MakeUnique<ServiceWorkerMetrics::ScopedEventRecorder>(); 1482 base::MakeUnique<ServiceWorkerMetrics::ScopedEventRecorder>();
1465 } 1483 }
1466 1484
1467 StartTimeoutTimer(); 1485 StartTimeoutTimer();
1468 1486
1487 std::unique_ptr<ServiceWorkerProviderHost> pending_provider_host =
1488 ServiceWorkerProviderHost::PreCreateForController(context());
1489 provider_host_ = pending_provider_host->AsWeakPtr();
1490
1469 auto params = base::MakeUnique<EmbeddedWorkerStartParams>(); 1491 auto params = base::MakeUnique<EmbeddedWorkerStartParams>();
1470 params->service_worker_version_id = version_id_; 1492 params->service_worker_version_id = version_id_;
1471 params->scope = scope_; 1493 params->scope = scope_;
1472 params->script_url = script_url_; 1494 params->script_url = script_url_;
1473 params->is_installed = IsInstalled(status_); 1495 params->is_installed = IsInstalled(status_);
1474 params->pause_after_download = pause_after_download_; 1496 params->pause_after_download = pause_after_download_;
1475 1497
1476 embedded_worker_->Start( 1498 embedded_worker_->Start(
1477 std::move(params), mojo::MakeRequest(&event_dispatcher_), 1499 std::move(params),
1500 // Unretained is used here because the callback will be owned by
1501 // |embedded_worker_| whose owner is |this|.
1502 base::BindOnce(&CompleteProviderHostPreparation, base::Unretained(this),
1503 base::Passed(&pending_provider_host), context()),
1504 mojo::MakeRequest(&event_dispatcher_),
1478 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, 1505 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
1479 weak_factory_.GetWeakPtr())); 1506 weak_factory_.GetWeakPtr()));
1480 event_dispatcher_.set_connection_error_handler(base::Bind( 1507 event_dispatcher_.set_connection_error_handler(base::Bind(
1481 &OnEventDispatcherConnectionError, embedded_worker_->AsWeakPtr())); 1508 &OnEventDispatcherConnectionError, embedded_worker_->AsWeakPtr()));
1482 } 1509 }
1483 1510
1484 void ServiceWorkerVersion::StartTimeoutTimer() { 1511 void ServiceWorkerVersion::StartTimeoutTimer() {
1485 DCHECK(!timeout_timer_.IsRunning()); 1512 DCHECK(!timeout_timer_.IsRunning());
1486 1513
1487 if (embedded_worker_->devtools_attached()) { 1514 if (embedded_worker_->devtools_attached()) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1859 1886
1860 void ServiceWorkerVersion::CleanUpExternalRequest( 1887 void ServiceWorkerVersion::CleanUpExternalRequest(
1861 const std::string& request_uuid, 1888 const std::string& request_uuid,
1862 ServiceWorkerStatusCode status) { 1889 ServiceWorkerStatusCode status) {
1863 if (status == SERVICE_WORKER_OK) 1890 if (status == SERVICE_WORKER_OK)
1864 return; 1891 return;
1865 external_request_uuid_to_request_id_.erase(request_uuid); 1892 external_request_uuid_to_request_id_.erase(request_uuid);
1866 } 1893 }
1867 1894
1868 } // namespace content 1895 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698