xref: /aosp_15_r20/external/cronet/net/disk_cache/blockfile/mapped_file.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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)14 bool 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)19 bool MappedFile::Store(const FileBlock* block) {
20   size_t offset = block->offset() + view_size_;
21   return Write(block->buffer(), block->size(), offset);
22 }
23 
Preload()24 bool 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