| 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_SYNCHRONOUS_ENTRY_H_ | 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
| 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ | 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <algorithm> | 10 #include <algorithm> |
| 9 #include <map> | 11 #include <map> |
| 10 #include <string> | 12 #include <string> |
| 11 #include <utility> | 13 #include <utility> |
| 12 #include <vector> | 14 #include <vector> |
| 13 | 15 |
| 14 #include "base/files/file.h" | 16 #include "base/files/file.h" |
| 15 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 16 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 29 | 31 |
| 30 class SimpleSynchronousEntry; | 32 class SimpleSynchronousEntry; |
| 31 | 33 |
| 32 // This class handles the passing of data about the entry between | 34 // This class handles the passing of data about the entry between |
| 33 // SimpleEntryImplementation and SimpleSynchronousEntry and the computation of | 35 // SimpleEntryImplementation and SimpleSynchronousEntry and the computation of |
| 34 // file offsets based on the data size for all streams. | 36 // file offsets based on the data size for all streams. |
| 35 class NET_EXPORT_PRIVATE SimpleEntryStat { | 37 class NET_EXPORT_PRIVATE SimpleEntryStat { |
| 36 public: | 38 public: |
| 37 SimpleEntryStat(base::Time last_used, | 39 SimpleEntryStat(base::Time last_used, |
| 38 base::Time last_modified, | 40 base::Time last_modified, |
| 39 const int32 data_size[], | 41 const int32_t data_size[], |
| 40 const int32 sparse_data_size); | 42 const int32_t sparse_data_size); |
| 41 | 43 |
| 42 int GetOffsetInFile(const std::string& key, | 44 int GetOffsetInFile(const std::string& key, |
| 43 int offset, | 45 int offset, |
| 44 int stream_index) const; | 46 int stream_index) const; |
| 45 int GetEOFOffsetInFile(const std::string& key, int stream_index) const; | 47 int GetEOFOffsetInFile(const std::string& key, int stream_index) const; |
| 46 int GetLastEOFOffsetInFile(const std::string& key, int file_index) const; | 48 int GetLastEOFOffsetInFile(const std::string& key, int file_index) const; |
| 47 int64 GetFileSize(const std::string& key, int file_index) const; | 49 int64_t GetFileSize(const std::string& key, int file_index) const; |
| 48 | 50 |
| 49 base::Time last_used() const { return last_used_; } | 51 base::Time last_used() const { return last_used_; } |
| 50 base::Time last_modified() const { return last_modified_; } | 52 base::Time last_modified() const { return last_modified_; } |
| 51 void set_last_used(base::Time last_used) { last_used_ = last_used; } | 53 void set_last_used(base::Time last_used) { last_used_ = last_used; } |
| 52 void set_last_modified(base::Time last_modified) { | 54 void set_last_modified(base::Time last_modified) { |
| 53 last_modified_ = last_modified; | 55 last_modified_ = last_modified; |
| 54 } | 56 } |
| 55 | 57 |
| 56 int32 data_size(int stream_index) const { return data_size_[stream_index]; } | 58 int32_t data_size(int stream_index) const { return data_size_[stream_index]; } |
| 57 void set_data_size(int stream_index, int data_size) { | 59 void set_data_size(int stream_index, int data_size) { |
| 58 data_size_[stream_index] = data_size; | 60 data_size_[stream_index] = data_size; |
| 59 } | 61 } |
| 60 | 62 |
| 61 int32 sparse_data_size() const { return sparse_data_size_; } | 63 int32_t sparse_data_size() const { return sparse_data_size_; } |
| 62 void set_sparse_data_size(int32 sparse_data_size) { | 64 void set_sparse_data_size(int32_t sparse_data_size) { |
| 63 sparse_data_size_ = sparse_data_size; | 65 sparse_data_size_ = sparse_data_size; |
| 64 } | 66 } |
| 65 | 67 |
| 66 private: | 68 private: |
| 67 base::Time last_used_; | 69 base::Time last_used_; |
| 68 base::Time last_modified_; | 70 base::Time last_modified_; |
| 69 int32 data_size_[kSimpleEntryStreamCount]; | 71 int32_t data_size_[kSimpleEntryStreamCount]; |
| 70 int32 sparse_data_size_; | 72 int32_t sparse_data_size_; |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 struct SimpleEntryCreationResults { | 75 struct SimpleEntryCreationResults { |
| 74 explicit SimpleEntryCreationResults(SimpleEntryStat entry_stat); | 76 explicit SimpleEntryCreationResults(SimpleEntryStat entry_stat); |
| 75 ~SimpleEntryCreationResults(); | 77 ~SimpleEntryCreationResults(); |
| 76 | 78 |
| 77 SimpleSynchronousEntry* sync_entry; | 79 SimpleSynchronousEntry* sync_entry; |
| 78 scoped_refptr<net::GrowableIOBuffer> stream_0_data; | 80 scoped_refptr<net::GrowableIOBuffer> stream_0_data; |
| 79 SimpleEntryStat entry_stat; | 81 SimpleEntryStat entry_stat; |
| 80 uint32 stream_0_crc32; | 82 uint32_t stream_0_crc32; |
| 81 int result; | 83 int result; |
| 82 }; | 84 }; |
| 83 | 85 |
| 84 // Worker thread interface to the very simple cache. This interface is not | 86 // Worker thread interface to the very simple cache. This interface is not |
| 85 // thread safe, and callers must ensure that it is only ever accessed from | 87 // thread safe, and callers must ensure that it is only ever accessed from |
| 86 // a single thread between synchronization points. | 88 // a single thread between synchronization points. |
| 87 class SimpleSynchronousEntry { | 89 class SimpleSynchronousEntry { |
| 88 public: | 90 public: |
| 89 struct CRCRecord { | 91 struct CRCRecord { |
| 90 CRCRecord(); | 92 CRCRecord(); |
| 91 CRCRecord(int index_p, bool has_crc32_p, uint32 data_crc32_p); | 93 CRCRecord(int index_p, bool has_crc32_p, uint32_t data_crc32_p); |
| 92 | 94 |
| 93 int index; | 95 int index; |
| 94 bool has_crc32; | 96 bool has_crc32; |
| 95 uint32 data_crc32; | 97 uint32_t data_crc32; |
| 96 }; | 98 }; |
| 97 | 99 |
| 98 struct EntryOperationData { | 100 struct EntryOperationData { |
| 99 EntryOperationData(int index_p, int offset_p, int buf_len_p); | 101 EntryOperationData(int index_p, int offset_p, int buf_len_p); |
| 100 EntryOperationData(int index_p, | 102 EntryOperationData(int index_p, |
| 101 int offset_p, | 103 int offset_p, |
| 102 int buf_len_p, | 104 int buf_len_p, |
| 103 bool truncate_p, | 105 bool truncate_p, |
| 104 bool doomed_p); | 106 bool doomed_p); |
| 105 EntryOperationData(int64 sparse_offset_p, int buf_len_p); | 107 EntryOperationData(int64_t sparse_offset_p, int buf_len_p); |
| 106 | 108 |
| 107 int index; | 109 int index; |
| 108 int offset; | 110 int offset; |
| 109 int64 sparse_offset; | 111 int64_t sparse_offset; |
| 110 int buf_len; | 112 int buf_len; |
| 111 bool truncate; | 113 bool truncate; |
| 112 bool doomed; | 114 bool doomed; |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 static void OpenEntry(net::CacheType cache_type, | 117 static void OpenEntry(net::CacheType cache_type, |
| 116 const base::FilePath& path, | 118 const base::FilePath& path, |
| 117 uint64 entry_hash, | 119 uint64_t entry_hash, |
| 118 bool had_index, | 120 bool had_index, |
| 119 SimpleEntryCreationResults* out_results); | 121 SimpleEntryCreationResults* out_results); |
| 120 | 122 |
| 121 static void CreateEntry(net::CacheType cache_type, | 123 static void CreateEntry(net::CacheType cache_type, |
| 122 const base::FilePath& path, | 124 const base::FilePath& path, |
| 123 const std::string& key, | 125 const std::string& key, |
| 124 uint64 entry_hash, | 126 uint64_t entry_hash, |
| 125 bool had_index, | 127 bool had_index, |
| 126 SimpleEntryCreationResults* out_results); | 128 SimpleEntryCreationResults* out_results); |
| 127 | 129 |
| 128 // Deletes an entry from the file system without affecting the state of the | 130 // Deletes an entry from the file system without affecting the state of the |
| 129 // corresponding instance, if any (allowing operations to continue to be | 131 // corresponding instance, if any (allowing operations to continue to be |
| 130 // executed through that instance). Returns a net error code. | 132 // executed through that instance). Returns a net error code. |
| 131 static int DoomEntry(const base::FilePath& path, | 133 static int DoomEntry(const base::FilePath& path, uint64_t entry_hash); |
| 132 uint64 entry_hash); | |
| 133 | 134 |
| 134 // Like |DoomEntry()| above. Deletes all entries corresponding to the | 135 // Like |DoomEntry()| above. Deletes all entries corresponding to the |
| 135 // |key_hashes|. Succeeds only when all entries are deleted. Returns a net | 136 // |key_hashes|. Succeeds only when all entries are deleted. Returns a net |
| 136 // error code. | 137 // error code. |
| 137 static int DoomEntrySet(const std::vector<uint64>* key_hashes, | 138 static int DoomEntrySet(const std::vector<uint64_t>* key_hashes, |
| 138 const base::FilePath& path); | 139 const base::FilePath& path); |
| 139 | 140 |
| 140 // N.B. ReadData(), WriteData(), CheckEOFRecord() and Close() may block on IO. | 141 // N.B. ReadData(), WriteData(), CheckEOFRecord() and Close() may block on IO. |
| 141 void ReadData(const EntryOperationData& in_entry_op, | 142 void ReadData(const EntryOperationData& in_entry_op, |
| 142 net::IOBuffer* out_buf, | 143 net::IOBuffer* out_buf, |
| 143 uint32* out_crc32, | 144 uint32_t* out_crc32, |
| 144 SimpleEntryStat* entry_stat, | 145 SimpleEntryStat* entry_stat, |
| 145 int* out_result) const; | 146 int* out_result) const; |
| 146 void WriteData(const EntryOperationData& in_entry_op, | 147 void WriteData(const EntryOperationData& in_entry_op, |
| 147 net::IOBuffer* in_buf, | 148 net::IOBuffer* in_buf, |
| 148 SimpleEntryStat* out_entry_stat, | 149 SimpleEntryStat* out_entry_stat, |
| 149 int* out_result); | 150 int* out_result); |
| 150 void CheckEOFRecord(int index, | 151 void CheckEOFRecord(int index, |
| 151 const SimpleEntryStat& entry_stat, | 152 const SimpleEntryStat& entry_stat, |
| 152 uint32 expected_crc32, | 153 uint32_t expected_crc32, |
| 153 int* out_result) const; | 154 int* out_result) const; |
| 154 | 155 |
| 155 void ReadSparseData(const EntryOperationData& in_entry_op, | 156 void ReadSparseData(const EntryOperationData& in_entry_op, |
| 156 net::IOBuffer* out_buf, | 157 net::IOBuffer* out_buf, |
| 157 base::Time* out_last_used, | 158 base::Time* out_last_used, |
| 158 int* out_result); | 159 int* out_result); |
| 159 void WriteSparseData(const EntryOperationData& in_entry_op, | 160 void WriteSparseData(const EntryOperationData& in_entry_op, |
| 160 net::IOBuffer* in_buf, | 161 net::IOBuffer* in_buf, |
| 161 uint64 max_sparse_data_size, | 162 uint64_t max_sparse_data_size, |
| 162 SimpleEntryStat* out_entry_stat, | 163 SimpleEntryStat* out_entry_stat, |
| 163 int* out_result); | 164 int* out_result); |
| 164 void GetAvailableRange(const EntryOperationData& in_entry_op, | 165 void GetAvailableRange(const EntryOperationData& in_entry_op, |
| 165 int64* out_start, | 166 int64_t* out_start, |
| 166 int* out_result); | 167 int* out_result); |
| 167 | 168 |
| 168 // Close all streams, and add write EOF records to streams indicated by the | 169 // Close all streams, and add write EOF records to streams indicated by the |
| 169 // CRCRecord entries in |crc32s_to_write|. | 170 // CRCRecord entries in |crc32s_to_write|. |
| 170 void Close(const SimpleEntryStat& entry_stat, | 171 void Close(const SimpleEntryStat& entry_stat, |
| 171 scoped_ptr<std::vector<CRCRecord> > crc32s_to_write, | 172 scoped_ptr<std::vector<CRCRecord> > crc32s_to_write, |
| 172 net::GrowableIOBuffer* stream_0_data); | 173 net::GrowableIOBuffer* stream_0_data); |
| 173 | 174 |
| 174 const base::FilePath& path() const { return path_; } | 175 const base::FilePath& path() const { return path_; } |
| 175 std::string key() const { return key_; } | 176 std::string key() const { return key_; } |
| 176 | 177 |
| 177 private: | 178 private: |
| 178 enum CreateEntryResult { | 179 enum CreateEntryResult { |
| 179 CREATE_ENTRY_SUCCESS = 0, | 180 CREATE_ENTRY_SUCCESS = 0, |
| 180 CREATE_ENTRY_PLATFORM_FILE_ERROR = 1, | 181 CREATE_ENTRY_PLATFORM_FILE_ERROR = 1, |
| 181 CREATE_ENTRY_CANT_WRITE_HEADER = 2, | 182 CREATE_ENTRY_CANT_WRITE_HEADER = 2, |
| 182 CREATE_ENTRY_CANT_WRITE_KEY = 3, | 183 CREATE_ENTRY_CANT_WRITE_KEY = 3, |
| 183 CREATE_ENTRY_MAX = 4, | 184 CREATE_ENTRY_MAX = 4, |
| 184 }; | 185 }; |
| 185 | 186 |
| 186 enum FileRequired { | 187 enum FileRequired { |
| 187 FILE_NOT_REQUIRED, | 188 FILE_NOT_REQUIRED, |
| 188 FILE_REQUIRED | 189 FILE_REQUIRED |
| 189 }; | 190 }; |
| 190 | 191 |
| 191 struct SparseRange { | 192 struct SparseRange { |
| 192 int64 offset; | 193 int64_t offset; |
| 193 int64 length; | 194 int64_t length; |
| 194 uint32 data_crc32; | 195 uint32_t data_crc32; |
| 195 int64 file_offset; | 196 int64_t file_offset; |
| 196 | 197 |
| 197 bool operator<(const SparseRange& other) const { | 198 bool operator<(const SparseRange& other) const { |
| 198 return offset < other.offset; | 199 return offset < other.offset; |
| 199 } | 200 } |
| 200 }; | 201 }; |
| 201 | 202 |
| 202 SimpleSynchronousEntry( | 203 SimpleSynchronousEntry(net::CacheType cache_type, |
| 203 net::CacheType cache_type, | 204 const base::FilePath& path, |
| 204 const base::FilePath& path, | 205 const std::string& key, |
| 205 const std::string& key, | 206 uint64_t entry_hash); |
| 206 uint64 entry_hash); | |
| 207 | 207 |
| 208 // Like Entry, the SimpleSynchronousEntry self releases when Close() is | 208 // Like Entry, the SimpleSynchronousEntry self releases when Close() is |
| 209 // called. | 209 // called. |
| 210 ~SimpleSynchronousEntry(); | 210 ~SimpleSynchronousEntry(); |
| 211 | 211 |
| 212 // Tries to open one of the cache entry files. Succeeds if the open succeeds | 212 // Tries to open one of the cache entry files. Succeeds if the open succeeds |
| 213 // or if the file was not found and is allowed to be omitted if the | 213 // or if the file was not found and is allowed to be omitted if the |
| 214 // corresponding stream is empty. | 214 // corresponding stream is empty. |
| 215 bool MaybeOpenFile(int file_index, | 215 bool MaybeOpenFile(int file_index, |
| 216 base::File::Error* out_error); | 216 base::File::Error* out_error); |
| 217 // Creates one of the cache entry files if necessary. If the file is allowed | 217 // Creates one of the cache entry files if necessary. If the file is allowed |
| 218 // to be omitted if the corresponding stream is empty, and if |file_required| | 218 // to be omitted if the corresponding stream is empty, and if |file_required| |
| 219 // is FILE_NOT_REQUIRED, then the file is not created; otherwise, it is. | 219 // is FILE_NOT_REQUIRED, then the file is not created; otherwise, it is. |
| 220 bool MaybeCreateFile(int file_index, | 220 bool MaybeCreateFile(int file_index, |
| 221 FileRequired file_required, | 221 FileRequired file_required, |
| 222 base::File::Error* out_error); | 222 base::File::Error* out_error); |
| 223 bool OpenFiles(bool had_index, | 223 bool OpenFiles(bool had_index, |
| 224 SimpleEntryStat* out_entry_stat); | 224 SimpleEntryStat* out_entry_stat); |
| 225 bool CreateFiles(bool had_index, | 225 bool CreateFiles(bool had_index, |
| 226 SimpleEntryStat* out_entry_stat); | 226 SimpleEntryStat* out_entry_stat); |
| 227 void CloseFile(int index); | 227 void CloseFile(int index); |
| 228 void CloseFiles(); | 228 void CloseFiles(); |
| 229 | 229 |
| 230 // Returns a net error, i.e. net::OK on success. |had_index| is passed | 230 // Returns a net error, i.e. net::OK on success. |had_index| is passed |
| 231 // from the main entry for metrics purposes, and is true if the index was | 231 // from the main entry for metrics purposes, and is true if the index was |
| 232 // initialized when the open operation began. | 232 // initialized when the open operation began. |
| 233 int InitializeForOpen(bool had_index, | 233 int InitializeForOpen(bool had_index, |
| 234 SimpleEntryStat* out_entry_stat, | 234 SimpleEntryStat* out_entry_stat, |
| 235 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, | 235 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, |
| 236 uint32* out_stream_0_crc32); | 236 uint32_t* out_stream_0_crc32); |
| 237 | 237 |
| 238 // Writes the header and key to a newly-created stream file. |index| is the | 238 // Writes the header and key to a newly-created stream file. |index| is the |
| 239 // index of the stream. Returns true on success; returns false and sets | 239 // index of the stream. Returns true on success; returns false and sets |
| 240 // |*out_result| on failure. | 240 // |*out_result| on failure. |
| 241 bool InitializeCreatedFile(int index, CreateEntryResult* out_result); | 241 bool InitializeCreatedFile(int index, CreateEntryResult* out_result); |
| 242 | 242 |
| 243 // Returns a net error, including net::OK on success and net::FILE_EXISTS | 243 // Returns a net error, including net::OK on success and net::FILE_EXISTS |
| 244 // when the entry already exists. |had_index| is passed from the main entry | 244 // when the entry already exists. |had_index| is passed from the main entry |
| 245 // for metrics purposes, and is true if the index was initialized when the | 245 // for metrics purposes, and is true if the index was initialized when the |
| 246 // create operation began. | 246 // create operation began. |
| 247 int InitializeForCreate(bool had_index, SimpleEntryStat* out_entry_stat); | 247 int InitializeForCreate(bool had_index, SimpleEntryStat* out_entry_stat); |
| 248 | 248 |
| 249 // Allocates and fills a buffer with stream 0 data in |stream_0_data|, then | 249 // Allocates and fills a buffer with stream 0 data in |stream_0_data|, then |
| 250 // checks its crc32. | 250 // checks its crc32. |
| 251 int ReadAndValidateStream0( | 251 int ReadAndValidateStream0( |
| 252 int total_data_size, | 252 int total_data_size, |
| 253 SimpleEntryStat* out_entry_stat, | 253 SimpleEntryStat* out_entry_stat, |
| 254 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, | 254 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, |
| 255 uint32* out_stream_0_crc32) const; | 255 uint32_t* out_stream_0_crc32) const; |
| 256 | 256 |
| 257 int GetEOFRecordData(int index, | 257 int GetEOFRecordData(int index, |
| 258 const SimpleEntryStat& entry_stat, | 258 const SimpleEntryStat& entry_stat, |
| 259 bool* out_has_crc32, | 259 bool* out_has_crc32, |
| 260 uint32* out_crc32, | 260 uint32_t* out_crc32, |
| 261 int* out_data_size) const; | 261 int* out_data_size) const; |
| 262 void Doom() const; | 262 void Doom() const; |
| 263 | 263 |
| 264 // Opens the sparse data file and scans it if it exists. | 264 // Opens the sparse data file and scans it if it exists. |
| 265 bool OpenSparseFileIfExists(int32* out_sparse_data_size); | 265 bool OpenSparseFileIfExists(int32_t* out_sparse_data_size); |
| 266 | 266 |
| 267 // Creates and initializes the sparse data file. | 267 // Creates and initializes the sparse data file. |
| 268 bool CreateSparseFile(); | 268 bool CreateSparseFile(); |
| 269 | 269 |
| 270 // Closes the sparse data file. | 270 // Closes the sparse data file. |
| 271 void CloseSparseFile(); | 271 void CloseSparseFile(); |
| 272 | 272 |
| 273 // Writes the header to the (newly-created) sparse file. | 273 // Writes the header to the (newly-created) sparse file. |
| 274 bool InitializeSparseFile(); | 274 bool InitializeSparseFile(); |
| 275 | 275 |
| 276 // Removes all but the header of the sparse file. | 276 // Removes all but the header of the sparse file. |
| 277 bool TruncateSparseFile(); | 277 bool TruncateSparseFile(); |
| 278 | 278 |
| 279 // Scans the existing ranges in the sparse file. Populates |sparse_ranges_| | 279 // Scans the existing ranges in the sparse file. Populates |sparse_ranges_| |
| 280 // and sets |*out_sparse_data_size| to the total size of all the ranges (not | 280 // and sets |*out_sparse_data_size| to the total size of all the ranges (not |
| 281 // including headers). | 281 // including headers). |
| 282 bool ScanSparseFile(int32* out_sparse_data_size); | 282 bool ScanSparseFile(int32_t* out_sparse_data_size); |
| 283 | 283 |
| 284 // Reads from a single sparse range. If asked to read the entire range, also | 284 // Reads from a single sparse range. If asked to read the entire range, also |
| 285 // verifies the CRC32. | 285 // verifies the CRC32. |
| 286 bool ReadSparseRange(const SparseRange* range, | 286 bool ReadSparseRange(const SparseRange* range, |
| 287 int offset, int len, char* buf); | 287 int offset, int len, char* buf); |
| 288 | 288 |
| 289 // Writes to a single (existing) sparse range. If asked to write the entire | 289 // Writes to a single (existing) sparse range. If asked to write the entire |
| 290 // range, also updates the CRC32; otherwise, invalidates it. | 290 // range, also updates the CRC32; otherwise, invalidates it. |
| 291 bool WriteSparseRange(SparseRange* range, | 291 bool WriteSparseRange(SparseRange* range, |
| 292 int offset, int len, const char* buf); | 292 int offset, int len, const char* buf); |
| 293 | 293 |
| 294 // Appends a new sparse range to the sparse data file. | 294 // Appends a new sparse range to the sparse data file. |
| 295 bool AppendSparseRange(int64 offset, int len, const char* buf); | 295 bool AppendSparseRange(int64_t offset, int len, const char* buf); |
| 296 | 296 |
| 297 static bool DeleteFileForEntryHash(const base::FilePath& path, | 297 static bool DeleteFileForEntryHash(const base::FilePath& path, |
| 298 uint64 entry_hash, | 298 uint64_t entry_hash, |
| 299 int file_index); | 299 int file_index); |
| 300 static bool DeleteFilesForEntryHash(const base::FilePath& path, | 300 static bool DeleteFilesForEntryHash(const base::FilePath& path, |
| 301 uint64 entry_hash); | 301 uint64_t entry_hash); |
| 302 | 302 |
| 303 void RecordSyncCreateResult(CreateEntryResult result, bool had_index); | 303 void RecordSyncCreateResult(CreateEntryResult result, bool had_index); |
| 304 | 304 |
| 305 base::FilePath GetFilenameFromFileIndex(int file_index); | 305 base::FilePath GetFilenameFromFileIndex(int file_index); |
| 306 | 306 |
| 307 bool sparse_file_open() const { | 307 bool sparse_file_open() const { |
| 308 return sparse_file_.IsValid(); | 308 return sparse_file_.IsValid(); |
| 309 } | 309 } |
| 310 | 310 |
| 311 const net::CacheType cache_type_; | 311 const net::CacheType cache_type_; |
| 312 const base::FilePath path_; | 312 const base::FilePath path_; |
| 313 const uint64 entry_hash_; | 313 const uint64_t entry_hash_; |
| 314 std::string key_; | 314 std::string key_; |
| 315 | 315 |
| 316 bool have_open_files_; | 316 bool have_open_files_; |
| 317 bool initialized_; | 317 bool initialized_; |
| 318 | 318 |
| 319 base::File files_[kSimpleEntryFileCount]; | 319 base::File files_[kSimpleEntryFileCount]; |
| 320 | 320 |
| 321 // True if the corresponding stream is empty and therefore no on-disk file | 321 // True if the corresponding stream is empty and therefore no on-disk file |
| 322 // was created to store it. | 322 // was created to store it. |
| 323 bool empty_file_omitted_[kSimpleEntryFileCount]; | 323 bool empty_file_omitted_[kSimpleEntryFileCount]; |
| 324 | 324 |
| 325 typedef std::map<int64, SparseRange> SparseRangeOffsetMap; | 325 typedef std::map<int64_t, SparseRange> SparseRangeOffsetMap; |
| 326 typedef SparseRangeOffsetMap::iterator SparseRangeIterator; | 326 typedef SparseRangeOffsetMap::iterator SparseRangeIterator; |
| 327 SparseRangeOffsetMap sparse_ranges_; | 327 SparseRangeOffsetMap sparse_ranges_; |
| 328 base::File sparse_file_; | 328 base::File sparse_file_; |
| 329 // Offset of the end of the sparse file (where the next sparse range will be | 329 // Offset of the end of the sparse file (where the next sparse range will be |
| 330 // written). | 330 // written). |
| 331 int64 sparse_tail_offset_; | 331 int64_t sparse_tail_offset_; |
| 332 | 332 |
| 333 // True if the entry was created, or false if it was opened. Used to log | 333 // True if the entry was created, or false if it was opened. Used to log |
| 334 // SimpleCache.*.EntryCreatedWithStream2Omitted only for created entries. | 334 // SimpleCache.*.EntryCreatedWithStream2Omitted only for created entries. |
| 335 bool files_created_; | 335 bool files_created_; |
| 336 }; | 336 }; |
| 337 | 337 |
| 338 } // namespace disk_cache | 338 } // namespace disk_cache |
| 339 | 339 |
| 340 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ | 340 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
| OLD | NEW |