Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: net/disk_cache/blockfile/mapped_file.cc

Issue 206453003: Move Preload() code to MappedFile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: New attempt Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
8
9 #include "base/memory/scoped_ptr.h"
10
7 namespace disk_cache { 11 namespace disk_cache {
8 12
9 // Note: Most of this class is implemented in platform-specific files. 13 // Note: Most of this class is implemented in platform-specific files.
10 14
11 bool MappedFile::Load(const FileBlock* block) { 15 bool MappedFile::Load(const FileBlock* block) {
12 size_t offset = block->offset() + view_size_; 16 size_t offset = block->offset() + view_size_;
13 return Read(block->buffer(), block->size(), offset); 17 return Read(block->buffer(), block->size(), offset);
14 } 18 }
15 19
16 bool MappedFile::Store(const FileBlock* block) { 20 bool MappedFile::Store(const FileBlock* block) {
17 size_t offset = block->offset() + view_size_; 21 size_t offset = block->offset() + view_size_;
18 return Write(block->buffer(), block->size(), offset); 22 return Write(block->buffer(), block->size(), offset);
19 } 23 }
20 24
21 bool MappedFile::Load(const FileBlock* block, 25 bool MappedFile::Load(const FileBlock* block,
22 FileIOCallback* callback, 26 FileIOCallback* callback,
23 bool* completed) { 27 bool* completed) {
24 size_t offset = block->offset() + view_size_; 28 size_t offset = block->offset() + view_size_;
25 return Read(block->buffer(), block->size(), offset, callback, completed); 29 return Read(block->buffer(), block->size(), offset, callback, completed);
26 } 30 }
27 31
28 bool MappedFile::Store(const FileBlock* block, 32 bool MappedFile::Store(const FileBlock* block,
29 FileIOCallback* callback, 33 FileIOCallback* callback,
30 bool* completed) { 34 bool* completed) {
31 size_t offset = block->offset() + view_size_; 35 size_t offset = block->offset() + view_size_;
32 return Write(block->buffer(), block->size(), offset, callback, completed); 36 return Write(block->buffer(), block->size(), offset, callback, completed);
33 } 37 }
34 38
39 bool MappedFile::Preload() {
40 static const size_t kPreloadBufferSize = 16384;
rvargas (doing something else) 2014/03/20 19:05:19 The files have a limited size... the index is at m
41 size_t file_len = GetLength();
42 size_t left_to_read = file_len;
43 scoped_ptr<char[]> buf(new char[kPreloadBufferSize]);
44 while (left_to_read > 0) {
45 size_t to_read = std::min(kPreloadBufferSize, left_to_read);
46 size_t offset = file_len - left_to_read;
47 if (!Read(buf.get(), to_read, offset)) {
48 return false;
49 }
50 left_to_read -= to_read;
51 }
52 return true;
53 }
35 } // namespace disk_cache 54 } // namespace disk_cache
OLDNEW
« net/disk_cache/blockfile/mapped_file.h ('K') | « net/disk_cache/blockfile/mapped_file.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698