diff options
author | bratell@opera.com <bratell@opera.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 11:37:14 +0000 |
---|---|---|
committer | bratell@opera.com <bratell@opera.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 11:37:14 +0000 |
commit | 9bcb5b353fe639fd1b676689e9cbc878dae7ffbe (patch) | |
tree | 6cfca39dfdb22a9e723d763ecebf3207da829859 /net | |
parent | 035cd4de910629be09e81660bd7dfff17f764eb1 (diff) | |
download | chromium_src-9bcb5b353fe639fd1b676689e9cbc878dae7ffbe.zip chromium_src-9bcb5b353fe639fd1b676689e9cbc878dae7ffbe.tar.gz chromium_src-9bcb5b353fe639fd1b676689e9cbc878dae7ffbe.tar.bz2 |
Move Preload() code to MappedFile
To heat up the file system caches we load the disk cache index
into RAM when starting the browser. To make it more obvious
what we're doing, move that to a method named Preload().
BUG=None
R=rvargas@chromium.org
Review URL: https://codereview.chromium.org/206453003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260844 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/disk_cache/blockfile/backend_impl.cc | 7 | ||||
-rw-r--r-- | net/disk_cache/blockfile/block_files.cc | 5 | ||||
-rw-r--r-- | net/disk_cache/blockfile/mapped_file.cc | 11 | ||||
-rw-r--r-- | net/disk_cache/blockfile/mapped_file.h | 4 |
4 files changed, 20 insertions, 7 deletions
diff --git a/net/disk_cache/blockfile/backend_impl.cc b/net/disk_cache/blockfile/backend_impl.cc index 85c4e36..af84b10 100644 --- a/net/disk_cache/blockfile/backend_impl.cc +++ b/net/disk_cache/blockfile/backend_impl.cc @@ -1285,7 +1285,7 @@ bool BackendImpl::InitBackingStore(bool* file_created) { return false; index_ = new MappedFile(); - data_ = reinterpret_cast<Index*>(index_->Init(index_name, 0)); + data_ = static_cast<Index*>(index_->Init(index_name, 0)); if (!data_) { LOG(ERROR) << "Unable to map Index file"; return false; @@ -2016,9 +2016,8 @@ bool BackendImpl::CheckIndex() { if (!mask_) mask_ = data_->header.table_len - 1; - // Load the table into memory with a single read. - scoped_ptr<char[]> buf(new char[current_size]); - return index_->Read(buf.get(), current_size, 0); + // Load the table into memory. + return index_->Preload(); } int BackendImpl::CheckAllEntries() { diff --git a/net/disk_cache/blockfile/block_files.cc b/net/disk_cache/blockfile/block_files.cc index 3f4bbf5..ac6114e 100644 --- a/net/disk_cache/blockfile/block_files.cc +++ b/net/disk_cache/blockfile/block_files.cc @@ -508,9 +508,8 @@ bool BlockFiles::OpenBlockFile(int index) { } if (index == 0) { - // Load the links file into memory with a single read. - scoped_ptr<char[]> buf(new char[file_len]); - if (!file->Read(buf.get(), file_len, 0)) + // Load the links file into memory. + if (!file->Preload()) return false; } diff --git a/net/disk_cache/blockfile/mapped_file.cc b/net/disk_cache/blockfile/mapped_file.cc index 4b0f27f..d26cead 100644 --- a/net/disk_cache/blockfile/mapped_file.cc +++ b/net/disk_cache/blockfile/mapped_file.cc @@ -4,6 +4,10 @@ #include "net/disk_cache/blockfile/mapped_file.h" +#include <algorithm> + +#include "base/memory/scoped_ptr.h" + namespace disk_cache { // Note: Most of this class is implemented in platform-specific files. @@ -32,4 +36,11 @@ bool MappedFile::Store(const FileBlock* block, return Write(block->buffer(), block->size(), offset, callback, completed); } +bool MappedFile::Preload() { + size_t file_len = GetLength(); + scoped_ptr<char[]> buf(new char[file_len]); + if (!Read(buf.get(), file_len, 0)) + return false; + return true; +} } // namespace disk_cache diff --git a/net/disk_cache/blockfile/mapped_file.h b/net/disk_cache/blockfile/mapped_file.h index 8a1e40f..f0efa41 100644 --- a/net/disk_cache/blockfile/mapped_file.h +++ b/net/disk_cache/blockfile/mapped_file.h @@ -46,6 +46,10 @@ class NET_EXPORT_PRIVATE MappedFile : public File { // Flush the memory-mapped section to disk (synchronously). void Flush(); + // Heats up the file system cache and make sure the file is fully + // readable (synchronously). + bool Preload(); + private: virtual ~MappedFile(); |