Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_INDEX_H_ | |
| 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_INDEX_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <string> | |
| 10 #include <unordered_map> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "content/browser/cache_storage/cache_storage.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 class CacheMetadata; | |
| 18 | |
| 19 // CacheStorageIndex maintains an ordered list of metadata (CacheMetadata) | |
| 20 // for each cache owned by a CacheStorage object. This class is not thread safe, | |
| 21 // and is owned by the CacheStorage. | |
| 22 class CONTENT_EXPORT CacheStorageIndex { | |
| 23 public: | |
| 24 struct CacheMetadata { | |
| 25 CacheMetadata(const std::string& name, int64_t size) | |
| 26 : name(name), size(size) {} | |
| 27 std::string name; | |
| 28 // The size (in bytes) of the cache. Set to CacheStorage::kSizeUnknown if | |
| 29 // size not known. | |
| 30 int64_t size; | |
| 31 }; | |
| 32 | |
| 33 CacheStorageIndex(); | |
| 34 ~CacheStorageIndex(); | |
| 35 | |
| 36 CacheStorageIndex& operator=(CacheStorageIndex&& rhs); | |
| 37 | |
| 38 void Insert(const CacheMetadata& cache_metadata); | |
| 39 void Delete(const std::string& cache_name); | |
| 40 | |
| 41 // Sets the cache size. Returns true if the new size is different than the | |
| 42 // current size else false. | |
| 43 bool SetCacheSize(const std::string& cache_name, int64_t size); | |
| 44 | |
| 45 // Return the size (in bytes) of the specified cache. Will return | |
| 46 // CacheStorage::kSizeUnknown if the specified cache does not exist. | |
| 47 int64_t GetCacheSize(const std::string& cache_name) const; | |
| 48 | |
| 49 const std::list<CacheMetadata>& ordered_cache_metadata() const { | |
| 50 return ordered_cache_metadata_; | |
| 51 } | |
| 52 | |
| 53 size_t num_entries() const { return ordered_cache_metadata_.size(); } | |
| 54 | |
| 55 // Will calculate (if necessary), and return the total sum of all cache sizes. | |
| 56 int64_t GetStorageSize(); | |
| 57 | |
| 58 // Mark the cache as doomed. This will remove the cache metadata from the | |
|
jkarlin
2016/12/19 17:48:15
This needs a bit more documentation. For instance,
cmumford
2016/12/19 19:25:57
Done.
| |
| 59 // index. To completely delete the metadata via FinalizeDoomedCache, and use | |
|
jkarlin
2016/12/19 17:48:15
s/via/call/
cmumford
2016/12/19 19:25:57
Done.
| |
| 60 // ResetDoomedCache to restore the metadata to the index at the original | |
| 61 // position. | |
| 62 void DoomCache(const std::string& cache_name); | |
| 63 void FinalizeDoomedCache(); | |
| 64 void ResetDoomedCache(); | |
|
jkarlin
2016/12/19 17:48:15
RestoreDoomedCache? RevertDoomedCache?
cmumford
2016/12/19 19:25:57
I went with RestoreDoomedCache.
| |
| 65 | |
| 66 private: | |
| 67 void UpdateStorageSize(); | |
| 68 void ClearDoomedCache(); | |
| 69 | |
| 70 // Use a list to keep saved iterators valid during insert/erase. | |
| 71 // Note: ordered by cache creation. | |
| 72 std::list<CacheMetadata> ordered_cache_metadata_; | |
| 73 std::unordered_map<std::string, std::list<CacheMetadata>::iterator> | |
| 74 cache_metadata_map_; | |
| 75 | |
| 76 // The total size of all caches in this store. | |
| 77 int64_t storage_size_ = CacheStorage::kSizeUnknown; | |
| 78 | |
| 79 // The doomed cache metadata saved when calling DoomCache. | |
| 80 CacheMetadata doomed_cache_metadata_; | |
| 81 std::list<CacheMetadata>::iterator after_doomed_cache_metadata_; | |
| 82 bool has_doomed_cache_ = false; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(CacheStorageIndex); | |
| 85 }; | |
| 86 | |
| 87 } // namespace content | |
| 88 | |
| 89 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_INDEX_H_ | |
| OLD | NEW |