1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/disk_cache/blockfile/mapped_file.h" 6 7 #include <algorithm> 8 #include <memory> 9 10 namespace disk_cache { 11 12 // Note: Most of this class is implemented in platform-specific files. 13 Load(const FileBlock * block)14bool MappedFile::Load(const FileBlock* block) { 15 size_t offset = block->offset() + view_size_; 16 return Read(block->buffer(), block->size(), offset); 17 } 18 Store(const FileBlock * block)19bool MappedFile::Store(const FileBlock* block) { 20 size_t offset = block->offset() + view_size_; 21 return Write(block->buffer(), block->size(), offset); 22 } 23 Preload()24bool MappedFile::Preload() { 25 size_t file_len = GetLength(); 26 auto buf = std::make_unique<char[]>(file_len); 27 if (!Read(buf.get(), file_len, 0)) 28 return false; 29 return true; 30 } 31 } // namespace disk_cache 32