OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 BASE_FILES_MEMORY_MAPPED_FILE_H_ | 5 #ifndef BASE_FILES_MEMORY_MAPPED_FILE_H_ |
6 #define BASE_FILES_MEMORY_MAPPED_FILE_H_ | 6 #define BASE_FILES_MEMORY_MAPPED_FILE_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class BASE_EXPORT MemoryMappedFile { | 21 class BASE_EXPORT MemoryMappedFile { |
22 public: | 22 public: |
23 // The default constructor sets all members to invalid/null values. | 23 // The default constructor sets all members to invalid/null values. |
24 MemoryMappedFile(); | 24 MemoryMappedFile(); |
25 ~MemoryMappedFile(); | 25 ~MemoryMappedFile(); |
26 | 26 |
27 // Used to hold information about a region [offset + size] of a file. | 27 // Used to hold information about a region [offset + size] of a file. |
28 struct BASE_EXPORT Region { | 28 struct BASE_EXPORT Region { |
29 static const Region kWholeFile; | 29 static const Region kWholeFile; |
30 | 30 |
31 Region(); | |
32 Region(int64 offset, int64 size); | |
33 | |
34 bool operator==(const Region& other) const; | 31 bool operator==(const Region& other) const; |
35 bool operator!=(const Region& other) const; | 32 bool operator!=(const Region& other) const; |
36 | 33 |
37 // Start of the region (measured in bytes from the beginning of the file). | 34 // Start of the region (measured in bytes from the beginning of the file). |
38 int64 offset; | 35 int64 offset; |
39 | 36 |
40 // Length of the region in bytes. | 37 // Length of the region in bytes. |
41 int64 size; | 38 int64 size; |
42 | |
43 private: | |
44 // Used by kWholeFile. | |
45 Region(base::LinkerInitialized); | |
46 }; | 39 }; |
47 | 40 |
48 // Opens an existing file and maps it into memory. Access is restricted to | 41 // Opens an existing file and maps it into memory. Access is restricted to |
49 // read only. If this object already points to a valid memory mapped file | 42 // read only. If this object already points to a valid memory mapped file |
50 // then this method will fail and return false. If it cannot open the file, | 43 // then this method will fail and return false. If it cannot open the file, |
51 // the file does not exist, or the memory mapping fails, it will return false. | 44 // the file does not exist, or the memory mapping fails, it will return false. |
52 // Later we may want to allow the user to specify access. | 45 // Later we may want to allow the user to specify access. |
53 bool Initialize(const FilePath& file_name); | 46 bool Initialize(const FilePath& file_name); |
54 | 47 |
55 // As above, but works with an already-opened file. MemoryMappedFile takes | 48 // As above, but works with an already-opened file. MemoryMappedFile takes |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 win::ScopedHandle file_mapping_; | 92 win::ScopedHandle file_mapping_; |
100 bool image_; // Map as an image. | 93 bool image_; // Map as an image. |
101 #endif | 94 #endif |
102 | 95 |
103 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); | 96 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); |
104 }; | 97 }; |
105 | 98 |
106 } // namespace base | 99 } // namespace base |
107 | 100 |
108 #endif // BASE_FILES_MEMORY_MAPPED_FILE_H_ | 101 #endif // BASE_FILES_MEMORY_MAPPED_FILE_H_ |
OLD | NEW |