| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See net/disk_cache/disk_cache.h for the public interface of the cache. | 5 // See net/disk_cache/disk_cache.h for the public interface of the cache. |
| 6 | 6 |
| 7 #ifndef NET_DISK_CACHE_BLOCKFILE_MAPPED_FILE_H_ | 7 #ifndef NET_DISK_CACHE_BLOCKFILE_MAPPED_FILE_H_ |
| 8 #define NET_DISK_CACHE_BLOCKFILE_MAPPED_FILE_H_ | 8 #define NET_DISK_CACHE_BLOCKFILE_MAPPED_FILE_H_ |
| 9 | 9 |
| 10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // time). | 23 // time). |
| 24 class NET_EXPORT_PRIVATE MappedFile : public File { | 24 class NET_EXPORT_PRIVATE MappedFile : public File { |
| 25 public: | 25 public: |
| 26 MappedFile() : File(true), init_(false) {} | 26 MappedFile() : File(true), init_(false) {} |
| 27 | 27 |
| 28 // Performs object initialization. name is the file to use, and size is the | 28 // Performs object initialization. name is the file to use, and size is the |
| 29 // amount of data to memory map from the file. If size is 0, the whole file | 29 // amount of data to memory map from the file. If size is 0, the whole file |
| 30 // will be mapped in memory. | 30 // will be mapped in memory. |
| 31 void* Init(const base::FilePath& name, size_t size); | 31 void* Init(const base::FilePath& name, size_t size); |
| 32 | 32 |
| 33 void* buffer() const { | 33 void* buffer() const { return buffer_; } |
| 34 return buffer_; | |
| 35 } | |
| 36 | 34 |
| 37 // Loads or stores a given block from the backing file (synchronously). | 35 // Loads or stores a given block from the backing file (synchronously). |
| 38 bool Load(const FileBlock* block); | 36 bool Load(const FileBlock* block); |
| 39 bool Store(const FileBlock* block); | 37 bool Store(const FileBlock* block); |
| 40 | 38 |
| 41 // Asynchronous versions of Load/Store, following the semantics of File::Read | 39 // Asynchronous versions of Load/Store, following the semantics of File::Read |
| 42 // and File::Write. | 40 // and File::Write. |
| 43 bool Load(const FileBlock* block, FileIOCallback* callback, bool* completed); | 41 bool Load(const FileBlock* block, FileIOCallback* callback, bool* completed); |
| 44 bool Store(const FileBlock* block, FileIOCallback* callback, bool* completed); | 42 bool Store(const FileBlock* block, FileIOCallback* callback, bool* completed); |
| 45 | 43 |
| 46 // Flush the memory-mapped section to disk (synchronously). | 44 // Flush the memory-mapped section to disk (synchronously). |
| 47 void Flush(); | 45 void Flush(); |
| 48 | 46 |
| 49 // Heats up the file system cache and make sure the file is fully | 47 // Heats up the file system cache and make sure the file is fully |
| 50 // readable (synchronously). | 48 // readable (synchronously). |
| 51 bool Preload(); | 49 bool Preload(); |
| 52 | 50 |
| 53 private: | 51 private: |
| 54 virtual ~MappedFile(); | 52 virtual ~MappedFile(); |
| 55 | 53 |
| 56 bool init_; | 54 bool init_; |
| 57 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 58 HANDLE section_; | 56 HANDLE section_; |
| 59 #endif | 57 #endif |
| 60 void* buffer_; // Address of the memory mapped buffer. | 58 void* buffer_; // Address of the memory mapped buffer. |
| 61 size_t view_size_; // Size of the memory pointed by buffer_. | 59 size_t view_size_; // Size of the memory pointed by buffer_. |
| 62 #if defined(POSIX_AVOID_MMAP) | 60 #if defined(POSIX_AVOID_MMAP) |
| 63 void* snapshot_; // Copy of the buffer taken when it was last flushed. | 61 void* snapshot_; // Copy of the buffer taken when it was last flushed. |
| 64 #endif | 62 #endif |
| 65 | 63 |
| 66 DISALLOW_COPY_AND_ASSIGN(MappedFile); | 64 DISALLOW_COPY_AND_ASSIGN(MappedFile); |
| 67 }; | 65 }; |
| 68 | 66 |
| 69 // Helper class for calling Flush() on exit from the current scope. | 67 // Helper class for calling Flush() on exit from the current scope. |
| 70 class ScopedFlush { | 68 class ScopedFlush { |
| 71 public: | 69 public: |
| 72 explicit ScopedFlush(MappedFile* file) : file_(file) {} | 70 explicit ScopedFlush(MappedFile* file) : file_(file) {} |
| 73 ~ScopedFlush() { | 71 ~ScopedFlush() { file_->Flush(); } |
| 74 file_->Flush(); | 72 |
| 75 } | |
| 76 private: | 73 private: |
| 77 MappedFile* file_; | 74 MappedFile* file_; |
| 78 }; | 75 }; |
| 79 | 76 |
| 80 } // namespace disk_cache | 77 } // namespace disk_cache |
| 81 | 78 |
| 82 #endif // NET_DISK_CACHE_BLOCKFILE_MAPPED_FILE_H_ | 79 #endif // NET_DISK_CACHE_BLOCKFILE_MAPPED_FILE_H_ |
| OLD | NEW |