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 fff872684d5df2df0f183883636cd2306f887e8a..b34323b864859bee7814398179f8838610b8cdd9 100644 |
| --- a/content/browser/service_worker/service_worker_storage.cc |
| +++ b/content/browser/service_worker/service_worker_storage.cc |
| @@ -338,7 +338,7 @@ void ServiceWorkerStorage::GetRegistrationsForOrigin( |
| if (state_ != INITIALIZING) { |
| RunSoon( |
| FROM_HERE, |
| - base::Bind(callback, |
| + base::Bind(callback, SERVICE_WORKER_ERROR_ABORT, |
| std::vector<scoped_refptr<ServiceWorkerRegistration>>())); |
| } |
| return; |
| @@ -364,8 +364,9 @@ void ServiceWorkerStorage::GetAllRegistrationsInfos( |
| base::Bind(&ServiceWorkerStorage::GetAllRegistrationsInfos, |
| weak_factory_.GetWeakPtr(), callback))) { |
| if (state_ != INITIALIZING) { |
| - RunSoon(FROM_HERE, base::Bind( |
| - callback, std::vector<ServiceWorkerRegistrationInfo>())); |
| + RunSoon(FROM_HERE, |
| + base::Bind(callback, SERVICE_WORKER_ERROR_ABORT, |
| + std::vector<ServiceWorkerRegistrationInfo>())); |
| } |
| return; |
| } |
| @@ -462,7 +463,6 @@ void ServiceWorkerStorage::UpdateToActiveState( |
| void ServiceWorkerStorage::UpdateLastUpdateCheckTime( |
| ServiceWorkerRegistration* registration) { |
| DCHECK(registration); |
| - |
| DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; |
| if (IsDisabled()) |
| return; |
| @@ -533,7 +533,9 @@ ServiceWorkerStorage::CreateResponseMetadataWriter(int64_t resource_id) { |
| void ServiceWorkerStorage::StoreUncommittedResourceId(int64_t resource_id) { |
| DCHECK_NE(kInvalidServiceWorkerResourceId, resource_id); |
| - DCHECK_EQ(INITIALIZED, state_); |
| + DCHECK(INITIALIZED == state_ || DISABLED == state_) << state_; |
| + if (IsDisabled()) |
| + return; |
| if (!has_checked_for_stale_resources_) |
| DeleteStaleResources(); |
| @@ -549,11 +551,18 @@ void ServiceWorkerStorage::StoreUncommittedResourceId(int64_t resource_id) { |
| void ServiceWorkerStorage::DoomUncommittedResource(int64_t resource_id) { |
| DCHECK_NE(kInvalidServiceWorkerResourceId, resource_id); |
| + DCHECK(INITIALIZED == state_ || DISABLED == state_) << state_; |
| + if (IsDisabled()) |
| + return; |
| DoomUncommittedResources(std::set<int64_t>(&resource_id, &resource_id + 1)); |
| } |
| void ServiceWorkerStorage::DoomUncommittedResources( |
| const std::set<int64_t>& resource_ids) { |
| + DCHECK(INITIALIZED == state_ || DISABLED == state_) << state_; |
| + if (IsDisabled()) |
| + return; |
| + |
| PostTaskAndReplyWithResult( |
| database_task_manager_->GetTaskRunner(), FROM_HERE, |
| base::Bind(&ServiceWorkerDatabase::PurgeUncommittedResourceIds, |
| @@ -758,10 +767,6 @@ void ServiceWorkerStorage::Disable() { |
| disk_cache_->Disable(); |
| } |
| -bool ServiceWorkerStorage::IsDisabled() const { |
| - return state_ == DISABLED; |
| -} |
| - |
| void ServiceWorkerStorage::PurgeResources(const ResourceList& resources) { |
| if (!has_checked_for_stale_resources_) |
| DeleteStaleResources(); |
| @@ -971,7 +976,8 @@ void ServiceWorkerStorage::DidGetRegistrations( |
| if (status != ServiceWorkerDatabase::STATUS_OK && |
| status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
| ScheduleDeleteAndStartOver(); |
| - callback.Run(std::vector<scoped_refptr<ServiceWorkerRegistration>>()); |
| + callback.Run(DatabaseStatusToStatusCode(status), |
| + std::vector<scoped_refptr<ServiceWorkerRegistration>>()); |
| return; |
| } |
| @@ -994,7 +1000,7 @@ void ServiceWorkerStorage::DidGetRegistrations( |
| } |
| } |
| - callback.Run(registrations); |
| + callback.Run(SERVICE_WORKER_OK, registrations); |
| } |
| void ServiceWorkerStorage::DidGetRegistrationsInfos( |
| @@ -1006,7 +1012,8 @@ void ServiceWorkerStorage::DidGetRegistrationsInfos( |
| if (status != ServiceWorkerDatabase::STATUS_OK && |
| status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
| ScheduleDeleteAndStartOver(); |
| - callback.Run(std::vector<ServiceWorkerRegistrationInfo>()); |
| + callback.Run(DatabaseStatusToStatusCode(status), |
| + std::vector<ServiceWorkerRegistrationInfo>()); |
| return; |
| } |
| @@ -1063,7 +1070,7 @@ void ServiceWorkerStorage::DidGetRegistrationsInfos( |
| } |
| } |
| - callback.Run(infos); |
| + callback.Run(SERVICE_WORKER_OK, infos); |
| } |
| void ServiceWorkerStorage::DidStoreRegistration( |
| @@ -1274,12 +1281,16 @@ ServiceWorkerStorage::FindInstallingRegistrationForId(int64_t registration_id) { |
| } |
| ServiceWorkerDiskCache* ServiceWorkerStorage::disk_cache() { |
| - DCHECK_EQ(INITIALIZED, state_); |
| + DCHECK(INITIALIZED == state_ || DISABLED == state_) << state_; |
| if (disk_cache_) |
| return disk_cache_.get(); |
| - |
| disk_cache_.reset(new ServiceWorkerDiskCache); |
| + if (IsDisabled()) { |
| + disk_cache_->Disable(); |
|
falken
2016/02/16 09:16:50
Ah, nice bug.
|
| + return disk_cache_.get(); |
| + } |
| + |
| base::FilePath path = GetDiskCachePath(); |
| if (path.empty()) { |
| int rv = disk_cache_->InitWithMemBackend(kMaxMemDiskCacheSize, |
| @@ -1687,6 +1698,10 @@ void ServiceWorkerStorage::DeleteAllDataForOriginsFromDB( |
| database->DeleteAllDataForOrigins(origins, &newly_purgeable_resources); |
| } |
| +bool ServiceWorkerStorage::IsDisabled() const { |
| + return state_ == DISABLED; |
| +} |
| + |
| // TODO(nhiroki): The corruption recovery should not be scheduled if the error |
| // is transient and it can get healed soon (e.g. IO error). To do that, the |
| // database should not disable itself when an error occurs and the storage |