Chromium Code Reviews| 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 #include "base/files/memory_mapped_file.h" | 5 #include "base/files/memory_mapped_file.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 bool MemoryMappedFile::Region::operator==( | 25 bool MemoryMappedFile::Region::operator==( |
| 26 const MemoryMappedFile::Region& other) const { | 26 const MemoryMappedFile::Region& other) const { |
| 27 return other.offset == offset && other.size == size; | 27 return other.offset == offset && other.size == size; |
| 28 } | 28 } |
| 29 | 29 |
| 30 MemoryMappedFile::~MemoryMappedFile() { | 30 MemoryMappedFile::~MemoryMappedFile() { |
| 31 CloseHandles(); | 31 CloseHandles(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool MemoryMappedFile::Initialize(const FilePath& file_name) { | 34 bool MemoryMappedFile::Initialize(const FilePath& file_name) { |
|
rvargas (doing something else)
2014/08/26 21:25:21
This method documentation states that "access is r
henryhsu
2014/08/27 02:59:06
Done.
| |
| 35 if (IsValid()) | 35 if (IsValid()) |
| 36 return false; | 36 return false; |
| 37 | 37 |
| 38 file_.Initialize(file_name, File::FLAG_OPEN | File::FLAG_READ); | 38 file_.Initialize(file_name, File::FLAG_OPEN | |
| 39 File::FLAG_READ | | |
| 40 File::FLAG_WRITE); | |
| 39 | 41 |
| 40 if (!file_.IsValid()) { | 42 if (!file_.IsValid()) { |
| 41 DLOG(ERROR) << "Couldn't open " << file_name.AsUTF8Unsafe(); | 43 DLOG(ERROR) << "Couldn't open " << file_name.AsUTF8Unsafe(); |
| 42 return false; | 44 return false; |
| 43 } | 45 } |
| 44 | 46 |
| 45 if (!MapFileRegionToMemory(Region::kWholeFile)) { | 47 if (!MapFileRegionToMemory(Region::kWholeFile)) { |
| 46 CloseHandles(); | 48 CloseHandles(); |
| 47 return false; | 49 return false; |
| 48 } | 50 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 int32* offset) { | 82 int32* offset) { |
| 81 // Sadly, on Windows, the mmap alignment is not just equal to the page size. | 83 // Sadly, on Windows, the mmap alignment is not just equal to the page size. |
| 82 const int64 mask = static_cast<int64>(SysInfo::VMAllocationGranularity()) - 1; | 84 const int64 mask = static_cast<int64>(SysInfo::VMAllocationGranularity()) - 1; |
| 83 DCHECK_LT(mask, std::numeric_limits<int32>::max()); | 85 DCHECK_LT(mask, std::numeric_limits<int32>::max()); |
| 84 *offset = start & mask; | 86 *offset = start & mask; |
| 85 *aligned_start = start & ~mask; | 87 *aligned_start = start & ~mask; |
| 86 *aligned_size = (size + *offset + mask) & ~mask; | 88 *aligned_size = (size + *offset + mask) & ~mask; |
| 87 } | 89 } |
| 88 | 90 |
| 89 } // namespace base | 91 } // namespace base |
| OLD | NEW |