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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_version.cc
diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
index 50adf19c784ffdcc79de8a15e9702d286bece151..1b1125b06c2b682ed6f5b3e1505010e67148da2e 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -200,6 +200,21 @@ void OnEventDispatcherConnectionError(
}
}
+mojom::ServiceWorkerProviderInfoForStartWorkerPtr
+CompleteProviderHostPreparation(
+ ServiceWorkerVersion* version,
+ std::unique_ptr<ServiceWorkerProviderHost> provider_host,
+ base::WeakPtr<ServiceWorkerContextCore> context,
+ int process_id) {
+ // Caller should ensure |context| is alive when completing StartWorker
+ // preparation.
+ DCHECK(context);
+ auto info =
+ provider_host->CompleteStartWorkerPreparation(process_id, version);
+ context->AddProviderHost(std::move(provider_host));
+ return info;
+}
+
} // namespace
const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 30;
@@ -847,6 +862,9 @@ ServiceWorkerVersion::PendingRequest::~PendingRequest() {}
void ServiceWorkerVersion::OnThreadStarted() {
DCHECK_EQ(EmbeddedWorkerStatus::STARTING, running_status());
+ DCHECK(provider_host_);
+ provider_host_->SetReadyToSendMessagesToWorker(
+ embedded_worker()->thread_id());
// Activate ping/pong now that JavaScript execution will start.
ping_controller_->Activate();
}
@@ -1466,6 +1484,10 @@ void ServiceWorkerVersion::StartWorkerInternal() {
StartTimeoutTimer();
+ std::unique_ptr<ServiceWorkerProviderHost> pending_provider_host =
+ ServiceWorkerProviderHost::PreCreateForController(context());
+ provider_host_ = pending_provider_host->AsWeakPtr();
+
auto params = base::MakeUnique<EmbeddedWorkerStartParams>();
params->service_worker_version_id = version_id_;
params->scope = scope_;
@@ -1474,7 +1496,12 @@ void ServiceWorkerVersion::StartWorkerInternal() {
params->pause_after_download = pause_after_download_;
embedded_worker_->Start(
- std::move(params), mojo::MakeRequest(&event_dispatcher_),
+ std::move(params),
+ // Unretained is used here because the callback will be owned by
+ // |embedded_worker_| whose owner is |this|.
+ base::BindOnce(&CompleteProviderHostPreparation, base::Unretained(this),
+ base::Passed(&pending_provider_host), context()),
+ mojo::MakeRequest(&event_dispatcher_),
base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
weak_factory_.GetWeakPtr()));
event_dispatcher_.set_connection_error_handler(base::Bind(

Powered by Google App Engine
This is Rietveld 408576698