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 active_enumerations_.Remove(IteratorToEnumerationId(iter)); |
487 static_cast<SimpleIndex::HashList*>(*iter); | |
488 delete entry_list; | |
489 *iter = NULL; | 487 *iter = NULL; |
490 } | 488 } |
491 | 489 |
492 void SimpleBackendImpl::GetStats( | 490 void SimpleBackendImpl::GetStats( |
493 std::vector<std::pair<std::string, std::string> >* stats) { | 491 std::vector<std::pair<std::string, std::string> >* stats) { |
494 std::pair<std::string, std::string> item; | 492 std::pair<std::string, std::string> item; |
495 item.first = "Cache type"; | 493 item.first = "Cache type"; |
496 item.second = "Simple Cache"; | 494 item.second = "Simple Cache"; |
497 stats->push_back(item); | 495 stats->push_back(item); |
498 } | 496 } |
499 | 497 |
500 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { | 498 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { |
501 index_->UseIfExists(simple_util::GetEntryHashKey(key)); | 499 index_->UseIfExists(simple_util::GetEntryHashKey(key)); |
502 } | 500 } |
503 | 501 |
| 502 // static |
| 503 SimpleBackendImpl::ActiveEnumerationMap::KeyType |
| 504 SimpleBackendImpl::IteratorToEnumerationId(void** iter) { |
| 505 COMPILE_ASSERT(sizeof(ptrdiff_t) >= sizeof(*iter), |
| 506 integer_type_must_fit_ptr_type_for_cast_to_be_reversible); |
| 507 const ptrdiff_t ptrdiff_enumeration_id = reinterpret_cast<ptrdiff_t>(*iter); |
| 508 const ActiveEnumerationMap::KeyType enumeration_id = ptrdiff_enumeration_id; |
| 509 DCHECK_EQ(enumeration_id, ptrdiff_enumeration_id); |
| 510 return enumeration_id; |
| 511 } |
| 512 |
| 513 // static |
| 514 void* SimpleBackendImpl::EnumerationIdToIterator( |
| 515 ActiveEnumerationMap::KeyType enumeration_id) { |
| 516 const ptrdiff_t ptrdiff_enumeration_id = enumeration_id; |
| 517 DCHECK_EQ(enumeration_id, ptrdiff_enumeration_id); |
| 518 COMPILE_ASSERT(sizeof(ptrdiff_t) >= sizeof(void*), |
| 519 integer_type_must_fit_ptr_type_for_cast_to_be_reversible); |
| 520 return reinterpret_cast<void*>(ptrdiff_enumeration_id); |
| 521 } |
| 522 |
504 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, | 523 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, |
505 const DiskStatResult& result) { | 524 const DiskStatResult& result) { |
506 if (result.net_error == net::OK) { | 525 if (result.net_error == net::OK) { |
507 index_->SetMaxSize(result.max_size); | 526 index_->SetMaxSize(result.max_size); |
508 index_->Initialize(result.cache_dir_mtime); | 527 index_->Initialize(result.cache_dir_mtime); |
509 } | 528 } |
510 callback.Run(result.net_error); | 529 callback.Run(result.net_error); |
511 } | 530 } |
512 | 531 |
513 SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk( | 532 SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 | 635 |
617 void SimpleBackendImpl::GetNextEntryInIterator( | 636 void SimpleBackendImpl::GetNextEntryInIterator( |
618 void** iter, | 637 void** iter, |
619 Entry** next_entry, | 638 Entry** next_entry, |
620 const CompletionCallback& callback, | 639 const CompletionCallback& callback, |
621 int error_code) { | 640 int error_code) { |
622 if (error_code != net::OK) { | 641 if (error_code != net::OK) { |
623 callback.Run(error_code); | 642 callback.Run(error_code); |
624 return; | 643 return; |
625 } | 644 } |
| 645 std::vector<uint64>* entry_list = NULL; |
626 if (*iter == NULL) { | 646 if (*iter == NULL) { |
627 *iter = index()->GetAllHashes().release(); | 647 const ActiveEnumerationMap::KeyType new_enumeration_id = |
| 648 active_enumerations_.Add( |
| 649 entry_list = index()->GetAllHashes().release()); |
| 650 *iter = EnumerationIdToIterator(new_enumeration_id); |
| 651 } else { |
| 652 entry_list = active_enumerations_.Lookup(IteratorToEnumerationId(iter)); |
628 } | 653 } |
629 SimpleIndex::HashList* entry_list = | |
630 static_cast<SimpleIndex::HashList*>(*iter); | |
631 while (entry_list->size() > 0) { | 654 while (entry_list->size() > 0) { |
632 uint64 entry_hash = entry_list->back(); | 655 uint64 entry_hash = entry_list->back(); |
633 entry_list->pop_back(); | 656 entry_list->pop_back(); |
634 if (index()->Has(entry_hash)) { | 657 if (index()->Has(entry_hash)) { |
635 *next_entry = NULL; | 658 *next_entry = NULL; |
636 CompletionCallback continue_iteration = base::Bind( | 659 CompletionCallback continue_iteration = base::Bind( |
637 &SimpleBackendImpl::CheckIterationReturnValue, | 660 &SimpleBackendImpl::CheckIterationReturnValue, |
638 AsWeakPtr(), | 661 AsWeakPtr(), |
639 iter, | 662 iter, |
640 next_entry, | 663 next_entry, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 this)); | 751 this)); |
729 callback.Run(result); | 752 callback.Run(result); |
730 } | 753 } |
731 | 754 |
732 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 755 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
733 if (g_sequenced_worker_pool) | 756 if (g_sequenced_worker_pool) |
734 g_sequenced_worker_pool->FlushForTesting(); | 757 g_sequenced_worker_pool->FlushForTesting(); |
735 } | 758 } |
736 | 759 |
737 } // namespace disk_cache | 760 } // namespace disk_cache |
OLD | NEW |