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(); |
31 Region(int64 offset, int64 size); | 32 Region(int64 offset, int64 size); |
32 | 33 |
33 bool operator==(const Region& other) const; | 34 bool operator==(const Region& other) const; |
| 35 bool operator!=(const Region& other) const; |
34 | 36 |
35 // Start of the region (measured in bytes from the beginning of the file). | 37 // Start of the region (measured in bytes from the beginning of the file). |
36 int64 offset; | 38 int64 offset; |
37 | 39 |
38 // Length of the region in bytes. | 40 // Length of the region in bytes. |
39 int64 size; | 41 int64 size; |
40 | 42 |
41 private: | 43 private: |
42 // This ctor is used only by kWholeFile, to construct a zero-sized Region | 44 // Used by kWholeFile. |
43 // (which is forbidden by the public ctor) and uniquely identify kWholeFile. | |
44 Region(base::LinkerInitialized); | 45 Region(base::LinkerInitialized); |
45 }; | 46 }; |
46 | 47 |
47 // Opens an existing file and maps it into memory. Access is restricted to | 48 // Opens an existing file and maps it into memory. Access is restricted to |
48 // read only. If this object already points to a valid memory mapped file | 49 // read only. If this object already points to a valid memory mapped file |
49 // then this method will fail and return false. If it cannot open the file, | 50 // then this method will fail and return false. If it cannot open the file, |
50 // the file does not exist, or the memory mapping fails, it will return false. | 51 // the file does not exist, or the memory mapping fails, it will return false. |
51 // Later we may want to allow the user to specify access. | 52 // Later we may want to allow the user to specify access. |
52 bool Initialize(const FilePath& file_name); | 53 bool Initialize(const FilePath& file_name); |
53 | 54 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 win::ScopedHandle file_mapping_; | 99 win::ScopedHandle file_mapping_; |
99 bool image_; // Map as an image. | 100 bool image_; // Map as an image. |
100 #endif | 101 #endif |
101 | 102 |
102 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); | 103 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); |
103 }; | 104 }; |
104 | 105 |
105 } // namespace base | 106 } // namespace base |
106 | 107 |
107 #endif // BASE_FILES_MEMORY_MAPPED_FILE_H_ | 108 #endif // BASE_FILES_MEMORY_MAPPED_FILE_H_ |
OLD | NEW |