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