Deprecate restore_scissor_on_fbo_change workaround
[chromium-blink-merge.git] / base / files / memory_mapped_file.cc
bloba48ec0ceb2a8b353b7ce7e09da96fb6f7dc35f96
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 #include "base/files/memory_mapped_file.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
10 namespace base {
12 MemoryMappedFile::~MemoryMappedFile() {
13 CloseHandles();
16 bool MemoryMappedFile::Initialize(const FilePath& file_name) {
17 if (IsValid())
18 return false;
20 if (!MapFileToMemory(file_name)) {
21 CloseHandles();
22 return false;
25 return true;
28 bool MemoryMappedFile::Initialize(PlatformFile file) {
29 if (IsValid())
30 return false;
32 file_ = file;
34 if (!MapFileToMemoryInternal()) {
35 CloseHandles();
36 return false;
39 return true;
42 bool MemoryMappedFile::IsValid() const {
43 return data_ != NULL;
46 bool MemoryMappedFile::MapFileToMemory(const FilePath& file_name) {
47 file_ = CreatePlatformFile(file_name, PLATFORM_FILE_OPEN | PLATFORM_FILE_READ,
48 NULL, NULL);
50 if (file_ == kInvalidPlatformFileValue) {
51 DLOG(ERROR) << "Couldn't open " << file_name.AsUTF8Unsafe();
52 return false;
55 return MapFileToMemoryInternal();
58 } // namespace base