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

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: Default backend 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 d7dfbacb9a822fad7f7326c1b497052ca0b17c2f..90d12df8c0da4b6a2d6182c0a95f13a0413796f9 100644
--- a/content/browser/service_worker/service_worker_cache_storage.cc
+++ b/content/browser/service_worker/service_worker_cache_storage.cc
@@ -63,7 +63,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_;
@@ -342,11 +342,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
@@ -446,6 +446,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(),
@@ -533,15 +536,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);
}
@@ -672,6 +676,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