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..b92a6bcaa0ee8c0f715492e87097c5f1dab1bbe2 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> |
jkarlin
2016/11/23 16:02:18
Nothing uses this that I can see.
cmumford
2016/11/29 18:10:20
Acknowledged.
|
#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; |
@@ -33,6 +35,7 @@ class BlobStorageContext; |
namespace content { |
class CacheStorageCacheHandle; |
+class CacheStorageIndex; |
class CacheStorageScheduler; |
// TODO(jkarlin): Constrain the total bytes used per origin. |
@@ -40,14 +43,16 @@ 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; |
+ constexpr static int64_t kSizeUnknown = -1; |
+ |
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): Rename this type (or use existing). |
jkarlin
2016/11/23 16:02:18
Can we resolve this TODO in this CL?
cmumford
2016/11/29 18:10:20
Sure. I renamed CacheStorageIndexCallback to Cache
jkarlin
2016/12/01 17:43:31
Perhaps in the future, but let's leave it for now.
|
+ using CacheMetadataCallback = base::Callback<void(const CacheStorageIndex&)>; |
using SizeCallback = base::Callback<void(int64_t)>; |
static const char kIndexFileName[]; |
@@ -86,8 +91,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 +121,16 @@ 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. |
jkarlin
2016/11/23 16:02:18
This looks out of place, there is no MemoryLoader
cmumford
2016/11/29 18:10:20
Oops - was added when CacheStorageIndex was being
|
class MemoryLoader; |
class SimpleCacheLoader; |
struct CacheMatchResponse; |
@@ -140,8 +151,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 +173,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 +182,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, |
@@ -203,6 +213,13 @@ class CONTENT_EXPORT CacheStorage { |
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 +242,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_; |
jkarlin
2016/11/23 16:02:18
nit: prefer cache_index_ for clarity
cmumford
2016/11/29 18:10:20
Done.
|
// The file path for this CacheStorage. |
base::FilePath origin_path_; |