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

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

Issue 125643002: Convert most of base and net to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use error_details() Created 6 years, 11 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 | Annotate | Revision Log
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_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 <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/files/file.h"
14 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/platform_file.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "net/base/cache_type.h" 19 #include "net/base/cache_type.h"
20 #include "net/base/net_export.h" 20 #include "net/base/net_export.h"
21 #include "net/disk_cache/simple/simple_entry_format.h" 21 #include "net/disk_cache/simple/simple_entry_format.h"
22 22
23 namespace net { 23 namespace net {
24 class GrowableIOBuffer; 24 class GrowableIOBuffer;
25 class IOBuffer; 25 class IOBuffer;
26 } 26 }
27 27
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 uint64 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::PlatformFileError* 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::PlatformFileError* 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.
(...skipping 28 matching lines...) Expand all
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* 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 bool 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).
(...skipping 16 matching lines...) Expand all
298 uint64 entry_hash, 298 uint64 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 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_ != base::kInvalidPlatformFileValue; 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 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::PlatformFile 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, SparseRange> SparseRangeOffsetMap;
326 typedef SparseRangeOffsetMap::iterator SparseRangeIterator; 326 typedef SparseRangeOffsetMap::iterator SparseRangeIterator;
327 SparseRangeOffsetMap sparse_ranges_; 327 SparseRangeOffsetMap sparse_ranges_;
328 base::PlatformFile 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 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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698