Chromium Code Reviews| Index: content/browser/cache_storage/cache_storage.h |
| diff --git a/content/browser/cache_storage/cache_storage.h b/content/browser/cache_storage/cache_storage.h |
| index e0569f19716d5327e43801801ee5a948e56a51d7..f9fe44b9a4d08bdceed78dc1e182cc81d845e807 100644 |
| --- a/content/browser/cache_storage/cache_storage.h |
| +++ b/content/browser/cache_storage/cache_storage.h |
| @@ -7,6 +7,7 @@ |
| #include <stdint.h> |
| +#include <list> |
| #include <map> |
| #include <memory> |
| #include <string> |
| @@ -18,6 +19,7 @@ |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/weak_ptr.h" |
| #include "content/browser/cache_storage/cache_storage_cache.h" |
| +#include "content/browser/cache_storage/cache_storage_cache_observer.h" |
| namespace base { |
| class SequencedTaskRunner; |
| @@ -40,14 +42,24 @@ class CacheStorageScheduler; |
| // CacheStorage holds the set of caches for a given origin. It is |
| // owned by the CacheStorageManager. This class expects to be run |
| // on the IO thread. The asynchronous methods are executed serially. |
| -class CONTENT_EXPORT CacheStorage { |
| +class CONTENT_EXPORT CacheStorage : public CacheStorageCacheObserver { |
| public: |
| - typedef std::vector<std::string> StringVector; |
| + static const int64_t kSizeUnknown = -1; |
| + |
| + struct CacheInfo { |
|
jkarlin
2016/10/21 18:04:19
Suggest CacheMetadata? Seems ever so slightly more
cmumford
2016/11/10 17:28:16
Done.
|
| + CacheInfo(const std::string& name, int64_t size) : name(name), size(size) {} |
| + std::string name; |
| + // The size (in bytes) of the cache. Set to kSizeUnknown if size not known. |
| + int64_t size; |
| + }; |
| + |
| typedef base::Callback<void(bool, CacheStorageError)> BoolAndErrorCallback; |
| typedef base::Callback<void(std::unique_ptr<CacheStorageCacheHandle>, |
| CacheStorageError)> |
| CacheAndErrorCallback; |
| - using StringsCallback = base::Callback<void(const StringVector&)>; |
| + // TODO(cmumford): Why not pass back the entire index instead of it's list of |
| + // CachInfo objects? |
| + using CacheInfoCallback = base::Callback<void(const std::list<CacheInfo>&)>; |
| using SizeCallback = base::Callback<void(int64_t)>; |
| static const char kIndexFileName[]; |
| @@ -86,8 +98,8 @@ class CONTENT_EXPORT CacheStorage { |
| void DeleteCache(const std::string& cache_name, |
| const BoolAndErrorCallback& callback); |
| - // Calls the callback with a vector of cache names (keys) available. |
| - void EnumerateCaches(const StringsCallback& callback); |
| + // Calls the callback with a collection of cache metadata available. |
| + void EnumerateCaches(const CacheInfoCallback& callback); |
| // Calls match on the cache with the given |cache_name|. |
| void MatchCache(const std::string& cache_name, |
| @@ -116,10 +128,18 @@ class CONTENT_EXPORT CacheStorage { |
| void StartAsyncOperationForTesting(); |
| void CompleteAsyncOperationForTesting(); |
| + // CacheStorageCacheObserver: |
| + void CacheModified(const CacheStorageCache* cache, |
| + int64_t size_delta) override; |
| + void SetCacheSize(const CacheStorageCache* cache, |
| + int64_t cache_size) override; |
| + |
| private: |
| friend class CacheStorageCacheHandle; |
| friend class CacheStorageCache; |
| class CacheLoader; |
| + // Note: Not to be confused with class by same name generated by protobuf. |
| + class CacheStorageIndex; |
| class MemoryLoader; |
| class SimpleCacheLoader; |
| struct CacheMatchResponse; |
| @@ -140,8 +160,7 @@ class CONTENT_EXPORT CacheStorage { |
| // Initializer and its callback are below. |
| void LazyInit(); |
| void LazyInitImpl(); |
| - void LazyInitDidLoadIndex( |
| - std::unique_ptr<std::vector<std::string>> indexed_cache_names); |
| + void LazyInitDidLoadIndex(std::unique_ptr<CacheStorageIndex> index); |
| // The Open and CreateCache callbacks are below. |
| void OpenCacheImpl(const std::string& cache_name, |
| @@ -163,7 +182,7 @@ class CONTENT_EXPORT CacheStorage { |
| const BoolAndErrorCallback& callback); |
| void DeleteCacheDidWriteIndex( |
| const std::string& cache_name, |
| - const StringVector& original_ordered_cache_names, |
| + std::unique_ptr<CacheStorageIndex> index_before_delete, |
| const BoolAndErrorCallback& callback, |
| bool success); |
| void DeleteCacheFinalize(std::unique_ptr<CacheStorageCache> doomed_cache); |
| @@ -172,7 +191,7 @@ class CONTENT_EXPORT CacheStorage { |
| void DeleteCacheDidCleanUp(bool success); |
| // The EnumerateCache callbacks are below. |
| - void EnumerateCachesImpl(const StringsCallback& callback); |
| + void EnumerateCachesImpl(const CacheInfoCallback& callback); |
| // The MatchCache callbacks are below. |
| void MatchCacheImpl(const std::string& cache_name, |
| @@ -200,9 +219,17 @@ class CONTENT_EXPORT CacheStorage { |
| std::unique_ptr<std::vector<CacheMatchResponse>> match_responses, |
| const CacheStorageCache::ResponseCallback& callback); |
| + void CloseAllCaches(); |
| void GetSizeThenCloseAllCachesImpl(const SizeCallback& callback); |
| void SizeImpl(const SizeCallback& callback); |
| + void SizeRetrievedFromCache( |
| + std::unique_ptr<CacheStorageCacheHandle> cache_handle, |
| + const base::Closure& closure, |
| + int64_t* accumulator, |
| + int64_t size); |
| + |
| + void ScheduleWriteIndex(); |
| // Whether or not we've loaded the list of cache names into memory. |
| bool initialized_; |
| @@ -225,8 +252,8 @@ class CONTENT_EXPORT CacheStorage { |
| // CacheStorageCacheHandle reference counts |
| std::map<CacheStorageCache*, size_t> cache_handle_counts_; |
| - // The names of caches in the order that they were created. |
| - StringVector ordered_cache_names_; |
| + // The cache index data. |
| + std::unique_ptr<CacheStorageIndex> index_; |
| // The file path for this CacheStorage. |
| base::FilePath origin_path_; |