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

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

Issue 417043006: ServiceWorker: Make SWProviderHost listen to SWRegistration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address michael's comments Created 6 years, 4 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_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 9d1a83d3101eee6415372ca52400865016b61039..87e5ebb087e56729c97209876b16a135dc1325b7 100644
--- a/content/browser/service_worker/service_worker_register_job.cc
+++ b/content/browser/service_worker/service_worker_register_job.cc
@@ -247,6 +247,7 @@ void ServiceWorkerRegisterJob::RegisterAndContinue(
set_registration(new ServiceWorkerRegistration(
pattern_, script_url_, context_->storage()->NewRegistrationId(),
context_));
+ AssociateProviderHostsToRegistration(registration());
UpdateAndContinue();
}
@@ -296,7 +297,6 @@ void ServiceWorkerRegisterJob::InstallAndContinue() {
// "3. Set registration.installingWorker to worker."
registration()->SetInstallingVersion(new_version());
- AssociateInstallingVersionToDocuments(context_, new_version());
// "4. Run the [[UpdateState]] algorithm passing registration.installingWorker
// and "installing" as the arguments."
@@ -346,9 +346,7 @@ void ServiceWorkerRegisterJob::OnStoreRegistrationComplete(
// "10. Set registration.waitingWorker to registration.installingWorker."
// "11. Set registration.installingWorker to null."
- DisassociateVersionFromDocuments(context_, new_version());
registration()->SetWaitingVersion(new_version());
- AssociateWaitingVersionToDocuments(context_, new_version());
// "12. Run the [[UpdateState]] algorithm passing registration.waitingWorker
// and "installed" as the arguments."
@@ -374,11 +372,12 @@ void ServiceWorkerRegisterJob::CompleteInternal(
if (status != SERVICE_WORKER_OK) {
if (registration()) {
if (new_version()) {
- DisassociateVersionFromDocuments(context_, new_version());
registration()->UnsetVersion(new_version());
new_version()->Doom();
}
- if (!registration()->active_version()) {
+ if (!registration()->waiting_version() &&
+ !registration()->active_version()) {
+ registration()->NotifyRegistrationFailed();
context_->storage()->DeleteRegistration(
registration()->id(),
registration()->script_url().GetOrigin(),
@@ -453,77 +452,19 @@ void ServiceWorkerRegisterJob::OnCompareScriptResourcesComplete(
new_version()->embedded_worker()->RemoveListener(this);
}
-// static
-void ServiceWorkerRegisterJob::AssociateInstallingVersionToDocuments(
- base::WeakPtr<ServiceWorkerContextCore> context,
- ServiceWorkerVersion* version) {
- DCHECK(context);
- DCHECK(version);
-
- for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
- context->GetProviderHostIterator();
- !it->IsAtEnd(); it->Advance()) {
- ServiceWorkerProviderHost* host = it->GetProviderHost();
- if (ServiceWorkerUtils::ScopeMatches(version->scope(),
- host->document_url())) {
- if (!host->CanAssociateVersion(version))
- continue;
- host->SetInstallingVersion(version);
- }
- }
-}
-
-// static
-void ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments(
- base::WeakPtr<ServiceWorkerContextCore> context,
- ServiceWorkerVersion* version) {
- DCHECK(context);
- DCHECK(version);
-
- for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
- context->GetProviderHostIterator();
- !it->IsAtEnd(); it->Advance()) {
- ServiceWorkerProviderHost* host = it->GetProviderHost();
- if (ServiceWorkerUtils::ScopeMatches(version->scope(),
- host->document_url())) {
- if (!host->CanAssociateVersion(version))
- continue;
- host->SetWaitingVersion(version);
- }
- }
-}
-
-// static
-void ServiceWorkerRegisterJob::AssociateActiveVersionToDocuments(
- base::WeakPtr<ServiceWorkerContextCore> context,
- ServiceWorkerVersion* version) {
- DCHECK(context);
- DCHECK(version);
-
+void ServiceWorkerRegisterJob::AssociateProviderHostsToRegistration(
+ ServiceWorkerRegistration* registration) {
+ DCHECK(registration);
for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
- context->GetProviderHostIterator();
+ context_->GetProviderHostIterator();
!it->IsAtEnd(); it->Advance()) {
ServiceWorkerProviderHost* host = it->GetProviderHost();
- if (ServiceWorkerUtils::ScopeMatches(version->scope(),
+ if (ServiceWorkerUtils::ScopeMatches(registration->pattern(),
host->document_url())) {
- if (!host->CanAssociateVersion(version))
- continue;
- host->SetActiveVersion(version);
+ if (host->CanAssociateRegistration(registration))
+ host->AssociateRegistration(registration);
}
}
}
-// static
-void ServiceWorkerRegisterJob::DisassociateVersionFromDocuments(
- base::WeakPtr<ServiceWorkerContextCore> context,
- ServiceWorkerVersion* version) {
- DCHECK(context);
- for (scoped_ptr<ServiceWorkerContextCore::ProviderHostIterator> it =
- context->GetProviderHostIterator();
- !it->IsAtEnd(); it->Advance()) {
- ServiceWorkerProviderHost* host = it->GetProviderHost();
- host->UnsetVersion(version);
- }
-}
-
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698