Make touch-action apply to double-tap zoom
[chromium-blink-merge.git] / base / files / memory_mapped_file.h
blobb02d8cfbdae09b89159675495313eae521a7576e
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
3 // found in the LICENSE file.
5 #ifndef BASE_FILES_MEMORY_MAPPED_FILE_H_
6 #define BASE_FILES_MEMORY_MAPPED_FILE_H_
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "base/files/file.h"
11 #include "build/build_config.h"
13 #if defined(OS_WIN)
14 #include <windows.h>
15 #endif
17 namespace base {
19 class FilePath;
21 class BASE_EXPORT MemoryMappedFile {
22 public:
23 // The default constructor sets all members to invalid/null values.
24 MemoryMappedFile();
25 ~MemoryMappedFile();
27 // Opens an existing file and maps it into memory. Access is restricted to
28 // read only. If this object already points to a valid memory mapped file
29 // then this method will fail and return false. If it cannot open the file,
30 // the file does not exist, or the memory mapping fails, it will return false.
31 // Later we may want to allow the user to specify access.
32 bool Initialize(const FilePath& file_name);
34 // As above, but works with an already-opened file. MemoryMappedFile takes
35 // ownership of |file| and closes it when done.
36 bool Initialize(File file);
38 #if defined(OS_WIN)
39 // Opens an existing file and maps it as an image section. Please refer to
40 // the Initialize function above for additional information.
41 bool InitializeAsImageSection(const FilePath& file_name);
42 #endif // OS_WIN
44 const uint8* data() const { return data_; }
45 size_t length() const { return length_; }
47 // Is file_ a valid file handle that points to an open, memory mapped file?
48 bool IsValid() const;
50 private:
51 // Map the file to memory, set data_ to that memory address. Return true on
52 // success, false on any kind of failure. This is a helper for Initialize().
53 bool MapFileToMemory();
55 // Closes all open handles.
56 void CloseHandles();
58 File file_;
59 uint8* data_;
60 size_t length_;
62 #if defined(OS_WIN)
63 win::ScopedHandle file_mapping_;
64 bool image_; // Map as an image.
65 #endif
67 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile);
70 } // namespace base
72 #endif // BASE_FILES_MEMORY_MAPPED_FILE_H_