Refresh android relocation packer from AOSP bionic.
[chromium-blink-merge.git] / net / disk_cache / blockfile / mapped_file.cc
blobd26cead89aab2064646b598e8b7b0ac5f0520c1e
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 "net/disk_cache/blockfile/mapped_file.h"
7 #include <algorithm>
9 #include "base/memory/scoped_ptr.h"
11 namespace disk_cache {
13 // Note: Most of this class is implemented in platform-specific files.
15 bool MappedFile::Load(const FileBlock* block) {
16 size_t offset = block->offset() + view_size_;
17 return Read(block->buffer(), block->size(), offset);
20 bool MappedFile::Store(const FileBlock* block) {
21 size_t offset = block->offset() + view_size_;
22 return Write(block->buffer(), block->size(), offset);
25 bool MappedFile::Load(const FileBlock* block,
26 FileIOCallback* callback,
27 bool* completed) {
28 size_t offset = block->offset() + view_size_;
29 return Read(block->buffer(), block->size(), offset, callback, completed);
32 bool MappedFile::Store(const FileBlock* block,
33 FileIOCallback* callback,
34 bool* completed) {
35 size_t offset = block->offset() + view_size_;
36 return Write(block->buffer(), block->size(), offset, callback, completed);
39 bool MappedFile::Preload() {
40 size_t file_len = GetLength();
41 scoped_ptr<char[]> buf(new char[file_len]);
42 if (!Read(buf.get(), file_len, 0))
43 return false;
44 return true;
46 } // namespace disk_cache