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

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

Issue 206453003: Move Preload() code to MappedFile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reworded comment Created 6 years, 8 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
« no previous file with comments | « no previous file | net/disk_cache/blockfile/block_files.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/backend_impl.h" 5 #include "net/disk_cache/blockfile/backend_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 1278
1279 bool ret = true; 1279 bool ret = true;
1280 if (*file_created) 1280 if (*file_created)
1281 ret = CreateBackingStore(file.get()); 1281 ret = CreateBackingStore(file.get());
1282 1282
1283 file = NULL; 1283 file = NULL;
1284 if (!ret) 1284 if (!ret)
1285 return false; 1285 return false;
1286 1286
1287 index_ = new MappedFile(); 1287 index_ = new MappedFile();
1288 data_ = reinterpret_cast<Index*>(index_->Init(index_name, 0)); 1288 data_ = static_cast<Index*>(index_->Init(index_name, 0));
1289 if (!data_) { 1289 if (!data_) {
1290 LOG(ERROR) << "Unable to map Index file"; 1290 LOG(ERROR) << "Unable to map Index file";
1291 return false; 1291 return false;
1292 } 1292 }
1293 1293
1294 if (index_->GetLength() < sizeof(Index)) { 1294 if (index_->GetLength() < sizeof(Index)) {
1295 // We verify this again on CheckIndex() but it's easier to make sure now 1295 // We verify this again on CheckIndex() but it's easier to make sure now
1296 // that the header is there. 1296 // that the header is there.
1297 LOG(ERROR) << "Corrupt Index file"; 1297 LOG(ERROR) << "Corrupt Index file";
1298 return false; 1298 return false;
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 #endif 2009 #endif
2010 2010
2011 if (data_->header.num_entries < 0) { 2011 if (data_->header.num_entries < 0) {
2012 LOG(ERROR) << "Invalid number of entries"; 2012 LOG(ERROR) << "Invalid number of entries";
2013 return false; 2013 return false;
2014 } 2014 }
2015 2015
2016 if (!mask_) 2016 if (!mask_)
2017 mask_ = data_->header.table_len - 1; 2017 mask_ = data_->header.table_len - 1;
2018 2018
2019 // Load the table into memory with a single read. 2019 // Load the table into memory.
2020 scoped_ptr<char[]> buf(new char[current_size]); 2020 return index_->Preload();
2021 return index_->Read(buf.get(), current_size, 0);
2022 } 2021 }
2023 2022
2024 int BackendImpl::CheckAllEntries() { 2023 int BackendImpl::CheckAllEntries() {
2025 int num_dirty = 0; 2024 int num_dirty = 0;
2026 int num_entries = 0; 2025 int num_entries = 0;
2027 DCHECK(mask_ < kuint32max); 2026 DCHECK(mask_ < kuint32max);
2028 for (unsigned int i = 0; i <= mask_; i++) { 2027 for (unsigned int i = 0; i <= mask_; i++) {
2029 Addr address(data_->table[i]); 2028 Addr address(data_->table[i]);
2030 if (!address.is_initialized()) 2029 if (!address.is_initialized())
2031 continue; 2030 continue;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 if (total_memory > kMaxBuffersSize || total_memory <= 0) 2090 if (total_memory > kMaxBuffersSize || total_memory <= 0)
2092 total_memory = kMaxBuffersSize; 2091 total_memory = kMaxBuffersSize;
2093 2092
2094 done = true; 2093 done = true;
2095 } 2094 }
2096 2095
2097 return static_cast<int>(total_memory); 2096 return static_cast<int>(total_memory);
2098 } 2097 }
2099 2098
2100 } // namespace disk_cache 2099 } // namespace disk_cache
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/blockfile/block_files.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698