OLD | NEW |
---|---|
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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 int SimpleBackendImpl::OpenNextEntry(void** iter, | 476 int SimpleBackendImpl::OpenNextEntry(void** iter, |
477 Entry** next_entry, | 477 Entry** next_entry, |
478 const CompletionCallback& callback) { | 478 const CompletionCallback& callback) { |
479 CompletionCallback get_next_entry = | 479 CompletionCallback get_next_entry = |
480 base::Bind(&SimpleBackendImpl::GetNextEntryInIterator, AsWeakPtr(), iter, | 480 base::Bind(&SimpleBackendImpl::GetNextEntryInIterator, AsWeakPtr(), iter, |
481 next_entry, callback); | 481 next_entry, callback); |
482 return index_->ExecuteWhenReady(get_next_entry); | 482 return index_->ExecuteWhenReady(get_next_entry); |
483 } | 483 } |
484 | 484 |
485 void SimpleBackendImpl::EndEnumeration(void** iter) { | 485 void SimpleBackendImpl::EndEnumeration(void** iter) { |
486 SimpleIndex::HashList* entry_list = | 486 const ptrdiff_t ptrdiff_enumeration_id = reinterpret_cast<ptrdiff_t>(*iter); |
487 static_cast<SimpleIndex::HashList*>(*iter); | 487 const ActiveEnumerationMap::KeyType enumeration_id = ptrdiff_enumeration_id; |
jsbell
2014/09/03 22:30:42
How about a helper to hide and self-document the r
gavinp
2014/09/12 21:01:04
Good idea. I threw in some COMPILE_ASSERTS around
| |
488 delete entry_list; | 488 DCHECK_EQ(enumeration_id, ptrdiff_enumeration_id); |
489 active_enumerations_.Remove(enumeration_id); | |
489 *iter = NULL; | 490 *iter = NULL; |
490 } | 491 } |
491 | 492 |
492 void SimpleBackendImpl::GetStats( | 493 void SimpleBackendImpl::GetStats( |
493 std::vector<std::pair<std::string, std::string> >* stats) { | 494 std::vector<std::pair<std::string, std::string> >* stats) { |
494 std::pair<std::string, std::string> item; | 495 std::pair<std::string, std::string> item; |
495 item.first = "Cache type"; | 496 item.first = "Cache type"; |
496 item.second = "Simple Cache"; | 497 item.second = "Simple Cache"; |
497 stats->push_back(item); | 498 stats->push_back(item); |
498 } | 499 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 | 617 |
617 void SimpleBackendImpl::GetNextEntryInIterator( | 618 void SimpleBackendImpl::GetNextEntryInIterator( |
618 void** iter, | 619 void** iter, |
619 Entry** next_entry, | 620 Entry** next_entry, |
620 const CompletionCallback& callback, | 621 const CompletionCallback& callback, |
621 int error_code) { | 622 int error_code) { |
622 if (error_code != net::OK) { | 623 if (error_code != net::OK) { |
623 callback.Run(error_code); | 624 callback.Run(error_code); |
624 return; | 625 return; |
625 } | 626 } |
627 std::vector<uint64>* entry_list = NULL; | |
clamy
2014/09/03 19:47:48
nit: The previous version used the type SimpleInde
gavinp
2014/09/12 21:01:04
No. Using SimpleIndex::HashList was actually the o
| |
626 if (*iter == NULL) { | 628 if (*iter == NULL) { |
627 *iter = index()->GetAllHashes().release(); | 629 const ActiveEnumerationMap::KeyType new_enumeration_id = |
630 active_enumerations_.Add( | |
631 entry_list = index()->GetAllHashes().release()); | |
632 const ptrdiff_t ptrdiff_new_enumeration_id = new_enumeration_id; | |
633 DCHECK_EQ(new_enumeration_id, ptrdiff_new_enumeration_id); | |
634 *iter = reinterpret_cast<void*>(ptrdiff_new_enumeration_id); | |
635 } else { | |
636 const ptrdiff_t ptrdiff_enumeration_id = | |
637 reinterpret_cast<ptrdiff_t>(*iter); | |
638 const ActiveEnumerationMap::KeyType enumeration_id = ptrdiff_enumeration_id; | |
clamy
2014/09/03 19:47:48
This is really ugly, but I guess we don't really h
gavinp
2014/09/12 21:01:04
I will do this via a helper as jsbell suggested.
| |
639 DCHECK_EQ(ptrdiff_enumeration_id, enumeration_id); | |
640 entry_list = active_enumerations_.Lookup(enumeration_id); | |
628 } | 641 } |
629 SimpleIndex::HashList* entry_list = | |
630 static_cast<SimpleIndex::HashList*>(*iter); | |
631 while (entry_list->size() > 0) { | 642 while (entry_list->size() > 0) { |
632 uint64 entry_hash = entry_list->back(); | 643 uint64 entry_hash = entry_list->back(); |
633 entry_list->pop_back(); | 644 entry_list->pop_back(); |
634 if (index()->Has(entry_hash)) { | 645 if (index()->Has(entry_hash)) { |
635 *next_entry = NULL; | 646 *next_entry = NULL; |
636 CompletionCallback continue_iteration = base::Bind( | 647 CompletionCallback continue_iteration = base::Bind( |
637 &SimpleBackendImpl::CheckIterationReturnValue, | 648 &SimpleBackendImpl::CheckIterationReturnValue, |
638 AsWeakPtr(), | 649 AsWeakPtr(), |
639 iter, | 650 iter, |
640 next_entry, | 651 next_entry, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 this)); | 739 this)); |
729 callback.Run(result); | 740 callback.Run(result); |
730 } | 741 } |
731 | 742 |
732 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 743 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
733 if (g_sequenced_worker_pool) | 744 if (g_sequenced_worker_pool) |
734 g_sequenced_worker_pool->FlushForTesting(); | 745 g_sequenced_worker_pool->FlushForTesting(); |
735 } | 746 } |
736 | 747 |
737 } // namespace disk_cache | 748 } // namespace disk_cache |
OLD | NEW |