Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 60 |
| 61 uint8_t GetMemoryEntryData() const { return memory_entry_data_; } | |
| 62 void SetMemoryEntryData(uint8_t val) { memory_entry_data_ = val; } | |
| 63 | |
| 61 // Serialize the data into the provided pickle. | 64 // Serialize the data into the provided pickle. |
| 62 void Serialize(base::Pickle* pickle) const; | 65 void Serialize(base::Pickle* pickle) const; |
| 63 bool Deserialize(base::PickleIterator* it); | 66 bool Deserialize(base::PickleIterator* it, bool has_memory_entry_data); |
| 64 | 67 |
| 65 static base::TimeDelta GetLowerEpsilonForTimeComparisons() { | 68 static base::TimeDelta GetLowerEpsilonForTimeComparisons() { |
| 66 return base::TimeDelta::FromSeconds(1); | 69 return base::TimeDelta::FromSeconds(1); |
| 67 } | 70 } |
| 68 static base::TimeDelta GetUpperEpsilonForTimeComparisons() { | 71 static base::TimeDelta GetUpperEpsilonForTimeComparisons() { |
| 69 return base::TimeDelta(); | 72 return base::TimeDelta(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 static const int kOnDiskSizeBytes = 16; | 75 static const int kOnDiskSizeBytes = 16; |
| 73 | 76 |
| 74 private: | 77 private: |
| 75 friend class SimpleIndexFileTest; | 78 friend class SimpleIndexFileTest; |
| 76 | 79 |
| 77 // There are tens of thousands of instances of EntryMetadata in memory, so the | 80 // 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 | 81 // 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 | 82 // 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. | 83 // each shouldn't exceed 32 bits, so we use 32-bit types here. |
| 81 uint32_t last_used_time_seconds_since_epoch_; | 84 uint32_t last_used_time_seconds_since_epoch_; |
| 82 uint32_t entry_size_; // Storage size in bytes. | 85 uint32_t entry_size_ : 24; // in 256-byte blocks. |
|
gavinp
2017/08/04 18:42:54
pasko elsewhere suggests renaming this member. +1
Maks Orlovich
2017/08/23 19:29:06
Went with entry_size_256b_chunks_, since I think r
| |
| 86 uint32_t memory_entry_data_ : 8; | |
| 83 }; | 87 }; |
| 84 static_assert(sizeof(EntryMetadata) == 8, "incorrect metadata size"); | 88 static_assert(sizeof(EntryMetadata) == 8, "incorrect metadata size"); |
| 85 | 89 |
| 86 // This class is not Thread-safe. | 90 // This class is not Thread-safe. |
| 87 class NET_EXPORT_PRIVATE SimpleIndex | 91 class NET_EXPORT_PRIVATE SimpleIndex |
| 88 : public base::SupportsWeakPtr<SimpleIndex> { | 92 : public base::SupportsWeakPtr<SimpleIndex> { |
| 89 public: | 93 public: |
| 90 // Used in histograms. Please only add entries at the end. | 94 // Used in histograms. Please only add entries at the end. |
| 91 enum IndexInitMethod { | 95 enum IndexInitMethod { |
| 92 INITIALIZE_METHOD_RECOVERED = 0, | 96 INITIALIZE_METHOD_RECOVERED = 0, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 120 void Insert(uint64_t entry_hash); | 124 void Insert(uint64_t entry_hash); |
| 121 void Remove(uint64_t entry_hash); | 125 void Remove(uint64_t entry_hash); |
| 122 | 126 |
| 123 // Check whether the index has the entry given the hash of its key. | 127 // Check whether the index has the entry given the hash of its key. |
| 124 bool Has(uint64_t entry_hash) const; | 128 bool Has(uint64_t entry_hash) const; |
| 125 | 129 |
| 126 // Update the last used time of the entry with the given key and return true | 130 // Update the last used time of the entry with the given key and return true |
| 127 // iff the entry exist in the index. | 131 // iff the entry exist in the index. |
| 128 bool UseIfExists(uint64_t entry_hash); | 132 bool UseIfExists(uint64_t entry_hash); |
| 129 | 133 |
| 134 uint8_t GetMemoryEntryData(uint64_t entry_hash) const; | |
| 135 void SetMemoryEntryData(uint64_t entry_hash, uint8_t value); | |
| 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); |
| 137 | 144 |
| 138 using EntrySet = std::unordered_map<uint64_t, EntryMetadata>; | 145 using EntrySet = std::unordered_map<uint64_t, EntryMetadata>; |
| 139 | 146 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 | 252 |
| 246 // Set to true when the app is on the background. When the app is in the | 253 // 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 | 254 // background we can write the index much more frequently, to insure fresh |
| 248 // index on next startup. | 255 // index on next startup. |
| 249 bool app_on_background_; | 256 bool app_on_background_; |
| 250 }; | 257 }; |
| 251 | 258 |
| 252 } // namespace disk_cache | 259 } // namespace disk_cache |
| 253 | 260 |
| 254 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 261 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
| OLD | NEW |