Remove additional dependencies from InternetOptionsHandler
[chromium-blink-merge.git] / base / files / memory_mapped_file.cc
blobace4e112628519137e7f56fbfb36f6176c2e8e83
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 file_.Initialize(file_name, File::FLAG_OPEN | File::FLAG_READ);
22 if (!file_.IsValid()) {
23 DLOG(ERROR) << "Couldn't open " << file_name.AsUTF8Unsafe();
24 return false;
27 if (!MapFileToMemory()) {
28 CloseHandles();
29 return false;
32 return true;
35 bool MemoryMappedFile::Initialize(File file) {
36 if (IsValid())
37 return false;
39 file_ = file.Pass();
41 if (!MapFileToMemory()) {
42 CloseHandles();
43 return false;
46 return true;
49 bool MemoryMappedFile::IsValid() const {
50 return data_ != NULL;
53 } // namespace base