| 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" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 | 12 |
| 13 #if defined(OS_WIN) | |
| 14 #include <windows.h> | |
| 15 #endif | |
| 16 | |
| 17 namespace base { | 13 namespace base { |
| 18 | 14 |
| 19 class FilePath; | 15 class FilePath; |
| 20 | 16 |
| 21 class BASE_EXPORT MemoryMappedFile { | 17 class BASE_EXPORT MemoryMappedFile { |
| 22 public: | 18 public: |
| 23 // The default constructor sets all members to invalid/null values. | 19 // The default constructor sets all members to invalid/null values. |
| 24 MemoryMappedFile(); | 20 MemoryMappedFile(); |
| 25 ~MemoryMappedFile(); | 21 ~MemoryMappedFile(); |
| 26 | 22 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 // Later we may want to allow the user to specify access. | 48 // Later we may want to allow the user to specify access. |
| 53 bool Initialize(const FilePath& file_name); | 49 bool Initialize(const FilePath& file_name); |
| 54 | 50 |
| 55 // As above, but works with an already-opened file. MemoryMappedFile takes | 51 // As above, but works with an already-opened file. MemoryMappedFile takes |
| 56 // ownership of |file| and closes it when done. | 52 // ownership of |file| and closes it when done. |
| 57 bool Initialize(File file); | 53 bool Initialize(File file); |
| 58 | 54 |
| 59 // As above, but works with a region of an already-opened file. | 55 // As above, but works with a region of an already-opened file. |
| 60 bool Initialize(File file, const Region& region); | 56 bool Initialize(File file, const Region& region); |
| 61 | 57 |
| 62 #if defined(OS_WIN) | |
| 63 // Opens an existing file and maps it as an image section. Please refer to | |
| 64 // the Initialize function above for additional information. | |
| 65 bool InitializeAsImageSection(const FilePath& file_name); | |
| 66 #endif // OS_WIN | |
| 67 | |
| 68 const uint8* data() const { return data_; } | 58 const uint8* data() const { return data_; } |
| 69 size_t length() const { return length_; } | 59 size_t length() const { return length_; } |
| 70 | 60 |
| 71 // Is file_ a valid file handle that points to an open, memory mapped file? | 61 // Is file_ a valid file handle that points to an open, memory mapped file? |
| 72 bool IsValid() const; | 62 bool IsValid() const; |
| 73 | 63 |
| 74 private: | 64 private: |
| 75 // Given the arbitrarily aligned memory region [start, size], returns the | 65 // Given the arbitrarily aligned memory region [start, size], returns the |
| 76 // boundaries of the region aligned to the granularity specified by the OS, | 66 // boundaries of the region aligned to the granularity specified by the OS, |
| 77 // (a page on Linux, ~32k on Windows) as follows: | 67 // (a page on Linux, ~32k on Windows) as follows: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 // success, false on any kind of failure. This is a helper for Initialize(). | 78 // success, false on any kind of failure. This is a helper for Initialize(). |
| 89 bool MapFileRegionToMemory(const Region& region); | 79 bool MapFileRegionToMemory(const Region& region); |
| 90 | 80 |
| 91 // Closes all open handles. | 81 // Closes all open handles. |
| 92 void CloseHandles(); | 82 void CloseHandles(); |
| 93 | 83 |
| 94 File file_; | 84 File file_; |
| 95 uint8* data_; | 85 uint8* data_; |
| 96 size_t length_; | 86 size_t length_; |
| 97 | 87 |
| 98 #if defined(OS_WIN) | |
| 99 win::ScopedHandle file_mapping_; | |
| 100 bool image_; // Map as an image. | |
| 101 #endif | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); | 88 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); |
| 104 }; | 89 }; |
| 105 | 90 |
| 106 } // namespace base | 91 } // namespace base |
| 107 | 92 |
| 108 #endif // BASE_FILES_MEMORY_MAPPED_FILE_H_ | 93 #endif // BASE_FILES_MEMORY_MAPPED_FILE_H_ |
| OLD | NEW |