| 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 <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 SimpleSynchronousEntry( | 168 SimpleSynchronousEntry( |
| 169 net::CacheType cache_type, | 169 net::CacheType cache_type, |
| 170 const base::FilePath& path, | 170 const base::FilePath& path, |
| 171 const std::string& key, | 171 const std::string& key, |
| 172 uint64 entry_hash); | 172 uint64 entry_hash); |
| 173 | 173 |
| 174 // Like Entry, the SimpleSynchronousEntry self releases when Close() is | 174 // Like Entry, the SimpleSynchronousEntry self releases when Close() is |
| 175 // called. | 175 // called. |
| 176 ~SimpleSynchronousEntry(); | 176 ~SimpleSynchronousEntry(); |
| 177 | 177 |
| 178 // Tries to open one of the cache entry files. Succeeds if the open succeeds | 178 // Tries to open one of the cache entry files. Succeeds if the open succeeds |
| 179 // or if the file was not found and is allowed to be omitted if the | 179 // or if the file was not found and is allowed to be omitted if the |
| 180 // corresponding stream is empty. | 180 // corresponding stream is empty. |
| 181 bool MaybeOpenFile(int file_index, | 181 bool MaybeOpenFile(int file_index, |
| 182 base::PlatformFileError* out_error); | 182 base::PlatformFileError* out_error); |
| 183 // Creates one of the cache entry files if necessary. If the file is allowed | 183 // Creates one of the cache entry files if necessary. If the file is allowed |
| 184 // to be omitted if the corresponding stream is empty, and if |file_required| | 184 // to be omitted if the corresponding stream is empty, and if |file_required| |
| 185 // is FILE_NOT_REQUIRED, then the file is not created; otherwise, it is. | 185 // is FILE_NOT_REQUIRED, then the file is not created; otherwise, it is. |
| 186 bool MaybeCreateFile(int file_index, | 186 bool MaybeCreateFile(int file_index, |
| 187 FileRequired file_required, | 187 FileRequired file_required, |
| 188 base::PlatformFileError* out_error); | 188 base::PlatformFileError* out_error); |
| 189 bool OpenFiles(bool had_index, | 189 bool OpenFiles(bool had_index, |
| 190 SimpleEntryStat* out_entry_stat); | 190 SimpleEntryStat* out_entry_stat); |
| 191 bool CreateFiles(bool had_index, | 191 bool CreateFiles(bool had_index, |
| 192 SimpleEntryStat* out_entry_stat); | 192 SimpleEntryStat* out_entry_stat); |
| 193 void CloseFile(int index); | 193 void CloseFile(int index); |
| 194 void CloseFiles(); | 194 void CloseFiles(); |
| 195 | 195 |
| 196 // Returns a net error, i.e. net::OK on success. |had_index| is passed | 196 // Returns a net error, i.e. net::OK on success. |had_index| is passed |
| 197 // from the main entry for metrics purposes, and is true if the index was | 197 // from the main entry for metrics purposes, and is true if the index was |
| 198 // initialized when the open operation began. | 198 // initialized when the open operation began. |
| 199 int InitializeForOpen(bool had_index, | 199 int InitializeForOpen(bool had_index, |
| 200 SimpleEntryStat* out_entry_stat, | 200 SimpleEntryStat* out_entry_stat, |
| 201 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, | 201 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, |
| 202 uint32* out_stream_0_crc32); | 202 uint32* out_stream_0_crc32); |
| 203 | 203 |
| 204 // Writes the header and key to a newly-created stream file. |index| is the | 204 // Writes the header and key to a newly-created stream file. |index| is the |
| 205 // index of the stream. Returns true on success; returns false and sets | 205 // index of the stream. Returns true on success; returns false and sets |
| 206 // |*out_result| on failure. | 206 // |*out_result| on failure. |
| 207 bool InitializeCreatedFile(int index, CreateEntryResult* out_result); | 207 bool InitializeCreatedFile(int index, CreateEntryResult* out_result); |
| 208 | 208 |
| 209 // Returns a net error, including net::OK on success and net::FILE_EXISTS | 209 // Returns a net error, including net::OK on success and net::FILE_EXISTS |
| 210 // when the entry already exists. |had_index| is passed from the main entry | 210 // when the entry already exists. |had_index| is passed from the main entry |
| 211 // for metrics purposes, and is true if the index was initialized when the | 211 // for metrics purposes, and is true if the index was initialized when the |
| 212 // create operation began. | 212 // create operation began. |
| 213 int InitializeForCreate(bool had_index, SimpleEntryStat* out_entry_stat); | 213 int InitializeForCreate(bool had_index, SimpleEntryStat* out_entry_stat); |
| 214 | 214 |
| 215 // Allocates and fills a buffer with stream 0 data in |stream_0_data|, then | 215 // Allocates and fills a buffer with stream 0 data in |stream_0_data|, then |
| 216 // checks its crc32. | 216 // checks its crc32. |
| 217 int ReadAndValidateStream0( | 217 int ReadAndValidateStream0( |
| 218 int total_data_size, | 218 int total_data_size, |
| 219 SimpleEntryStat* out_entry_stat, | 219 SimpleEntryStat* out_entry_stat, |
| 220 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, | 220 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 243 std::string key_; | 243 std::string key_; |
| 244 | 244 |
| 245 bool have_open_files_; | 245 bool have_open_files_; |
| 246 bool initialized_; | 246 bool initialized_; |
| 247 | 247 |
| 248 base::PlatformFile files_[kSimpleEntryFileCount]; | 248 base::PlatformFile files_[kSimpleEntryFileCount]; |
| 249 | 249 |
| 250 // True if the corresponding stream is empty and therefore no on-disk file | 250 // True if the corresponding stream is empty and therefore no on-disk file |
| 251 // was created to store it. | 251 // was created to store it. |
| 252 bool empty_file_omitted_[kSimpleEntryFileCount]; | 252 bool empty_file_omitted_[kSimpleEntryFileCount]; |
| 253 |
| 254 // True if the entry was created, or false if it was opened. Used to log |
| 255 // SimpleCache.*.EntryCreatedWithStream2Omitted only for created entries. |
| 256 bool files_created_; |
| 253 }; | 257 }; |
| 254 | 258 |
| 255 } // namespace disk_cache | 259 } // namespace disk_cache |
| 256 | 260 |
| 257 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ | 261 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
| OLD | NEW |