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

Side by Side Diff: net/disk_cache/simple/simple_entry_impl.cc

Issue 2922973003: RFC: use some in-memory state in SimpleCache to quickly cache-miss some CantConditionalize cases
Patch Set: - Implement support for oracle bytes in MockHttpCache, so the code actually gets exercised in tests… Created 3 years, 6 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/simple/simple_entry_impl.h" 5 #include "net/disk_cache/simple/simple_entry_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 CreateNetLogSimpleEntryConstructionCallback(this)); 198 CreateNetLogSimpleEntryConstructionCallback(this));
199 } 199 }
200 200
201 void SimpleEntryImpl::SetActiveEntryProxy( 201 void SimpleEntryImpl::SetActiveEntryProxy(
202 std::unique_ptr<ActiveEntryProxy> active_entry_proxy) { 202 std::unique_ptr<ActiveEntryProxy> active_entry_proxy) {
203 DCHECK(!active_entry_proxy_); 203 DCHECK(!active_entry_proxy_);
204 active_entry_proxy_ = std::move(active_entry_proxy); 204 active_entry_proxy_ = std::move(active_entry_proxy);
205 } 205 }
206 206
207 int SimpleEntryImpl::OpenEntry(Entry** out_entry, 207 int SimpleEntryImpl::OpenEntry(Entry** out_entry,
208 const Backend::OracleCallback& oracle,
208 const CompletionCallback& callback) { 209 const CompletionCallback& callback) {
209 DCHECK(backend_.get()); 210 DCHECK(backend_.get());
210 211
211 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_CALL); 212 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_CALL);
212 213
213 bool have_index = backend_->index()->initialized(); 214 bool have_index = backend_->index()->initialized();
214 // This enumeration is used in histograms, add entries only at end. 215 // This enumeration is used in histograms, add entries only at end.
215 enum OpenEntryIndexEnum { 216 enum OpenEntryIndexEnum {
216 INDEX_NOEXIST = 0, 217 INDEX_NOEXIST = 0,
217 INDEX_MISS = 1, 218 INDEX_MISS = 1,
218 INDEX_HIT = 2, 219 INDEX_HIT = 2,
219 INDEX_MAX = 3, 220 INDEX_MAX = 3,
220 }; 221 };
221 OpenEntryIndexEnum open_entry_index_enum = INDEX_NOEXIST; 222 OpenEntryIndexEnum open_entry_index_enum = INDEX_NOEXIST;
223 uint8_t oracle_byte = 0;
222 if (have_index) { 224 if (have_index) {
223 if (backend_->index()->Has(entry_hash_)) 225 if (backend_->index()->HasWithOracleByte(entry_hash_, &oracle_byte))
224 open_entry_index_enum = INDEX_HIT; 226 open_entry_index_enum = INDEX_HIT;
225 else 227 else
226 open_entry_index_enum = INDEX_MISS; 228 open_entry_index_enum = INDEX_MISS;
227 } 229 }
228 SIMPLE_CACHE_UMA(ENUMERATION, 230 SIMPLE_CACHE_UMA(ENUMERATION,
229 "OpenEntryIndexState", cache_type_, 231 "OpenEntryIndexState", cache_type_,
230 open_entry_index_enum, INDEX_MAX); 232 open_entry_index_enum, INDEX_MAX);
231 233
234 if (open_entry_index_enum == INDEX_HIT && !oracle.is_null() &&
235 oracle.Run(oracle_byte) == Backend::OracleJudgement::MISS_AND_DOOM) {
236 // ### UMA this.
237 // ### net log.
238 Doom();
239 return net::ERR_FAILED;
240 }
241
232 // If entry is not known to the index, initiate fast failover to the network. 242 // If entry is not known to the index, initiate fast failover to the network.
233 if (open_entry_index_enum == INDEX_MISS) { 243 if (open_entry_index_enum == INDEX_MISS) {
234 net_log_.AddEventWithNetErrorCode( 244 net_log_.AddEventWithNetErrorCode(
235 net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_END, net::ERR_FAILED); 245 net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_END, net::ERR_FAILED);
236 return net::ERR_FAILED; 246 return net::ERR_FAILED;
237 } 247 }
238 248
239 pending_operations_.push(SimpleEntryOperation::OpenOperation( 249 pending_operations_.push(SimpleEntryOperation::OpenOperation(
240 this, have_index, callback, out_entry)); 250 this, have_index, callback, out_entry));
241 RunNextOperationIfNeeded(); 251 RunNextOperationIfNeeded();
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { 1366 for (int i = 0; i < kSimpleEntryStreamCount; ++i) {
1357 data_size_[i] = entry_stat.data_size(i); 1367 data_size_[i] = entry_stat.data_size(i);
1358 } 1368 }
1359 sparse_data_size_ = entry_stat.sparse_data_size(); 1369 sparse_data_size_ = entry_stat.sparse_data_size();
1360 if (!doomed_ && backend_.get()) { 1370 if (!doomed_ && backend_.get()) {
1361 backend_->index()->UpdateEntrySize( 1371 backend_->index()->UpdateEntrySize(
1362 entry_hash_, base::checked_cast<uint32_t>(GetDiskUsage())); 1372 entry_hash_, base::checked_cast<uint32_t>(GetDiskUsage()));
1363 } 1373 }
1364 } 1374 }
1365 1375
1376 void SimpleEntryImpl::SetOracleByte(uint8_t oracle_byte) {
1377 DCHECK(io_thread_checker_.CalledOnValidThread());
1378 if (!doomed_ && backend_.get()) {
1379 backend_->index()->UpdateEntryOracleByte(entry_hash_, oracle_byte);
1380 }
1381 }
1382
1366 int64_t SimpleEntryImpl::GetDiskUsage() const { 1383 int64_t SimpleEntryImpl::GetDiskUsage() const {
1367 int64_t file_size = 0; 1384 int64_t file_size = 0;
1368 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { 1385 for (int i = 0; i < kSimpleEntryStreamCount; ++i) {
1369 file_size += 1386 file_size +=
1370 simple_util::GetFileSizeFromDataSize(key_.size(), data_size_[i]); 1387 simple_util::GetFileSizeFromDataSize(key_.size(), data_size_[i]);
1371 } 1388 }
1372 file_size += sparse_data_size_; 1389 file_size += sparse_data_size_;
1373 return file_size; 1390 return file_size;
1374 } 1391 }
1375 1392
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 } 1533 }
1517 crc32s_end_offset_[stream_index] = offset + length; 1534 crc32s_end_offset_[stream_index] = offset + length;
1518 } else if (offset < crc32s_end_offset_[stream_index]) { 1535 } else if (offset < crc32s_end_offset_[stream_index]) {
1519 // If a range for which the crc32 was already computed is rewritten, the 1536 // If a range for which the crc32 was already computed is rewritten, the
1520 // computation of the crc32 need to start from 0 again. 1537 // computation of the crc32 need to start from 0 again.
1521 crc32s_end_offset_[stream_index] = 0; 1538 crc32s_end_offset_[stream_index] = 0;
1522 } 1539 }
1523 } 1540 }
1524 1541
1525 } // namespace disk_cache 1542 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698