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 #include "content/browser/cache_storage/cache_storage.h" | |
|
jkarlin
2016/12/14 14:19:56
new line above this line
cmumford
2016/12/15 22:29:14
Done.
| |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 class CacheMetadata; | |
| 16 | |
| 17 // CacheStorageIndex maintains an ordered list of metadata (CacheMetadata) | |
| 18 // for each cache owned by a CacheStorage object. This class is not thread safe, | |
| 19 // and is owned by the CacheStorage. | |
| 20 class CONTENT_EXPORT CacheStorageIndex { | |
| 21 public: | |
| 22 struct CacheMetadata { | |
| 23 CacheMetadata(const std::string& name, int64_t size) | |
| 24 : name(name), size(size) {} | |
| 25 std::string name; | |
| 26 // The size (in bytes) of the cache. Set to CacheStorage::kSizeUnknown if | |
| 27 // size not known. | |
| 28 int64_t size; | |
| 29 }; | |
| 30 | |
| 31 CacheStorageIndex(const CacheStorageIndex& other); | |
| 32 CacheStorageIndex(); | |
| 33 ~CacheStorageIndex(); | |
| 34 | |
| 35 CacheStorageIndex& operator=(CacheStorageIndex&& rhs); | |
| 36 CacheStorageIndex& operator=(const 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 int64_t GetCacheSize(const std::string& cache_name) const; | |
|
jkarlin
2016/12/14 14:19:56
Add comment of what it will return if the size is
cmumford
2016/12/15 22:29:15
Done.
| |
| 46 | |
| 47 const std::list<CacheMetadata>& ordered_cache_metadata() const { | |
| 48 return ordered_cache_metadata_; | |
| 49 } | |
| 50 | |
| 51 size_t num_entries() const { return ordered_cache_metadata_.size(); } | |
| 52 | |
| 53 int64_t GetStorageSize(); | |
|
jkarlin
2016/12/14 14:19:56
This needs a comment.
cmumford
2016/12/15 22:29:15
Done.
| |
| 54 | |
| 55 private: | |
| 56 void UpdateStorageSize(); | |
| 57 | |
| 58 // Use a list to keep saved iterators valid during insert/erase. | |
| 59 // Note: ordered by cache creation. | |
| 60 std::list<CacheMetadata> ordered_cache_metadata_; | |
| 61 std::unordered_map<std::string, std::list<CacheMetadata>::iterator> | |
| 62 cache_metadata_map_; | |
| 63 | |
| 64 // The total size of all caches in this store. | |
| 65 int64_t storage_size_ = CacheStorage::kSizeUnknown; | |
|
jkarlin
2016/12/14 14:19:56
Can you add a TODO to make this class DISALLOW_COP
cmumford
2016/12/15 22:29:15
Implemented, See DoomedCache, FinalizeDoomedCache,
| |
| 66 }; | |
| 67 | |
| 68 } // namespace content | |
| 69 | |
| 70 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_INDEX_H_ | |
| OLD | NEW |