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

Side by Side Diff: net/disk_cache/simple/simple_backend_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_backend_impl.h" 5 #include "net/disk_cache/simple/simple_backend_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdlib> 8 #include <cstdlib>
9 #include <functional> 9 #include <functional>
10 #include <limits> 10 #include <limits>
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 377 }
378 378
379 int32_t SimpleBackendImpl::GetEntryCount() const { 379 int32_t SimpleBackendImpl::GetEntryCount() const {
380 // TODO(pasko): Use directory file count when index is not ready. 380 // TODO(pasko): Use directory file count when index is not ready.
381 return index_->GetEntryCount(); 381 return index_->GetEntryCount();
382 } 382 }
383 383
384 int SimpleBackendImpl::OpenEntry(const std::string& key, 384 int SimpleBackendImpl::OpenEntry(const std::string& key,
385 Entry** entry, 385 Entry** entry,
386 const CompletionCallback& callback) { 386 const CompletionCallback& callback) {
387 return OpenEntryWithOracleByte(key, entry, OracleCallback(), callback);
388 }
389
390 int SimpleBackendImpl::OpenEntryWithOracleByte(
391 const std::string& key,
392 Entry** entry,
393 const OracleCallback& oracle,
394 const CompletionCallback& callback) {
387 const uint64_t entry_hash = simple_util::GetEntryHashKey(key); 395 const uint64_t entry_hash = simple_util::GetEntryHashKey(key);
388 396
389 // TODO(gavinp): Factor out this (not quite completely) repetitive code 397 // TODO(gavinp): Factor out this (not quite completely) repetitive code
390 // block from OpenEntry/CreateEntry/DoomEntry. 398 // block from OpenEntry/CreateEntry/DoomEntry.
391 std::unordered_map<uint64_t, std::vector<Closure>>::iterator it = 399 std::unordered_map<uint64_t, std::vector<Closure>>::iterator it =
392 entries_pending_doom_.find(entry_hash); 400 entries_pending_doom_.find(entry_hash);
393 if (it != entries_pending_doom_.end()) { 401 if (it != entries_pending_doom_.end()) {
394 Callback<int(const net::CompletionCallback&)> operation = 402 Callback<int(const net::CompletionCallback&)> operation =
395 base::Bind(&SimpleBackendImpl::OpenEntry, 403 base::Bind(&SimpleBackendImpl::OpenEntry,
396 base::Unretained(this), key, entry); 404 base::Unretained(this), key, entry);
397 it->second.push_back(base::Bind(&RunOperationAndCallback, 405 it->second.push_back(base::Bind(&RunOperationAndCallback,
398 operation, callback)); 406 operation, callback));
399 return net::ERR_IO_PENDING; 407 return net::ERR_IO_PENDING;
400 } 408 }
401 scoped_refptr<SimpleEntryImpl> simple_entry = 409 scoped_refptr<SimpleEntryImpl> simple_entry =
402 CreateOrFindActiveEntry(entry_hash, key); 410 CreateOrFindActiveEntry(entry_hash, key);
403 return simple_entry->OpenEntry(entry, callback); 411 return simple_entry->OpenEntry(entry, oracle, callback);
404 } 412 }
405 413
406 int SimpleBackendImpl::CreateEntry(const std::string& key, 414 int SimpleBackendImpl::CreateEntry(const std::string& key,
407 Entry** entry, 415 Entry** entry,
408 const CompletionCallback& callback) { 416 const CompletionCallback& callback) {
409 DCHECK_LT(0u, key.size()); 417 DCHECK_LT(0u, key.size());
410 const uint64_t entry_hash = simple_util::GetEntryHashKey(key); 418 const uint64_t entry_hash = simple_util::GetEntryHashKey(key);
411 419
412 std::unordered_map<uint64_t, std::vector<Closure>>::iterator it = 420 std::unordered_map<uint64_t, std::vector<Closure>>::iterator it =
413 entries_pending_doom_.find(entry_hash); 421 entries_pending_doom_.find(entry_hash);
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 EntryMap::iterator has_active = active_entries_.find(entry_hash); 701 EntryMap::iterator has_active = active_entries_.find(entry_hash);
694 if (has_active != active_entries_.end()) { 702 if (has_active != active_entries_.end()) {
695 return OpenEntry(has_active->second->key(), entry, callback); 703 return OpenEntry(has_active->second->key(), entry, callback);
696 } 704 }
697 705
698 scoped_refptr<SimpleEntryImpl> simple_entry = new SimpleEntryImpl( 706 scoped_refptr<SimpleEntryImpl> simple_entry = new SimpleEntryImpl(
699 cache_type_, path_, entry_hash, entry_operations_mode_, this, net_log_); 707 cache_type_, path_, entry_hash, entry_operations_mode_, this, net_log_);
700 CompletionCallback backend_callback = 708 CompletionCallback backend_callback =
701 base::Bind(&SimpleBackendImpl::OnEntryOpenedFromHash, 709 base::Bind(&SimpleBackendImpl::OnEntryOpenedFromHash,
702 AsWeakPtr(), entry_hash, entry, simple_entry, callback); 710 AsWeakPtr(), entry_hash, entry, simple_entry, callback);
703 return simple_entry->OpenEntry(entry, backend_callback); 711 return simple_entry->OpenEntry(entry, OracleCallback(), backend_callback);
704 } 712 }
705 713
706 int SimpleBackendImpl::DoomEntryFromHash(uint64_t entry_hash, 714 int SimpleBackendImpl::DoomEntryFromHash(uint64_t entry_hash,
707 const CompletionCallback& callback) { 715 const CompletionCallback& callback) {
708 Entry** entry = new Entry*(); 716 Entry** entry = new Entry*();
709 std::unique_ptr<Entry*> scoped_entry(entry); 717 std::unique_ptr<Entry*> scoped_entry(entry);
710 718
711 std::unordered_map<uint64_t, std::vector<Closure>>::iterator pending_it = 719 std::unordered_map<uint64_t, std::vector<Closure>>::iterator pending_it =
712 entries_pending_doom_.find(entry_hash); 720 entries_pending_doom_.find(entry_hash);
713 if (pending_it != entries_pending_doom_.end()) { 721 if (pending_it != entries_pending_doom_.end()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 // There was no active entry corresponding to this hash. We've already put 758 // There was no active entry corresponding to this hash. We've already put
751 // the entry opened from hash in the |active_entries_|. We now provide the 759 // the entry opened from hash in the |active_entries_|. We now provide the
752 // proxy object to the entry. 760 // proxy object to the entry.
753 it->second->SetActiveEntryProxy(ActiveEntryProxy::Create(hash, this)); 761 it->second->SetActiveEntryProxy(ActiveEntryProxy::Create(hash, this));
754 callback.Run(net::OK); 762 callback.Run(net::OK);
755 } else { 763 } else {
756 // The entry was made active while we waiting for the open from hash to 764 // The entry was made active while we waiting for the open from hash to
757 // finish. The entry created from hash needs to be closed, and the one 765 // finish. The entry created from hash needs to be closed, and the one
758 // in |active_entries_| can be returned to the caller. 766 // in |active_entries_| can be returned to the caller.
759 simple_entry->Close(); 767 simple_entry->Close();
760 it->second->OpenEntry(entry, callback); 768 it->second->OpenEntry(entry, OracleCallback(), callback);
761 } 769 }
762 } 770 }
763 771
764 void SimpleBackendImpl::DoomEntriesComplete( 772 void SimpleBackendImpl::DoomEntriesComplete(
765 std::unique_ptr<std::vector<uint64_t>> entry_hashes, 773 std::unique_ptr<std::vector<uint64_t>> entry_hashes,
766 const net::CompletionCallback& callback, 774 const net::CompletionCallback& callback,
767 int result) { 775 int result) {
768 for (const uint64_t& entry_hash : *entry_hashes) 776 for (const uint64_t& entry_hash : *entry_hashes)
769 OnDoomComplete(entry_hash); 777 OnDoomComplete(entry_hash);
770 callback.Run(result); 778 callback.Run(result);
771 } 779 }
772 780
773 // static 781 // static
774 void SimpleBackendImpl::FlushWorkerPoolForTesting() { 782 void SimpleBackendImpl::FlushWorkerPoolForTesting() {
775 // We only need to do this if we there is an active task runner. 783 // We only need to do this if we there is an active task runner.
776 if (base::ThreadTaskRunnerHandle::IsSet()) 784 if (base::ThreadTaskRunnerHandle::IsSet())
777 g_sequenced_worker_pool.Get().FlushForTesting(); 785 g_sequenced_worker_pool.Get().FlushForTesting();
778 } 786 }
779 787
780 } // namespace disk_cache 788 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698