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

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: actually fix test 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 }
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.
1150 if (key_.empty()) { 1146 if (key_.empty()) {
1151 SetKey(synchronous_entry_->key()); 1147 SetKey(synchronous_entry_->key());
1152 } else { 1148 } else {
1153 // This should only be triggered when creating an entry. The key check in 1149 // This should only be triggered when creating an entry. In the open case
1154 // the open case is handled in SimpleBackendImpl. 1150 // the key is either copied from the arguments to open, or checked
1151 // in the synchronous entry.
1155 DCHECK_EQ(key_, synchronous_entry_->key()); 1152 DCHECK_EQ(key_, synchronous_entry_->key());
1156 } 1153 }
1157 UpdateDataFromEntryStat(in_results->entry_stat); 1154 UpdateDataFromEntryStat(in_results->entry_stat);
1158 SIMPLE_CACHE_UMA(TIMES, 1155 SIMPLE_CACHE_UMA(TIMES,
1159 "EntryCreationTime", cache_type_, 1156 "EntryCreationTime", cache_type_,
1160 (base::TimeTicks::Now() - start_time)); 1157 (base::TimeTicks::Now() - start_time));
1161 AdjustOpenEntryCountBy(cache_type_, 1); 1158 AdjustOpenEntryCountBy(cache_type_, 1);
1162 1159
1163 net_log_.AddEvent(end_event_type); 1160 net_log_.AddEvent(end_event_type);
1164 PostClientCallback(completion_callback, net::OK); 1161 PostClientCallback(completion_callback, net::OK);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 } 1393 }
1397 sparse_data_size_ = entry_stat.sparse_data_size(); 1394 sparse_data_size_ = entry_stat.sparse_data_size();
1398 if (!doomed_ && backend_.get()) 1395 if (!doomed_ && backend_.get())
1399 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage()); 1396 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage());
1400 } 1397 }
1401 1398
1402 int64_t SimpleEntryImpl::GetDiskUsage() const { 1399 int64_t SimpleEntryImpl::GetDiskUsage() const {
1403 int64_t file_size = 0; 1400 int64_t file_size = 0;
1404 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { 1401 for (int i = 0; i < kSimpleEntryStreamCount; ++i) {
1405 file_size += 1402 file_size +=
1406 simple_util::GetFileSizeFromKeyAndDataSize(key_, data_size_[i]); 1403 simple_util::GetFileSizeFromDataSize(key_.size(), data_size_[i]);
1407 } 1404 }
1408 file_size += sparse_data_size_; 1405 file_size += sparse_data_size_;
1409 return file_size; 1406 return file_size;
1410 } 1407 }
1411 1408
1412 void SimpleEntryImpl::RecordReadIsParallelizable( 1409 void SimpleEntryImpl::RecordReadIsParallelizable(
1413 const SimpleEntryOperation& operation) const { 1410 const SimpleEntryOperation& operation) const {
1414 if (!executing_operation_) 1411 if (!executing_operation_)
1415 return; 1412 return;
1416 // Used in histograms, please only add entries at the end. 1413 // Used in histograms, please only add entries at the end.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 } 1549 }
1553 crc32s_end_offset_[stream_index] = offset + length; 1550 crc32s_end_offset_[stream_index] = offset + length;
1554 } else if (offset < crc32s_end_offset_[stream_index]) { 1551 } else if (offset < crc32s_end_offset_[stream_index]) {
1555 // If a range for which the crc32 was already computed is rewritten, the 1552 // If a range for which the crc32 was already computed is rewritten, the
1556 // computation of the crc32 need to start from 0 again. 1553 // computation of the crc32 need to start from 0 again.
1557 crc32s_end_offset_[stream_index] = 0; 1554 crc32s_end_offset_[stream_index] = 0;
1558 } 1555 }
1559 } 1556 }
1560 1557
1561 } // namespace disk_cache 1558 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | net/disk_cache/simple/simple_synchronous_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698