| 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 f2ecc1fd9c73d56cf0e135fa625767d129b408f9..ae7b436b00946fad25eec26ecf8bc2ed60f85b12 100644
|
| --- a/content/browser/service_worker/service_worker_register_job.cc
|
| +++ b/content/browser/service_worker/service_worker_register_job.cc
|
| @@ -6,8 +6,6 @@
|
|
|
| #include <stdint.h>
|
|
|
| -#include <vector>
|
| -
|
| #include "base/location.h"
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/thread_task_runner_handle.h"
|
| @@ -16,6 +14,7 @@
|
| #include "content/browser/service_worker/service_worker_metrics.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_write_to_cache_job.h"
|
| #include "content/common/service_worker/service_worker_messages.h"
|
| #include "content/common/service_worker/service_worker_types.h"
|
| #include "content/common/service_worker/service_worker_utils.h"
|
| @@ -345,7 +344,12 @@ void ServiceWorkerRegisterJob::UpdateAndContinue() {
|
| set_new_version(new ServiceWorkerVersion(registration(), script_url_,
|
| version_id, context_));
|
| new_version()->set_force_bypass_cache_for_scripts(force_bypass_cache_);
|
| - new_version()->set_skip_script_comparison(skip_script_comparison_);
|
| + if (registration()->has_installed_version() && !skip_script_comparison_) {
|
| + new_version()->set_pause_after_download(true);
|
| + new_version()->embedded_worker()->AddListener(this);
|
| + } else {
|
| + new_version()->set_pause_after_download(false);
|
| + }
|
| new_version()->StartWorker(
|
| base::Bind(&ServiceWorkerRegisterJob::OnStartWorkerFinished,
|
| weak_factory_.GetWeakPtr()));
|
| @@ -363,7 +367,7 @@ void ServiceWorkerRegisterJob::OnStartWorkerFinished(
|
| registration()->last_update_check().is_null()) {
|
| registration()->set_last_update_check(base::Time::Now());
|
|
|
| - if (registration()->waiting_version() || registration()->active_version())
|
| + if (registration()->has_installed_version())
|
| context_->storage()->UpdateLastUpdateCheckTime(registration());
|
| }
|
|
|
| @@ -372,13 +376,6 @@ void ServiceWorkerRegisterJob::OnStartWorkerFinished(
|
| return;
|
| }
|
|
|
| - // The updated worker is identical to the incumbent.
|
| - if (status == SERVICE_WORKER_ERROR_EXISTS) {
|
| - ResolvePromise(SERVICE_WORKER_OK, std::string(), registration());
|
| - Complete(status, "The updated worker is identical to the incumbent.");
|
| - return;
|
| - }
|
| -
|
| // "If serviceWorker fails to start up..." then reject the promise with an
|
| // error and abort.
|
| if (status == SERVICE_WORKER_ERROR_TIMEOUT) {
|
| @@ -507,6 +504,12 @@ void ServiceWorkerRegisterJob::CompleteInternal(
|
| ServiceWorkerStatusCode status,
|
| const std::string& status_message) {
|
| SetPhase(COMPLETE);
|
| +
|
| + if (new_version()) {
|
| + new_version()->set_pause_after_download(false);
|
| + new_version()->embedded_worker()->RemoveListener(this);
|
| + }
|
| +
|
| if (status != SERVICE_WORKER_OK) {
|
| if (registration()) {
|
| if (should_uninstall_on_failure_)
|
| @@ -535,7 +538,7 @@ void ServiceWorkerRegisterJob::CompleteInternal(
|
| if (registration()) {
|
| context_->storage()->NotifyDoneInstallingRegistration(
|
| registration(), new_version(), status);
|
| - if (registration()->waiting_version() || registration()->active_version())
|
| + if (registration()->has_installed_version())
|
| registration()->set_is_uninstalled(false);
|
| }
|
| }
|
| @@ -574,4 +577,23 @@ void ServiceWorkerRegisterJob::AddRegistrationToMatchingProviderHosts(
|
| }
|
| }
|
|
|
| +void ServiceWorkerRegisterJob::OnScriptLoaded() {
|
| + DCHECK(new_version()->pause_after_download());
|
| + new_version()->set_pause_after_download(false);
|
| + net::URLRequestStatus status =
|
| + new_version()->script_cache_map()->main_script_status();
|
| + if (!status.is_success()) {
|
| + // OnScriptLoaded signifies a successful network load, which translates into
|
| + // a script cache error only in the byte-for-byte identical case.
|
| + DCHECK_EQ(status.error(),
|
| + ServiceWorkerWriteToCacheJob::kIdenticalScriptError);
|
| + ResolvePromise(SERVICE_WORKER_OK, std::string(), registration());
|
| + Complete(SERVICE_WORKER_ERROR_EXISTS,
|
| + "The updated worker is identical to the incumbent.");
|
| + return;
|
| + }
|
| +
|
| + new_version()->embedded_worker()->ResumeAfterDownload();
|
| +}
|
| +
|
| } // namespace content
|
|
|