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/mapped_file.h"
10 #include "base/files/file_path.h"
11 #include "base/logging.h"
12 #include "net/disk_cache/disk_cache.h"
14 namespace disk_cache
{
16 void* MappedFile::Init(const base::FilePath
& name
, size_t size
) {
18 if (init_
|| !File::Init(name
))
21 size_t temp_len
= size
? size
: 4096;
25 buffer_
= mmap(NULL
, size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
,
29 DCHECK(reinterpret_cast<intptr_t>(buffer_
) != -1);
30 if (reinterpret_cast<intptr_t>(buffer_
) == -1)
33 // Make sure we detect hardware failures reading the headers.
34 scoped_ptr
<char[]> temp(new char[temp_len
]);
35 if (!Read(temp
.get(), temp_len
, 0))
41 void MappedFile::Flush() {
44 MappedFile::~MappedFile() {
49 int ret
= munmap(buffer_
, view_size_
);
54 } // namespace disk_cache