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

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

Issue 542733002: Remove void** from disk_cache interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: narrow given upstream Created 6 years, 3 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 10
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 base::Bind(&SimpleBackendImpl::IndexReadyForDoom, AsWeakPtr(), 466 base::Bind(&SimpleBackendImpl::IndexReadyForDoom, AsWeakPtr(),
467 initial_time, end_time, callback)); 467 initial_time, end_time, callback));
468 } 468 }
469 469
470 int SimpleBackendImpl::DoomEntriesSince( 470 int SimpleBackendImpl::DoomEntriesSince(
471 const Time initial_time, 471 const Time initial_time,
472 const CompletionCallback& callback) { 472 const CompletionCallback& callback) {
473 return DoomEntriesBetween(initial_time, Time(), callback); 473 return DoomEntriesBetween(initial_time, Time(), callback);
474 } 474 }
475 475
476 int SimpleBackendImpl::OpenNextEntry(void** iter, 476 int SimpleBackendImpl::OpenNextEntry(Iterator* iter,
477 Entry** next_entry, 477 Entry** next_entry,
478 const CompletionCallback& callback) { 478 const CompletionCallback& callback) {
479 CompletionCallback get_next_entry = 479 CompletionCallback open_next_entry_impl =
480 base::Bind(&SimpleBackendImpl::GetNextEntryInIterator, AsWeakPtr(), iter, 480 base::Bind(&SimpleBackendImpl::OpenNextEntryImpl, AsWeakPtr(), iter,
481 next_entry, callback); 481 next_entry, callback);
482 return index_->ExecuteWhenReady(get_next_entry); 482 return index_->ExecuteWhenReady(open_next_entry_impl);
483 }
484
485 void SimpleBackendImpl::EndEnumeration(void** iter) {
486 SimpleIndex::HashList* entry_list =
487 static_cast<SimpleIndex::HashList*>(*iter);
488 delete entry_list;
489 *iter = NULL;
490 } 483 }
491 484
492 void SimpleBackendImpl::GetStats( 485 void SimpleBackendImpl::GetStats(
493 std::vector<std::pair<std::string, std::string> >* stats) { 486 std::vector<std::pair<std::string, std::string> >* stats) {
494 std::pair<std::string, std::string> item; 487 std::pair<std::string, std::string> item;
495 item.first = "Cache type"; 488 item.first = "Cache type";
496 item.second = "Simple Cache"; 489 item.second = "Simple Cache";
497 stats->push_back(item); 490 stats->push_back(item);
498 } 491 }
499 492
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 return active_it->second->DoomEntry(callback); 600 return active_it->second->DoomEntry(callback);
608 601
609 // There's no pending dooms, nor any open entry. We can make a trivial 602 // There's no pending dooms, nor any open entry. We can make a trivial
610 // call to DoomEntries() to delete this entry. 603 // call to DoomEntries() to delete this entry.
611 std::vector<uint64> entry_hash_vector; 604 std::vector<uint64> entry_hash_vector;
612 entry_hash_vector.push_back(entry_hash); 605 entry_hash_vector.push_back(entry_hash);
613 DoomEntries(&entry_hash_vector, callback); 606 DoomEntries(&entry_hash_vector, callback);
614 return net::ERR_IO_PENDING; 607 return net::ERR_IO_PENDING;
615 } 608 }
616 609
617 void SimpleBackendImpl::GetNextEntryInIterator( 610 void SimpleBackendImpl::OpenNextEntryImpl(Iterator* iter,
618 void** iter, 611 Entry** next_entry,
619 Entry** next_entry, 612 const CompletionCallback& callback,
620 const CompletionCallback& callback, 613 int index_initialization_error_code) {
621 int error_code) { 614 if (index_initialization_error_code != net::OK) {
622 if (error_code != net::OK) { 615 callback.Run(index_initialization_error_code);
623 callback.Run(error_code);
624 return; 616 return;
625 } 617 }
626 if (*iter == NULL) { 618
627 *iter = index()->GetAllHashes().release(); 619 class State : public EnumerationState {
628 } 620 public:
629 SimpleIndex::HashList* entry_list = 621 explicit State(scoped_ptr<std::vector<uint64> > hashes_to_enumerate) {
630 static_cast<SimpleIndex::HashList*>(*iter); 622 hashes_to_enumerate_.swap(*hashes_to_enumerate);
631 while (entry_list->size() > 0) { 623 }
632 uint64 entry_hash = entry_list->back(); 624 virtual ~State() {}
633 entry_list->pop_back(); 625
626 std::vector<uint64>& hashes_to_enumerate() { return hashes_to_enumerate_; }
627
628 private:
629 std::vector<uint64> hashes_to_enumerate_;
630 };
631
632 if (!*iter)
633 iter->reset(new State(index()->GetAllHashes().Pass()));
634 State* state = static_cast<State*>(iter->get());
635
636 while (!state->hashes_to_enumerate().empty()) {
637 uint64 entry_hash = state->hashes_to_enumerate().back();
638 state->hashes_to_enumerate().pop_back();
634 if (index()->Has(entry_hash)) { 639 if (index()->Has(entry_hash)) {
635 *next_entry = NULL; 640 *next_entry = NULL;
636 CompletionCallback continue_iteration = base::Bind( 641 CompletionCallback continue_iteration = base::Bind(
637 &SimpleBackendImpl::CheckIterationReturnValue, 642 &SimpleBackendImpl::CheckIterationReturnValue,
638 AsWeakPtr(), 643 AsWeakPtr(),
639 iter, 644 iter,
640 next_entry, 645 next_entry,
641 callback); 646 callback);
642 int error_code_open = OpenEntryFromHash(entry_hash, 647 int error_code_open = OpenEntryFromHash(entry_hash,
643 next_entry, 648 next_entry,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 final_code = net::ERR_FAILED; 705 final_code = net::ERR_FAILED;
701 } else { 706 } else {
702 DCHECK_EQ(simple_entry->entry_hash(), simple_util::GetEntryHashKey(key)); 707 DCHECK_EQ(simple_entry->entry_hash(), simple_util::GetEntryHashKey(key));
703 } 708 }
704 SIMPLE_CACHE_UMA(BOOLEAN, "KeyMatchedOnOpen", cache_type_, key_matches); 709 SIMPLE_CACHE_UMA(BOOLEAN, "KeyMatchedOnOpen", cache_type_, key_matches);
705 } 710 }
706 callback.Run(final_code); 711 callback.Run(final_code);
707 } 712 }
708 713
709 void SimpleBackendImpl::CheckIterationReturnValue( 714 void SimpleBackendImpl::CheckIterationReturnValue(
710 void** iter, 715 Iterator* iter,
711 Entry** entry, 716 Entry** entry,
712 const CompletionCallback& callback, 717 const CompletionCallback& callback,
713 int error_code) { 718 int error_code) {
714 if (error_code == net::ERR_FAILED) { 719 if (error_code == net::ERR_FAILED) {
715 OpenNextEntry(iter, entry, callback); 720 OpenNextEntry(iter, entry, callback);
716 return; 721 return;
717 } 722 }
718 callback.Run(error_code); 723 callback.Run(error_code);
719 } 724 }
720 725
721 void SimpleBackendImpl::DoomEntriesComplete( 726 void SimpleBackendImpl::DoomEntriesComplete(
722 scoped_ptr<std::vector<uint64> > entry_hashes, 727 scoped_ptr<std::vector<uint64> > entry_hashes,
723 const net::CompletionCallback& callback, 728 const net::CompletionCallback& callback,
724 int result) { 729 int result) {
725 std::for_each( 730 std::for_each(
726 entry_hashes->begin(), entry_hashes->end(), 731 entry_hashes->begin(), entry_hashes->end(),
727 std::bind1st(std::mem_fun(&SimpleBackendImpl::OnDoomComplete), 732 std::bind1st(std::mem_fun(&SimpleBackendImpl::OnDoomComplete),
728 this)); 733 this));
729 callback.Run(result); 734 callback.Run(result);
730 } 735 }
731 736
732 void SimpleBackendImpl::FlushWorkerPoolForTesting() { 737 void SimpleBackendImpl::FlushWorkerPoolForTesting() {
733 if (g_sequenced_worker_pool) 738 if (g_sequenced_worker_pool)
734 g_sequenced_worker_pool->FlushForTesting(); 739 g_sequenced_worker_pool->FlushForTesting();
735 } 740 }
736 741
737 } // namespace disk_cache 742 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698