OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_MAPPED_FILE_H_ | 7 #ifndef NET_DISK_CACHE_MAPPED_FILE_H_ |
8 #define NET_DISK_CACHE_MAPPED_FILE_H_ | 8 #define NET_DISK_CACHE_MAPPED_FILE_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "net/disk_cache/disk_format.h" | 12 #include "net/disk_cache/disk_format.h" |
13 #include "net/disk_cache/file.h" | 13 #include "net/disk_cache/file.h" |
14 #include "net/disk_cache/file_block.h" | 14 #include "net/disk_cache/file_block.h" |
15 | 15 |
16 namespace disk_cache { | 16 namespace disk_cache { |
17 | 17 |
18 // This class implements a memory mapped file used to access block-files. The | 18 // This class implements a memory mapped file used to access block-files. The |
19 // idea is that the header and bitmap will be memory mapped all the time, and | 19 // idea is that the header and bitmap will be memory mapped all the time, and |
20 // the actual data for the blocks will be access asynchronously (most of the | 20 // the actual data for the blocks will be access asynchronously (most of the |
21 // time). | 21 // time). |
22 class MappedFile : public File { | 22 class MappedFile : public File { |
23 public: | 23 public: |
24 MappedFile() : File(true), init_(false) {} | 24 MappedFile() : File(true), init_(false) {} |
25 | 25 |
26 // Performs object initialization. name is the file to use, and size is the | 26 // Performs object initialization. name is the file to use, and size is the |
27 // ammount of data to memory map from th efile. If size is 0, the whole file | 27 // ammount of data to memory map from th efile. If size is 0, the whole file |
28 // will be mapped in memory. | 28 // will be mapped in memory. |
29 void* Init(const std::wstring name, size_t size); | 29 void* Init(const std::wstring& name, size_t size); |
30 | 30 |
31 void* buffer() const { | 31 void* buffer() const { |
32 return buffer_; | 32 return buffer_; |
33 } | 33 } |
34 | 34 |
35 // Loads or stores a given block from the backing file (synchronously). | 35 // Loads or stores a given block from the backing file (synchronously). |
36 bool Load(const FileBlock* block); | 36 bool Load(const FileBlock* block); |
37 bool Store(const FileBlock* block); | 37 bool Store(const FileBlock* block); |
38 | 38 |
39 protected: | 39 protected: |
40 virtual ~MappedFile(); | 40 virtual ~MappedFile(); |
41 | 41 |
42 private: | 42 private: |
43 bool init_; | 43 bool init_; |
44 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
45 HANDLE section_; | 45 HANDLE section_; |
46 #endif | 46 #endif |
47 void* buffer_; // Address of the memory mapped buffer. | 47 void* buffer_; // Address of the memory mapped buffer. |
48 size_t view_size_; // Size of the memory pointed by buffer_. | 48 size_t view_size_; // Size of the memory pointed by buffer_. |
49 | 49 |
50 DISALLOW_COPY_AND_ASSIGN(MappedFile); | 50 DISALLOW_COPY_AND_ASSIGN(MappedFile); |
51 }; | 51 }; |
52 | 52 |
53 } // namespace disk_cache | 53 } // namespace disk_cache |
54 | 54 |
55 #endif // NET_DISK_CACHE_MAPPED_FILE_H_ | 55 #endif // NET_DISK_CACHE_MAPPED_FILE_H_ |
OLD | NEW |