diff options
Diffstat (limited to 'chromium/net/disk_cache/blockfile/mapped_file_win.cc')
-rw-r--r-- | chromium/net/disk_cache/blockfile/mapped_file_win.cc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/chromium/net/disk_cache/blockfile/mapped_file_win.cc b/chromium/net/disk_cache/blockfile/mapped_file_win.cc new file mode 100644 index 00000000000..d725238e32e --- /dev/null +++ b/chromium/net/disk_cache/blockfile/mapped_file_win.cc @@ -0,0 +1,55 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/disk_cache/blockfile/mapped_file.h" + +#include "base/files/file_path.h" +#include "base/logging.h" +#include "base/memory/scoped_ptr.h" +#include "net/disk_cache/disk_cache.h" + +namespace disk_cache { + +void* MappedFile::Init(const base::FilePath& name, size_t size) { + DCHECK(!init_); + if (init_ || !File::Init(name)) + return NULL; + + buffer_ = NULL; + init_ = true; + section_ = CreateFileMapping(platform_file(), NULL, PAGE_READWRITE, 0, + static_cast<DWORD>(size), NULL); + if (!section_) + return NULL; + + buffer_ = MapViewOfFile(section_, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, size); + DCHECK(buffer_); + view_size_ = size; + + // Make sure we detect hardware failures reading the headers. + size_t temp_len = size ? size : 4096; + scoped_ptr<char[]> temp(new char[temp_len]); + if (!Read(temp.get(), temp_len, 0)) + return NULL; + + return buffer_; +} + +MappedFile::~MappedFile() { + if (!init_) + return; + + if (buffer_) { + BOOL ret = UnmapViewOfFile(buffer_); + DCHECK(ret); + } + + if (section_) + CloseHandle(section_); +} + +void MappedFile::Flush() { +} + +} // namespace disk_cache |