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

Unified Diff: content/browser/service_worker/service_worker_version.cc

Issue 996123002: ServiceWorker: Ensure live registration during starting worker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 53f05f35587fccc65f3b26b5fb4fadef4e6cd0c0..b9fcf7fb08d12f075a78d21fd751cc25ccf3cc1a 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -377,10 +377,32 @@ void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) {
void ServiceWorkerVersion::StartWorker(
bool pause_after_download,
const StatusCallback& callback) {
- if (is_doomed()) {
+ if (!context_) {
+ RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED));
+ return;
+ }
+
+ // Ensure live registration during starting worker so that the worker can get
+ // associated with registration on SWDispatcherHost::OnSetHostedVersionId().
+ context_->storage()->FindRegistrationForId(
+ registration_id_,
+ scope_.GetOrigin(),
+ base::Bind(&ServiceWorkerVersion::DidEnsureLiveRegistration,
+ weak_factory_.GetWeakPtr(),
+ pause_after_download,
+ callback));
+}
+
+void ServiceWorkerVersion::DidEnsureLiveRegistration(
+ bool pause_after_download,
+ const StatusCallback& callback,
+ ServiceWorkerStatusCode status,
+ const scoped_refptr<ServiceWorkerRegistration>& protect) {
+ if (status != SERVICE_WORKER_OK || is_doomed()) {
RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED));
return;
}
+
switch (running_status()) {
case RUNNING:
RunSoon(base::Bind(callback, SERVICE_WORKER_OK));
@@ -397,7 +419,8 @@ void ServiceWorkerVersion::StartWorker(
embedded_worker_->Start(
version_id_, scope_, script_url_, pause_after_download,
base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
- weak_factory_.GetWeakPtr()));
+ weak_factory_.GetWeakPtr(),
+ protect));
kinuko 2015/03/11 14:41:56 I wonder just keeping this 'protect' in start_call
michaeln 2015/03/11 20:18:56 That sounds pretty good provided it can be made to
nhiroki 2015/03/12 05:27:11 Good idea. Modified the CL in this way.
}
return;
}
@@ -881,17 +904,8 @@ void ServiceWorkerVersion::OnStopped(
cache_listener_.reset();
// Restart worker if we have any start callbacks and the worker isn't doomed.
- if (should_restart) {
- if (embedded_worker_->devtools_attached())
- ClearTick(&start_time_);
- else
- RestartTick(&start_time_);
- cache_listener_.reset(new ServiceWorkerCacheListener(this, context_));
- embedded_worker_->Start(
- version_id_, scope_, script_url_, false /* pause_after_download */,
- base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
- weak_factory_.GetWeakPtr()));
nhiroki 2015/03/11 09:08:08 kinuko@ or falken@: I'm not really sure whether th
kinuko 2015/03/11 14:41:57 It's minor and is probably ok, but it looks just c
nhiroki 2015/03/12 05:27:11 Reverted this because it's no longer necessary to
- }
+ if (should_restart)
+ StartWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
}
void ServiceWorkerVersion::OnReportException(
@@ -963,6 +977,7 @@ bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) {
}
void ServiceWorkerVersion::OnStartSentAndScriptEvaluated(
+ scoped_refptr<ServiceWorkerRegistration> protect,
ServiceWorkerStatusCode status) {
if (status != SERVICE_WORKER_OK)
RunCallbacks(this, &start_callbacks_, status);
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698