Add WebRtc logging in IpcPacketSocket when the socket is blocked or unblocked.
[chromium-blink-merge.git] / base / files / memory_mapped_file_win.cc
blobf3822873bfdddb877bd73afd9fa2548ca5cd83f2
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/strings/string16.h"
9 #include "base/threading/thread_restrictions.h"
11 namespace base {
13 MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0), image_(false) {
16 bool MemoryMappedFile::InitializeAsImageSection(const FilePath& file_name) {
17 image_ = true;
18 return Initialize(file_name);
21 bool MemoryMappedFile::MapFileToMemory() {
22 ThreadRestrictions::AssertIOAllowed();
24 if (!file_.IsValid())
25 return false;
27 int64 len = file_.GetLength();
28 if (len <= 0 || len > kint32max)
29 return false;
30 length_ = static_cast<size_t>(len);
32 int flags = image_ ? SEC_IMAGE | PAGE_READONLY : PAGE_READONLY;
34 file_mapping_.Set(::CreateFileMapping(file_.GetPlatformFile(), NULL,
35 flags, 0, 0, NULL));
36 if (!file_mapping_.IsValid())
37 return false;
39 data_ = static_cast<uint8*>(::MapViewOfFile(file_mapping_.Get(),
40 FILE_MAP_READ, 0, 0, 0));
41 return data_ != NULL;
44 void MemoryMappedFile::CloseHandles() {
45 if (data_)
46 ::UnmapViewOfFile(data_);
47 if (file_mapping_.IsValid())
48 file_mapping_.Close();
49 if (file_.IsValid())
50 file_.Close();
52 data_ = NULL;
53 length_ = 0;
56 } // namespace base