Index: content/browser/service_worker/service_worker_register_job.cc |
diff --git a/content/browser/service_worker/service_worker_register_job.cc b/content/browser/service_worker/service_worker_register_job.cc |
index 0a28dc1ccab0af6b23f99e53b9b04f4f851599e6..3a38eb09737cac14c46f93c74f06f19dafdeb00a 100644 |
--- a/content/browser/service_worker/service_worker_register_job.cc |
+++ b/content/browser/service_worker/service_worker_register_job.cc |
@@ -7,12 +7,14 @@ |
#include <vector> |
#include "base/message_loop/message_loop.h" |
+#include "base/rand_util.h" |
#include "content/browser/service_worker/service_worker_context_core.h" |
#include "content/browser/service_worker/service_worker_job_coordinator.h" |
#include "content/browser/service_worker/service_worker_registration.h" |
#include "content/browser/service_worker/service_worker_storage.h" |
#include "content/browser/service_worker/service_worker_utils.h" |
#include "content/common/service_worker/service_worker_types.h" |
+#include "content/public/browser/browser_main_runner.h" |
#include "net/base/net_errors.h" |
namespace content { |
@@ -81,6 +83,16 @@ void ServiceWorkerRegisterJob::AddCallback( |
void ServiceWorkerRegisterJob::Start() { |
SetPhase(START); |
+ |
+ if (IsBrowserStartingUp()) { |
+ // Delay running update jobs until after startup. |
+ delayed_start_timer_.Start( |
+ FROM_HERE, base::TimeDelta::FromSeconds(base::RandInt(5, 15)), |
+ base::Bind(&ServiceWorkerRegisterJob::Restart, |
+ weak_factory_.GetWeakPtr())); |
+ return; |
+ } |
+ |
ServiceWorkerStorage::FindRegistrationCallback next_step; |
if (job_type_ == REGISTRATION_JOB) { |
next_step = base::Bind( |
@@ -178,11 +190,18 @@ void ServiceWorkerRegisterJob::SetPhase(Phase phase) { |
DCHECK(phase_ != INITIAL && phase_ != COMPLETE) << phase_; |
break; |
case ABORT: |
+ delayed_start_timer_.Stop(); |
break; |
} |
phase_ = phase; |
} |
+void ServiceWorkerRegisterJob::Restart() { |
+ DCHECK(phase_ == START) << phase_; |
cmumford
2015/02/26 23:47:45
DCHECK_EQ.
Also, couldn't you get here before STA
|
+ phase_ = INITIAL; |
+ Start(); |
+} |
+ |
// This function corresponds to the steps in [[Register]] following |
// "Let registration be the result of running the [[GetRegistration]] algorithm. |
// Throughout this file, comments in quotes are excerpts from the spec. |