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

Side by Side Diff: net/disk_cache/simple/simple_index.h

Issue 2922973003: RFC: use some in-memory state in SimpleCache to quickly cache-miss some CantConditionalize cases
Patch Set: - Implement support for oracle bytes in MockHttpCache, so the code actually gets exercised in tests… Created 3 years, 6 months 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 base::Time GetLastUsedTime() const; 51 base::Time GetLastUsedTime() const;
52 void SetLastUsedTime(const base::Time& last_used_time); 52 void SetLastUsedTime(const base::Time& last_used_time);
53 53
54 uint32_t RawTimeForSorting() const { 54 uint32_t RawTimeForSorting() const {
55 return last_used_time_seconds_since_epoch_; 55 return last_used_time_seconds_since_epoch_;
56 } 56 }
57 57
58 uint32_t GetEntrySize() const; 58 uint32_t GetEntrySize() const;
59 void SetEntrySize(base::StrictNumeric<uint32_t> entry_size); 59 void SetEntrySize(base::StrictNumeric<uint32_t> entry_size);
60 uint8_t GetOracleByte() const;
61 void SetOracleByte(uint8_t oracle_byte);
60 62
61 // Serialize the data into the provided pickle. 63 // Serialize the data into the provided pickle.
62 void Serialize(base::Pickle* pickle) const; 64 void Serialize(base::Pickle* pickle) const;
63 bool Deserialize(base::PickleIterator* it); 65 bool Deserialize(base::PickleIterator* it, bool has_oracle_byte);
64 66
65 static base::TimeDelta GetLowerEpsilonForTimeComparisons() { 67 static base::TimeDelta GetLowerEpsilonForTimeComparisons() {
66 return base::TimeDelta::FromSeconds(1); 68 return base::TimeDelta::FromSeconds(1);
67 } 69 }
68 static base::TimeDelta GetUpperEpsilonForTimeComparisons() { 70 static base::TimeDelta GetUpperEpsilonForTimeComparisons() {
69 return base::TimeDelta(); 71 return base::TimeDelta();
70 } 72 }
71 73
72 static const int kOnDiskSizeBytes = 16; 74 static const int kOnDiskSizeBytes = 16;
73 75
74 private: 76 private:
75 friend class SimpleIndexFileTest; 77 friend class SimpleIndexFileTest;
76 78
77 // There are tens of thousands of instances of EntryMetadata in memory, so the 79 // There are tens of thousands of instances of EntryMetadata in memory, so the
78 // size of each entry matters. Even when the values used to set these members 80 // size of each entry matters. Even when the values used to set these members
79 // are originally calculated as >32-bit types, the actual necessary size for 81 // are originally calculated as >32-bit types, the actual necessary size for
80 // each shouldn't exceed 32 bits, so we use 32-bit types here. 82 // each shouldn't exceed 32 bits, so we use 32-bit types here.
81 uint32_t last_used_time_seconds_since_epoch_; 83 uint32_t last_used_time_seconds_since_epoch_;
82 uint32_t entry_size_; // Storage size in bytes. 84 // Storage size in bytes... with oracle byte packed into lower 8 bites.
85 uint32_t entry_size_;
83 }; 86 };
84 static_assert(sizeof(EntryMetadata) == 8, "incorrect metadata size"); 87 static_assert(sizeof(EntryMetadata) == 8, "incorrect metadata size");
85 88
86 // This class is not Thread-safe. 89 // This class is not Thread-safe.
87 class NET_EXPORT_PRIVATE SimpleIndex 90 class NET_EXPORT_PRIVATE SimpleIndex
88 : public base::SupportsWeakPtr<SimpleIndex> { 91 : public base::SupportsWeakPtr<SimpleIndex> {
89 public: 92 public:
90 // Used in histograms. Please only add entries at the end. 93 // Used in histograms. Please only add entries at the end.
91 enum IndexInitMethod { 94 enum IndexInitMethod {
92 INITIALIZE_METHOD_RECOVERED = 0, 95 INITIALIZE_METHOD_RECOVERED = 0,
(...skipping 23 matching lines...) Expand all
116 119
117 void SetMaxSize(uint64_t max_bytes); 120 void SetMaxSize(uint64_t max_bytes);
118 uint64_t max_size() const { return max_size_; } 121 uint64_t max_size() const { return max_size_; }
119 122
120 void Insert(uint64_t entry_hash); 123 void Insert(uint64_t entry_hash);
121 void Remove(uint64_t entry_hash); 124 void Remove(uint64_t entry_hash);
122 125
123 // Check whether the index has the entry given the hash of its key. 126 // Check whether the index has the entry given the hash of its key.
124 bool Has(uint64_t entry_hash) const; 127 bool Has(uint64_t entry_hash) const;
125 128
129 // Like above, but also writes out the oracle byte (or 0) into |*oracle_byte|
130 // if returned true.
131 bool HasWithOracleByte(uint64_t entry_hash, uint8_t* oracle_byte);
132
126 // Update the last used time of the entry with the given key and return true 133 // Update the last used time of the entry with the given key and return true
127 // iff the entry exist in the index. 134 // iff the entry exist in the index.
128 bool UseIfExists(uint64_t entry_hash); 135 bool UseIfExists(uint64_t entry_hash);
129 136
130 void WriteToDisk(IndexWriteToDiskReason reason); 137 void WriteToDisk(IndexWriteToDiskReason reason);
131 138
132 // Update the size (in bytes) of an entry, in the metadata stored in the 139 // Update the size (in bytes) of an entry, in the metadata stored in the
133 // index. This should be the total disk-file size including all streams of the 140 // index. This should be the total disk-file size including all streams of the
134 // entry. 141 // entry.
135 bool UpdateEntrySize(uint64_t entry_hash, 142 bool UpdateEntrySize(uint64_t entry_hash,
136 base::StrictNumeric<uint32_t> entry_size); 143 base::StrictNumeric<uint32_t> entry_size);
144 void UpdateEntryOracleByte(uint64_t entry_hash, uint8_t oracle_byte);
137 145
138 using EntrySet = std::unordered_map<uint64_t, EntryMetadata>; 146 using EntrySet = std::unordered_map<uint64_t, EntryMetadata>;
139 147
140 static void InsertInEntrySet(uint64_t entry_hash, 148 static void InsertInEntrySet(uint64_t entry_hash,
141 const EntryMetadata& entry_metadata, 149 const EntryMetadata& entry_metadata,
142 EntrySet* entry_set); 150 EntrySet* entry_set);
143 151
144 // For use in tests only. Updates cache_size_, but will not start evictions 152 // For use in tests only. Updates cache_size_, but will not start evictions
145 // or adjust index writing time. Requires entry to not already be in the set. 153 // or adjust index writing time. Requires entry to not already be in the set.
146 void InsertEntryForTesting(uint64_t entry_hash, 154 void InsertEntryForTesting(uint64_t entry_hash,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 253
246 // Set to true when the app is on the background. When the app is in the 254 // Set to true when the app is on the background. When the app is in the
247 // background we can write the index much more frequently, to insure fresh 255 // background we can write the index much more frequently, to insure fresh
248 // index on next startup. 256 // index on next startup.
249 bool app_on_background_; 257 bool app_on_background_;
250 }; 258 };
251 259
252 } // namespace disk_cache 260 } // namespace disk_cache
253 261
254 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ 262 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698