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

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

Issue 1977863003: SimpleCache: open with fewer seeks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@open-speeder-macbetter
Patch Set: remediate Created 4 years, 7 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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 return; 689 return;
690 } 690 }
691 691
692 DCHECK_EQ(STATE_UNINITIALIZED, state_); 692 DCHECK_EQ(STATE_UNINITIALIZED, state_);
693 DCHECK(!synchronous_entry_); 693 DCHECK(!synchronous_entry_);
694 state_ = STATE_IO_PENDING; 694 state_ = STATE_IO_PENDING;
695 const base::TimeTicks start_time = base::TimeTicks::Now(); 695 const base::TimeTicks start_time = base::TimeTicks::Now();
696 std::unique_ptr<SimpleEntryCreationResults> results( 696 std::unique_ptr<SimpleEntryCreationResults> results(
697 new SimpleEntryCreationResults(SimpleEntryStat( 697 new SimpleEntryCreationResults(SimpleEntryStat(
698 last_used_, last_modified_, data_size_, sparse_data_size_))); 698 last_used_, last_modified_, data_size_, sparse_data_size_)));
699 Closure task = base::Bind(&SimpleSynchronousEntry::OpenEntry, 699 Closure task =
700 cache_type_, 700 base::Bind(&SimpleSynchronousEntry::OpenEntry, cache_type_, path_, key_,
701 path_, 701 entry_hash_, have_index, results.get());
702 entry_hash_, 702 Closure reply =
703 have_index, 703 base::Bind(&SimpleEntryImpl::CreationOperationComplete, this, callback,
704 results.get()); 704 start_time, base::Passed(&results), out_entry,
705 Closure reply = base::Bind(&SimpleEntryImpl::CreationOperationComplete, 705 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END);
706 this,
707 callback,
708 start_time,
709 base::Passed(&results),
710 out_entry,
711 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END);
712 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 706 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
713 } 707 }
714 708
715 void SimpleEntryImpl::CreateEntryInternal(bool have_index, 709 void SimpleEntryImpl::CreateEntryInternal(bool have_index,
716 const CompletionCallback& callback, 710 const CompletionCallback& callback,
717 Entry** out_entry) { 711 Entry** out_entry) {
718 ScopedOperationRunner operation_runner(this); 712 ScopedOperationRunner operation_runner(this);
719 713
720 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_BEGIN); 714 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_BEGIN);
721 715
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 1134
1141 state_ = STATE_READY; 1135 state_ = STATE_READY;
1142 synchronous_entry_ = in_results->sync_entry; 1136 synchronous_entry_ = in_results->sync_entry;
1143 if (in_results->stream_0_data.get()) { 1137 if (in_results->stream_0_data.get()) {
1144 stream_0_data_ = in_results->stream_0_data; 1138 stream_0_data_ = in_results->stream_0_data;
1145 // The crc was read in SimpleSynchronousEntry. 1139 // The crc was read in SimpleSynchronousEntry.
1146 crc_check_state_[0] = CRC_CHECK_DONE; 1140 crc_check_state_[0] = CRC_CHECK_DONE;
1147 crc32s_[0] = in_results->stream_0_crc32; 1141 crc32s_[0] = in_results->stream_0_crc32;
1148 crc32s_end_offset_[0] = in_results->entry_stat.data_size(0); 1142 crc32s_end_offset_[0] = in_results->entry_stat.data_size(0);
1149 } 1143 }
1150 if (key_.empty()) { 1144 // If this entry was opened by hash, key_ could still be empty. If so, update
1145 // it with the key read from the synchronous entry.
1146 if (key_.empty())
1151 SetKey(synchronous_entry_->key()); 1147 SetKey(synchronous_entry_->key());
1152 } else {
1153 // This should only be triggered when creating an entry. The key check in
1154 // the open case is handled in SimpleBackendImpl.
1155 DCHECK_EQ(key_, synchronous_entry_->key());
1156 }
Randy Smith (Not in Mondays) 2016/05/18 16:41:30 Why eliminate the DCHECK?
gavinp 2016/05/18 19:05:03 I put it back in, because an updated comment was d
1157 UpdateDataFromEntryStat(in_results->entry_stat); 1148 UpdateDataFromEntryStat(in_results->entry_stat);
1158 SIMPLE_CACHE_UMA(TIMES, 1149 SIMPLE_CACHE_UMA(TIMES,
1159 "EntryCreationTime", cache_type_, 1150 "EntryCreationTime", cache_type_,
1160 (base::TimeTicks::Now() - start_time)); 1151 (base::TimeTicks::Now() - start_time));
1161 AdjustOpenEntryCountBy(cache_type_, 1); 1152 AdjustOpenEntryCountBy(cache_type_, 1);
1162 1153
1163 net_log_.AddEvent(end_event_type); 1154 net_log_.AddEvent(end_event_type);
1164 PostClientCallback(completion_callback, net::OK); 1155 PostClientCallback(completion_callback, net::OK);
1165 } 1156 }
1166 1157
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 } 1387 }
1397 sparse_data_size_ = entry_stat.sparse_data_size(); 1388 sparse_data_size_ = entry_stat.sparse_data_size();
1398 if (!doomed_ && backend_.get()) 1389 if (!doomed_ && backend_.get())
1399 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage()); 1390 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage());
1400 } 1391 }
1401 1392
1402 int64_t SimpleEntryImpl::GetDiskUsage() const { 1393 int64_t SimpleEntryImpl::GetDiskUsage() const {
1403 int64_t file_size = 0; 1394 int64_t file_size = 0;
1404 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { 1395 for (int i = 0; i < kSimpleEntryStreamCount; ++i) {
1405 file_size += 1396 file_size +=
1406 simple_util::GetFileSizeFromKeyAndDataSize(key_, data_size_[i]); 1397 simple_util::GetFileSizeFromDataSize(key_.size(), data_size_[i]);
1407 } 1398 }
1408 file_size += sparse_data_size_; 1399 file_size += sparse_data_size_;
1409 return file_size; 1400 return file_size;
1410 } 1401 }
1411 1402
1412 void SimpleEntryImpl::RecordReadIsParallelizable( 1403 void SimpleEntryImpl::RecordReadIsParallelizable(
1413 const SimpleEntryOperation& operation) const { 1404 const SimpleEntryOperation& operation) const {
1414 if (!executing_operation_) 1405 if (!executing_operation_)
1415 return; 1406 return;
1416 // Used in histograms, please only add entries at the end. 1407 // Used in histograms, please only add entries at the end.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 } 1543 }
1553 crc32s_end_offset_[stream_index] = offset + length; 1544 crc32s_end_offset_[stream_index] = offset + length;
1554 } else if (offset < crc32s_end_offset_[stream_index]) { 1545 } else if (offset < crc32s_end_offset_[stream_index]) {
1555 // If a range for which the crc32 was already computed is rewritten, the 1546 // If a range for which the crc32 was already computed is rewritten, the
1556 // computation of the crc32 need to start from 0 again. 1547 // computation of the crc32 need to start from 0 again.
1557 crc32s_end_offset_[stream_index] = 0; 1548 crc32s_end_offset_[stream_index] = 0;
1558 } 1549 }
1559 } 1550 }
1560 1551
1561 } // namespace disk_cache 1552 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698