| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 base::Time GetLastUsedTime() const; | 52 base::Time GetLastUsedTime() const; |
| 53 void SetLastUsedTime(const base::Time& last_used_time); | 53 void SetLastUsedTime(const base::Time& last_used_time); |
| 54 | 54 |
| 55 uint32_t RawTimeForSorting() const { | 55 uint32_t RawTimeForSorting() const { |
| 56 return last_used_time_seconds_since_epoch_; | 56 return last_used_time_seconds_since_epoch_; |
| 57 } | 57 } |
| 58 | 58 |
| 59 uint32_t GetEntrySize() const; | 59 uint32_t GetEntrySize() const; |
| 60 void SetEntrySize(base::StrictNumeric<uint32_t> entry_size); | 60 void SetEntrySize(base::StrictNumeric<uint32_t> entry_size); |
| 61 | 61 |
| 62 uint8_t GetInMemoryData() const { return in_memory_data_; } |
| 63 void SetInMemoryData(uint8_t val) { in_memory_data_ = val; } |
| 64 |
| 62 // Serialize the data into the provided pickle. | 65 // Serialize the data into the provided pickle. |
| 63 void Serialize(base::Pickle* pickle) const; | 66 void Serialize(base::Pickle* pickle) const; |
| 64 bool Deserialize(base::PickleIterator* it); | 67 bool Deserialize(base::PickleIterator* it, bool has_entry_in_memory_data); |
| 65 | 68 |
| 66 static base::TimeDelta GetLowerEpsilonForTimeComparisons() { | 69 static base::TimeDelta GetLowerEpsilonForTimeComparisons() { |
| 67 return base::TimeDelta::FromSeconds(1); | 70 return base::TimeDelta::FromSeconds(1); |
| 68 } | 71 } |
| 69 static base::TimeDelta GetUpperEpsilonForTimeComparisons() { | 72 static base::TimeDelta GetUpperEpsilonForTimeComparisons() { |
| 70 return base::TimeDelta(); | 73 return base::TimeDelta(); |
| 71 } | 74 } |
| 72 | 75 |
| 73 static const int kOnDiskSizeBytes = 16; | 76 static const int kOnDiskSizeBytes = 16; |
| 74 | 77 |
| 75 private: | 78 private: |
| 76 friend class SimpleIndexFileTest; | 79 friend class SimpleIndexFileTest; |
| 77 | 80 |
| 78 // There are tens of thousands of instances of EntryMetadata in memory, so the | 81 // There are tens of thousands of instances of EntryMetadata in memory, so the |
| 79 // size of each entry matters. Even when the values used to set these members | 82 // size of each entry matters. Even when the values used to set these members |
| 80 // are originally calculated as >32-bit types, the actual necessary size for | 83 // are originally calculated as >32-bit types, the actual necessary size for |
| 81 // each shouldn't exceed 32 bits, so we use 32-bit types here. | 84 // each shouldn't exceed 32 bits, so we use 32-bit types here. |
| 82 uint32_t last_used_time_seconds_since_epoch_; | 85 uint32_t last_used_time_seconds_since_epoch_; |
| 83 uint32_t entry_size_; // Storage size in bytes. | 86 uint32_t entry_size_256b_chunks_ : 24; // in 256-byte blocks, rounded up. |
| 87 uint32_t in_memory_data_ : 8; |
| 84 }; | 88 }; |
| 85 static_assert(sizeof(EntryMetadata) == 8, "incorrect metadata size"); | 89 static_assert(sizeof(EntryMetadata) == 8, "incorrect metadata size"); |
| 86 | 90 |
| 87 // This class is not Thread-safe. | 91 // This class is not Thread-safe. |
| 88 class NET_EXPORT_PRIVATE SimpleIndex | 92 class NET_EXPORT_PRIVATE SimpleIndex |
| 89 : public base::SupportsWeakPtr<SimpleIndex> { | 93 : public base::SupportsWeakPtr<SimpleIndex> { |
| 90 public: | 94 public: |
| 91 // Used in histograms. Please only add entries at the end. | 95 // Used in histograms. Please only add entries at the end. |
| 92 enum IndexInitMethod { | 96 enum IndexInitMethod { |
| 93 INITIALIZE_METHOD_RECOVERED = 0, | 97 INITIALIZE_METHOD_RECOVERED = 0, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 122 void Insert(uint64_t entry_hash); | 126 void Insert(uint64_t entry_hash); |
| 123 void Remove(uint64_t entry_hash); | 127 void Remove(uint64_t entry_hash); |
| 124 | 128 |
| 125 // Check whether the index has the entry given the hash of its key. | 129 // Check whether the index has the entry given the hash of its key. |
| 126 bool Has(uint64_t entry_hash) const; | 130 bool Has(uint64_t entry_hash) const; |
| 127 | 131 |
| 128 // Update the last used time of the entry with the given key and return true | 132 // Update the last used time of the entry with the given key and return true |
| 129 // iff the entry exist in the index. | 133 // iff the entry exist in the index. |
| 130 bool UseIfExists(uint64_t entry_hash); | 134 bool UseIfExists(uint64_t entry_hash); |
| 131 | 135 |
| 136 uint8_t GetEntryInMemoryData(uint64_t entry_hash) const; |
| 137 void SetEntryInMemoryData(uint64_t entry_hash, uint8_t value); |
| 138 |
| 132 void WriteToDisk(IndexWriteToDiskReason reason); | 139 void WriteToDisk(IndexWriteToDiskReason reason); |
| 133 | 140 |
| 134 // Update the size (in bytes) of an entry, in the metadata stored in the | 141 // Update the size (in bytes) of an entry, in the metadata stored in the |
| 135 // index. This should be the total disk-file size including all streams of the | 142 // index. This should be the total disk-file size including all streams of the |
| 136 // entry. | 143 // entry. |
| 137 bool UpdateEntrySize(uint64_t entry_hash, | 144 bool UpdateEntrySize(uint64_t entry_hash, |
| 138 base::StrictNumeric<uint32_t> entry_size); | 145 base::StrictNumeric<uint32_t> entry_size); |
| 139 | 146 |
| 140 using EntrySet = std::unordered_map<uint64_t, EntryMetadata>; | 147 using EntrySet = std::unordered_map<uint64_t, EntryMetadata>; |
| 141 | 148 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 256 |
| 250 // Set to true when the app is on the background. When the app is in the | 257 // Set to true when the app is on the background. When the app is in the |
| 251 // background we can write the index much more frequently, to insure fresh | 258 // background we can write the index much more frequently, to insure fresh |
| 252 // index on next startup. | 259 // index on next startup. |
| 253 bool app_on_background_; | 260 bool app_on_background_; |
| 254 }; | 261 }; |
| 255 | 262 |
| 256 } // namespace disk_cache | 263 } // namespace disk_cache |
| 257 | 264 |
| 258 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 265 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
| OLD | NEW |