1 // Copyright (c) 2012 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 "net/disk_cache/blockfile/mapped_file.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "net/disk_cache/disk_cache.h"
12 namespace disk_cache
{
14 void* MappedFile::Init(const base::FilePath
& name
, size_t size
) {
16 if (init_
|| !File::Init(name
))
21 section_
= CreateFileMapping(platform_file(), NULL
, PAGE_READWRITE
, 0,
22 static_cast<DWORD
>(size
), NULL
);
26 buffer_
= MapViewOfFile(section_
, FILE_MAP_READ
| FILE_MAP_WRITE
, 0, 0, size
);
30 // Make sure we detect hardware failures reading the headers.
31 size_t temp_len
= size
? size
: 4096;
32 scoped_ptr
<char[]> temp(new char[temp_len
]);
33 if (!Read(temp
.get(), temp_len
, 0))
39 MappedFile::~MappedFile() {
44 BOOL ret
= UnmapViewOfFile(buffer_
);
49 CloseHandle(section_
);
52 void MappedFile::Flush() {
55 } // namespace disk_cache