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" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 class CacheMetadata; | |
| 16 | |
|
jkarlin
2016/11/23 16:02:18
Class needs a comment.
cmumford
2016/11/29 18:10:21
Done. I also added some documentation to README.md
| |
| 17 class CONTENT_EXPORT CacheStorageIndex { | |
| 18 public: | |
| 19 struct CacheMetadata { | |
| 20 CacheMetadata(const std::string& name, int64_t size) | |
| 21 : name(name), size(size) {} | |
| 22 std::string name; | |
| 23 // The size (in bytes) of the cache. Set to CacheStorage::kSizeUnknown if | |
| 24 // size not known. | |
| 25 int64_t size; | |
| 26 }; | |
| 27 | |
| 28 CacheStorageIndex(const CacheStorageIndex& other); | |
| 29 CacheStorageIndex(); | |
| 30 ~CacheStorageIndex(); | |
| 31 | |
| 32 CacheStorageIndex& operator=(CacheStorageIndex&& rhs); | |
| 33 CacheStorageIndex& operator=(const CacheStorageIndex& rhs); | |
| 34 | |
| 35 void Insert(const CacheMetadata& cache_metadata); | |
| 36 void Delete(const std::string& cache_name); | |
| 37 | |
| 38 // Sets the cache size. Returns true if the new size is different than the | |
| 39 // current size else false. | |
| 40 bool SetCacheSize(const std::string& cache_name, int64_t size); | |
| 41 | |
| 42 // The cache was modified, increasing/decreasing cache size by |size_delta|. | |
| 43 void SetCacheSizeModified(const std::string& cache_name, int64_t size_delta); | |
| 44 | |
| 45 int64_t GetCacheSize(const std::string& cache_name) const; | |
| 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(); | |
| 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; | |
| 66 }; | |
| 67 | |
| 68 } // namespace content | |
| 69 | |
| 70 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_INDEX_H_ | |
| OLD | NEW |