diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-12 20:12:38 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-12 20:12:38 +0000 |
commit | 45cbfb0444d2ae27d9dbc9880c547c0d42978782 (patch) | |
tree | 3f5a3477831c68b73f87365c8222b3033758358a /base/file_util.h | |
parent | f33651e32ab77d1413e01f5fed1e90f5b36f7534 (diff) | |
download | chromium_src-45cbfb0444d2ae27d9dbc9880c547c0d42978782.zip chromium_src-45cbfb0444d2ae27d9dbc9880c547c0d42978782.tar.gz chromium_src-45cbfb0444d2ae27d9dbc9880c547c0d42978782.tar.bz2 |
Add a MemoryMappedFile class to file_util.
Factor out windowisms from the spell checker.
Review URL: http://codereview.chromium.org/14041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6919 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util.h')
-rw-r--r-- | base/file_util.h | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/base/file_util.h b/base/file_util.h index 7bc7e820..854703f 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -305,7 +305,6 @@ bool GetFileInfo(const FilePath& file_path, FileInfo* info); // Deprecated temporary compatibility function. bool GetFileInfo(const std::wstring& file_path, FileInfo* info); - // Wrapper for fopen-like calls. Returns non-NULL FILE* on success. FILE* OpenFile(const FilePath& filename, const char* mode); // Deprecated temporary compatibility functions. @@ -415,6 +414,44 @@ class FileEnumerator { DISALLOW_EVIL_CONSTRUCTORS(FileEnumerator); }; +// TODO(port): port this class to posix. +#if defined(OS_WIN) +class MemoryMappedFile { + public: + // The default constructor sets all members to invalid/null values. + MemoryMappedFile(); + ~MemoryMappedFile(); + + // Opens an existing file and maps it into memory. Access is restricted to + // read only. If this object already points to a valid memory mapped file + // then this method will fail and return false. If it cannot open the file, + // the file does not exist, or the memory mapping fails, it will return false. + // Later we may want to allow the user to specify access. + bool Initialize(const FilePath& file_name); + + const uint8* Data() const { return data_; } + size_t Length() const { return length_; } + + // Is file_ a valid file handle that points to an open, memory mapped file? + bool IsValid(); + + private: + // Map the file to memory, set data_ to that memory address. Return true on + // success, false on any kind of failure. This is a helper for Initialize(). + bool MapFileToMemory(const FilePath& file_name); + + // Closes all open handles. Later we may want to make this public. + void CloseHandles(); + + HANDLE file_; + HANDLE file_mapping_; + const uint8* data_; + size_t length_; + + DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); +}; +#endif // defined(OS_WIN) + // Renames a file using the SHFileOperation API to ensure that the target file // gets the correct default security descriptor in the new path. bool RenameFileAndResetSecurityDescriptor( |