Index: content/browser/service_worker/service_worker_cache_storage.h |
diff --git a/content/browser/service_worker/service_worker_cache_storage.h b/content/browser/service_worker/service_worker_cache_storage.h |
index 6eebb7d6c79c873ff01014ffd4baf98f4ad21d7e..6a65902b3939134faf770a4e2dc9e379fd34a9dd 100644 |
--- a/content/browser/service_worker/service_worker_cache_storage.h |
+++ b/content/browser/service_worker/service_worker_cache_storage.h |
@@ -26,12 +26,13 @@ class BlobStorageContext; |
} |
namespace content { |
+class ServiceWorkerCacheScheduler; |
// TODO(jkarlin): Constrain the total bytes used per origin. |
// ServiceWorkerCacheStorage holds the set of caches for a given origin. It is |
// owned by the ServiceWorkerCacheStorageManager. This class expects to be run |
-// on the IO thread. |
+// on the IO thread. The asynchronous methods are executed serially. |
class CONTENT_EXPORT ServiceWorkerCacheStorage { |
public: |
enum CacheStorageError { |
@@ -94,12 +95,19 @@ class CONTENT_EXPORT ServiceWorkerCacheStorage { |
void MatchAllCaches(scoped_ptr<ServiceWorkerFetchRequest> request, |
const ServiceWorkerCache::ResponseCallback& callback); |
+ // Calls close on each cache and runs the callback after all of them have |
+ // closed. |
void CloseAllCaches(const base::Closure& callback); |
// The size of all of the origin's contents in memory. Returns 0 if the cache |
- // backend is not a memory backend. |
+ // backend is not a memory backend. Runs synchronously. |
int64 MemoryBackedSize() const; |
+ // The functions below are for tests to verify that the operations run |
+ // serially. |
+ void StartAsyncOperationForTesting(); |
+ void CompleteAsyncOperationForTesting(); |
+ |
private: |
class MemoryLoader; |
class SimpleCacheLoader; |
@@ -112,17 +120,15 @@ class CONTENT_EXPORT ServiceWorkerCacheStorage { |
scoped_refptr<ServiceWorkerCache> GetLoadedCache( |
const std::string& cache_name); |
- // Initializer and its callback are below. While LazyInit is running any new |
- // operations will be queued and started in order after initialization. |
- void LazyInit(const base::Closure& closure); |
+ // Initializer and its callback are below. |
+ void LazyInit(); |
+ void LazyInitImpl(); |
void LazyInitDidLoadIndex( |
- const base::Closure& callback, |
scoped_ptr<std::vector<std::string> > indexed_cache_names); |
- void AddCacheToMap(const std::string& cache_name, |
- base::WeakPtr<ServiceWorkerCache> cache); |
- |
- // The CreateCache callbacks are below. |
+ // The Open and CreateCache callbacks are below. |
+ void OpenCacheImpl(const std::string& cache_name, |
+ const CacheAndErrorCallback& callback); |
void CreateCacheDidCreateCache( |
const std::string& cache_name, |
const CacheAndErrorCallback& callback, |
@@ -131,7 +137,14 @@ class CONTENT_EXPORT ServiceWorkerCacheStorage { |
const scoped_refptr<ServiceWorkerCache>& cache, |
bool success); |
+ // The HasCache callbacks are below. |
+ void HasCacheImpl(const std::string& cache_name, |
+ const BoolAndErrorCallback& callback); |
+ |
// The DeleteCache callbacks are below. |
+ void DeleteCacheImpl(const std::string& cache_name, |
+ const BoolAndErrorCallback& callback); |
+ |
void DeleteCacheDidClose(const std::string& cache_name, |
const BoolAndErrorCallback& callback, |
const StringVector& ordered_cache_names, |
@@ -142,7 +155,13 @@ class CONTENT_EXPORT ServiceWorkerCacheStorage { |
void DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback, |
bool success); |
+ // The EnumerateCache callbacks are below. |
+ void EnumerateCachesImpl(const StringsAndErrorCallback& callback); |
+ |
// The MatchCache callbacks are below. |
+ void MatchCacheImpl(const std::string& cache_name, |
+ scoped_ptr<ServiceWorkerFetchRequest> request, |
+ const ServiceWorkerCache::ResponseCallback& callback); |
void MatchCacheDidMatch(const scoped_refptr<ServiceWorkerCache>& cache, |
const ServiceWorkerCache::ResponseCallback& callback, |
ServiceWorkerCache::ErrorType error, |
@@ -150,6 +169,8 @@ class CONTENT_EXPORT ServiceWorkerCacheStorage { |
scoped_ptr<storage::BlobDataHandle> handle); |
// The MatchAllCaches callbacks are below. |
+ void MatchAllCachesImpl(scoped_ptr<ServiceWorkerFetchRequest> request, |
+ const ServiceWorkerCache::ResponseCallback& callback); |
void MatchAllCachesDidMatch(scoped_refptr<ServiceWorkerCache> cache, |
const base::Closure& barrier_closure, |
ServiceWorkerCache::ResponseCallback* callback, |
@@ -159,11 +180,32 @@ class CONTENT_EXPORT ServiceWorkerCacheStorage { |
void MatchAllCachesDidMatchAll( |
scoped_ptr<ServiceWorkerCache::ResponseCallback> callback); |
+ // The CloseAllCaches callbacks are below. |
+ void CloseAllCachesImpl(const base::Closure& callback); |
+ |
+ void PendingClosure(const base::Closure& callback); |
+ void PendingBoolAndErrorCallback(const BoolAndErrorCallback& callback, |
+ bool found, |
+ CacheStorageError error); |
+ void PendingCacheAndErrorCallback( |
+ const CacheAndErrorCallback& callback, |
+ const scoped_refptr<ServiceWorkerCache>& cache, |
+ CacheStorageError error); |
+ void PendingStringsAndErrorCallback(const StringsAndErrorCallback& callback, |
+ const StringVector& strings, |
+ CacheStorageError error); |
+ void PendingResponseCallback( |
+ const ServiceWorkerCache::ResponseCallback& callback, |
+ ServiceWorkerCache::ErrorType error, |
+ scoped_ptr<ServiceWorkerResponse> response, |
+ scoped_ptr<storage::BlobDataHandle> blob_data_handle); |
+ |
// Whether or not we've loaded the list of cache names into memory. |
bool initialized_; |
+ bool initializing_; |
- // The list of operations waiting on initialization. |
- std::vector<base::Closure> init_callbacks_; |
+ // The pending operation scheduler. |
+ scoped_ptr<ServiceWorkerCacheScheduler> scheduler_; |
// The map of cache names to ServiceWorkerCache objects. |
CacheMap cache_map_; |