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

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

Issue 465463002: Initial implementation of ServiceWorkerCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cache2
Patch Set: Comments on inputs (request and response) and back to SimpleCache now that it's fixed 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_cache_storage.cc
diff --git a/content/browser/service_worker/service_worker_cache_storage.cc b/content/browser/service_worker/service_worker_cache_storage.cc
index 8a9c6c4d266b029aa591b275acbaab4d2003d108..58b2763bd6f7b636a370542c344f091ff167a72c 100644
--- a/content/browser/service_worker/service_worker_cache_storage.cc
+++ b/content/browser/service_worker/service_worker_cache_storage.cc
@@ -64,7 +64,7 @@ class ServiceWorkerCacheStorage::CacheLoader
friend class base::RefCountedThreadSafe<
ServiceWorkerCacheStorage::CacheLoader>;
- virtual ~CacheLoader() {};
+ virtual ~CacheLoader() {}
virtual void LoadCacheImpl(const std::string&) {}
scoped_refptr<base::SequencedTaskRunner> cache_task_runner_;
@@ -344,11 +344,11 @@ class ServiceWorkerCacheStorage::SimpleCacheLoader
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerCacheStorageIndex index;
- index.ParseFromString(serialized);
-
- for (int i = 0, max = index.cache_size(); i < max; ++i) {
- const ServiceWorkerCacheStorageIndex::Cache& cache = index.cache(i);
- names->push_back(cache.name());
+ if (index.ParseFromString(serialized)) {
+ for (int i = 0, max = index.cache_size(); i < max; ++i) {
+ const ServiceWorkerCacheStorageIndex::Cache& cache = index.cache(i);
+ names->push_back(cache.name());
+ }
}
// TODO(jkarlin): Delete caches that are in the directory and not returned
@@ -448,6 +448,9 @@ void ServiceWorkerCacheStorage::GetCache(
return;
}
+ if (cache->HasCreatedBackend())
+ return callback.Run(cache->id(), CACHE_STORAGE_ERROR_NO_ERROR);
+
cache->CreateBackend(base::Bind(&ServiceWorkerCacheStorage::DidCreateBackend,
weak_factory_.GetWeakPtr(),
cache->AsWeakPtr(),
@@ -535,15 +538,16 @@ void ServiceWorkerCacheStorage::EnumerateCaches(
void ServiceWorkerCacheStorage::DidCreateBackend(
base::WeakPtr<ServiceWorkerCache> cache,
const CacheAndErrorCallback& callback,
- bool success) {
+ ServiceWorkerCache::ErrorType error) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (!success || !cache) {
+ if (error != ServiceWorkerCache::ErrorTypeOK || !cache) {
// TODO(jkarlin): This should delete the directory and try again in case
// the cache is simply corrupt.
callback.Run(0, CACHE_STORAGE_ERROR_STORAGE);
return;
}
+
callback.Run(cache->id(), CACHE_STORAGE_ERROR_NO_ERROR);
}
@@ -674,6 +678,7 @@ void ServiceWorkerCacheStorage::CreateCacheDidWriteIndex(
callback.Run(false, CACHE_STORAGE_ERROR_STORAGE);
return;
}
+
cache->CreateBackend(base::Bind(&ServiceWorkerCacheStorage::DidCreateBackend,
weak_factory_.GetWeakPtr(),
cache,

Powered by Google App Engine
This is Rietveld 408576698