Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(725)

Side by Side Diff: content/browser/cache_storage/cache_storage_index.h

Issue 2416713002: Write out CacheStorageCache size to index file. (Closed)
Patch Set: Scheduling index writes + lots of other fixes. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
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 // The cache was modified, increasing/decreasing cache size by |size_delta|.
46 void SetCacheSizeModified(const std::string& cache_name, int64_t size_delta);
47
48 int64_t GetCacheSize(const std::string& cache_name) const;
49
50 const std::list<CacheMetadata>& ordered_cache_metadata() const {
51 return ordered_cache_metadata_;
52 }
53
54 size_t num_entries() const { return ordered_cache_metadata_.size(); }
55
56 int64_t GetStorageSize();
57
58 private:
59 void UpdateStorageSize();
60
61 // Use a list to keep saved iterators valid during insert/erase.
62 // Note: ordered by cache creation.
63 std::list<CacheMetadata> ordered_cache_metadata_;
64 std::unordered_map<std::string, std::list<CacheMetadata>::iterator>
65 cache_metadata_map_;
66
67 // The total size of all caches in this store.
68 int64_t storage_size_ = CacheStorage::kSizeUnknown;
69 };
70
71 } // namespace content
72
73 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_INDEX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698