Chromium Code Reviews| 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 c758f866928f4f5f46b8192e6c03f3ddf1280f07..db236fd283c7a7525985208fd62cd5f0e528077c 100644 |
| --- a/content/browser/service_worker/service_worker_storage.cc |
| +++ b/content/browser/service_worker/service_worker_storage.cc |
| @@ -116,6 +116,13 @@ scoped_ptr<ServiceWorkerStorage> ServiceWorkerStorage::Create( |
| old_storage->quota_manager_proxy_)); |
| } |
| +void ServiceWorkerStorage::OnNoControllees(ServiceWorkerVersion* version) { |
| + std::map<int64, std::vector<int64> >::iterator it = |
| + deleted_version_resource_ids_.find(version->version_id()); |
| + DCHECK(it != deleted_version_resource_ids_.end()); |
| + StartPurgingResources(it->second); |
| + deleted_version_resource_ids_.erase(it); |
|
michaeln
2014/06/30 22:31:54
maybe vers->removelistener(this) so theres less of
falken
2014/07/01 06:17:39
Done.
|
| +} |
| void ServiceWorkerStorage::FindRegistrationForDocument( |
| const GURL& document_url, |
| @@ -709,6 +716,7 @@ void ServiceWorkerStorage::DidDeleteRegistration( |
| const GURL& origin, |
| const StatusCallback& callback, |
| bool origin_is_deletable, |
| + int64 version_id, |
| const std::vector<int64>& newly_purgeable_resources, |
| ServiceWorkerDatabase::Status status) { |
| if (status != ServiceWorkerDatabase::STATUS_OK) { |
| @@ -719,7 +727,17 @@ void ServiceWorkerStorage::DidDeleteRegistration( |
| if (origin_is_deletable) |
| registered_origins_.erase(origin); |
| callback.Run(SERVICE_WORKER_OK); |
| - StartPurgingResources(newly_purgeable_resources); |
| + |
| + DCHECK(deleted_version_resource_ids_.find(version_id) == |
| + deleted_version_resource_ids_.end()); |
| + scoped_refptr<ServiceWorkerVersion> version = |
| + context_ ? context_->GetLiveVersion(version_id) : NULL; |
| + if (version && version->HasControllee()) { |
| + deleted_version_resource_ids_[version_id] = newly_purgeable_resources; |
| + version->AddListener(this); |
| + } else { |
| + StartPurgingResources(newly_purgeable_resources); |
| + } |
| } |
| scoped_refptr<ServiceWorkerRegistration> |
| @@ -832,26 +850,26 @@ void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) { |
| void ServiceWorkerStorage::StartPurgingResources( |
| const std::vector<int64>& ids) { |
| for (size_t i = 0; i < ids.size(); ++i) |
| - purgeable_reource_ids_.push_back(ids[i]); |
| + purgeable_resource_ids_.push_back(ids[i]); |
| ContinuePurgingResources(); |
| } |
| void ServiceWorkerStorage::StartPurgingResources( |
| const ResourceList& resources) { |
| for (size_t i = 0; i < resources.size(); ++i) |
| - purgeable_reource_ids_.push_back(resources[i].resource_id); |
| + purgeable_resource_ids_.push_back(resources[i].resource_id); |
| ContinuePurgingResources(); |
| } |
| void ServiceWorkerStorage::ContinuePurgingResources() { |
| - if (purgeable_reource_ids_.empty() || is_purge_pending_) |
| + if (purgeable_resource_ids_.empty() || is_purge_pending_) |
| return; |
| // Do one at a time until we're done, use RunSoon to avoid recursion when |
| // DoomEntry returns immediately. |
| is_purge_pending_ = true; |
| - int64 id = purgeable_reource_ids_.front(); |
| - purgeable_reource_ids_.pop_front(); |
| + int64 id = purgeable_resource_ids_.front(); |
| + purgeable_resource_ids_.pop_front(); |
| RunSoon(FROM_HERE, |
| base::Bind(&ServiceWorkerStorage::PurgeResource, |
| weak_factory_.GetWeakPtr(), id)); |
| @@ -911,13 +929,17 @@ void ServiceWorkerStorage::DeleteRegistrationFromDB( |
| const DeleteRegistrationCallback& callback) { |
| DCHECK(database); |
| + int64 version_id = kInvalidServiceWorkerVersionId; |
| std::vector<int64> newly_purgeable_resources; |
| - ServiceWorkerDatabase::Status status = |
| - database->DeleteRegistration(registration_id, origin, |
| - &newly_purgeable_resources); |
| + ServiceWorkerDatabase::Status status = database->DeleteRegistration( |
| + registration_id, origin, &version_id, &newly_purgeable_resources); |
| if (status != ServiceWorkerDatabase::STATUS_OK) { |
| - original_task_runner->PostTask( |
| - FROM_HERE, base::Bind(callback, false, std::vector<int64>(), status)); |
| + original_task_runner->PostTask(FROM_HERE, |
| + base::Bind(callback, |
| + false, |
| + kInvalidServiceWorkerVersionId, |
| + std::vector<int64>(), |
| + status)); |
| return; |
| } |
| @@ -926,15 +948,20 @@ void ServiceWorkerStorage::DeleteRegistrationFromDB( |
| std::vector<ServiceWorkerDatabase::RegistrationData> registrations; |
| status = database->GetRegistrationsForOrigin(origin, ®istrations); |
| if (status != ServiceWorkerDatabase::STATUS_OK) { |
| - original_task_runner->PostTask( |
| - FROM_HERE, base::Bind(callback, false, std::vector<int64>(), status)); |
| + original_task_runner->PostTask(FROM_HERE, |
| + base::Bind(callback, |
| + false, |
| + kInvalidServiceWorkerVersionId, |
| + std::vector<int64>(), |
| + status)); |
| return; |
| } |
| bool deletable = registrations.empty(); |
| original_task_runner->PostTask( |
| - FROM_HERE, base::Bind(callback, deletable, |
| - newly_purgeable_resources, status)); |
| + FROM_HERE, |
| + base::Bind( |
| + callback, deletable, version_id, newly_purgeable_resources, status)); |
| } |
| void ServiceWorkerStorage::WriteRegistrationInDB( |