| 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..8a98759fbe08462b2476f4768c29ae89b007b1c9 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,26 @@ 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 CacheMetadata {
|
| + CacheMetadata(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 CacheMetadataCallback =
|
| + base::Callback<void(const std::list<CacheMetadata>&)>;
|
| using SizeCallback = base::Callback<void(int64_t)>;
|
|
|
| static const char kIndexFileName[];
|
| @@ -86,8 +100,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 CacheMetadataCallback& callback);
|
|
|
| // Calls match on the cache with the given |cache_name|.
|
| void MatchCache(const std::string& cache_name,
|
| @@ -116,10 +130,17 @@ class CONTENT_EXPORT CacheStorage {
|
| void StartAsyncOperationForTesting();
|
| void CompleteAsyncOperationForTesting();
|
|
|
| + // CacheStorageCacheObserver:
|
| + void CacheSizeSet(const CacheStorageCache* cache,
|
| + Whence whence,
|
| + int64_t 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 +161,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 +183,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 +192,7 @@ class CONTENT_EXPORT CacheStorage {
|
| void DeleteCacheDidCleanUp(bool success);
|
|
|
| // The EnumerateCache callbacks are below.
|
| - void EnumerateCachesImpl(const StringsCallback& callback);
|
| + void EnumerateCachesImpl(const CacheMetadataCallback& callback);
|
|
|
| // The MatchCache callbacks are below.
|
| void MatchCacheImpl(const std::string& cache_name,
|
| @@ -200,9 +220,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 +253,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_;
|
|
|