Index: content/browser/service_worker/service_worker_storage.cc |
diff --git a/content/browser/service_worker/service_worker_storage.cc b/content/browser/service_worker/service_worker_storage.cc |
index 83e8c798fb3f5ea20465a51e8f1c23d631662876..2662a5ecb90f313381ad7b909aaa33a606515e3f 100644 |
--- a/content/browser/service_worker/service_worker_storage.cc |
+++ b/content/browser/service_worker/service_worker_storage.cc |
@@ -329,6 +329,22 @@ void ServiceWorkerStorage::FindRegistrationForPattern( |
weak_factory_.GetWeakPtr(), scope, callback))); |
} |
+scoped_refptr<ServiceWorkerRegistration> |
+ServiceWorkerStorage::GetUninstallingRegistration(const GURL& scope) { |
+ if (state_ != INITIALIZED || !context_) |
+ return NULL; |
+ for (RegistrationRefsById::const_iterator it = |
+ uninstalling_registrations_.begin(); |
+ it != uninstalling_registrations_.end(); |
+ ++it) { |
+ if (it->second->pattern() == scope) { |
+ DCHECK(it->second->is_uninstalling()); |
+ return it->second; |
+ } |
+ } |
+ return NULL; |
+} |
+ |
void ServiceWorkerStorage::FindRegistrationForId( |
int64 registration_id, |
const GURL& origin, |
@@ -420,7 +436,7 @@ void ServiceWorkerStorage::StoreRegistration( |
data.has_fetch_handler = true; |
data.version_id = version->version_id(); |
data.last_update_check = base::Time::Now(); |
- data.is_active = false; // initially stored in the waiting state |
+ data.is_active = (version == registration->active_version()); |
ResourceList resources; |
version->script_cache_map()->GetResources(&resources); |
@@ -437,6 +453,8 @@ void ServiceWorkerStorage::StoreRegistration( |
base::Bind(&ServiceWorkerStorage::DidStoreRegistration, |
weak_factory_.GetWeakPtr(), |
callback))); |
+ |
+ registration->set_is_deleted(false); |
} |
void ServiceWorkerStorage::UpdateToActiveState( |
@@ -494,7 +512,7 @@ void ServiceWorkerStorage::DeleteRegistration( |
ServiceWorkerRegistration* registration = |
context_->GetLiveRegistration(registration_id); |
if (registration) |
- registration->set_is_deleted(); |
+ registration->set_is_deleted(true); |
} |
scoped_ptr<ServiceWorkerResponseReader> |
@@ -608,6 +626,41 @@ void ServiceWorkerStorage::NotifyDoneInstallingRegistration( |
} |
} |
+void ServiceWorkerStorage::NotifyUninstallingRegistration( |
+ ServiceWorkerRegistration* registration) { |
+ uninstalling_registrations_[registration->id()] = registration; |
+ |
+ DeleteRegistration(registration->id(), |
+ registration->script_url().GetOrigin(), |
+ base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
+} |
+ |
+void ServiceWorkerStorage::NotifyAbortedUninstallingRegistration( |
+ ServiceWorkerRegistration* registration) { |
+ uninstalling_registrations_.erase(registration->id()); |
+ installing_registrations_[registration->id()] = registration; |
+ |
+ if (registration->waiting_version()) { |
+ StoreRegistration(registration, |
+ registration->waiting_version(), |
+ base::Bind(&ServiceWorkerStorage::DidRestoreRegistration, |
+ weak_factory_.GetWeakPtr(), |
+ registration->id())); |
+ } else if (registration->active_version()) { |
+ StoreRegistration(registration, |
+ registration->active_version(), |
+ base::Bind(&ServiceWorkerStorage::DidRestoreRegistration, |
+ weak_factory_.GetWeakPtr(), |
+ registration->id())); |
+ } |
+ registration->set_is_deleted(false); |
+} |
+ |
+void ServiceWorkerStorage::NotifyUninstalledRegistration( |
+ ServiceWorkerRegistration* registration) { |
+ uninstalling_registrations_.erase(registration->id()); |
+} |
+ |
void ServiceWorkerStorage::Disable() { |
state_ = DISABLED; |
if (disk_cache_) |
@@ -881,6 +934,13 @@ void ServiceWorkerStorage::DidStoreRegistration( |
StartPurgingResources(newly_purgeable_resources); |
} |
+void ServiceWorkerStorage::DidRestoreRegistration( |
+ int64 registration_id, |
+ ServiceWorkerStatusCode status) { |
+ if (status == SERVICE_WORKER_OK) |
+ installing_registrations_.erase(registration_id); |
+} |
+ |
void ServiceWorkerStorage::DidUpdateToActiveState( |
const StatusCallback& callback, |
ServiceWorkerDatabase::Status status) { |
@@ -924,7 +984,7 @@ ServiceWorkerStorage::GetOrCreateRegistration( |
data.scope, data.script, data.registration_id, context_); |
if (pending_deletions_.find(data.registration_id) != |
pending_deletions_.end()) { |
- registration->set_is_deleted(); |
+ registration->set_is_deleted(true); |
} |
scoped_refptr<ServiceWorkerVersion> version = |
context_->GetLiveVersion(data.version_id); |