OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http/mock_http_cache.h" | 5 #include "net/http/mock_http_cache.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 it->second->Release(); | 527 it->second->Release(); |
528 entries_.clear(); | 528 entries_.clear(); |
529 } | 529 } |
530 | 530 |
531 void MockDiskCache::CallbackLater(const CompletionCallback& callback, | 531 void MockDiskCache::CallbackLater(const CompletionCallback& callback, |
532 int result) { | 532 int result) { |
533 base::ThreadTaskRunnerHandle::Get()->PostTask( | 533 base::ThreadTaskRunnerHandle::Get()->PostTask( |
534 FROM_HERE, base::Bind(&CallbackForwader, callback, result)); | 534 FROM_HERE, base::Bind(&CallbackForwader, callback, result)); |
535 } | 535 } |
536 | 536 |
537 bool MockDiskCache::IsDiskEntryDoomed(const std::string& key) { | |
jkarlin
2017/04/20 15:05:40
It looks as if MockDiskCache::DoomEntry doesn't ca
| |
538 auto it = entries_.find(key); | |
539 if (it == entries_.end()) | |
540 return false; | |
541 return it->second->is_doomed(); | |
542 } | |
543 | |
537 //----------------------------------------------------------------------------- | 544 //----------------------------------------------------------------------------- |
538 | 545 |
539 int MockBackendFactory::CreateBackend( | 546 int MockBackendFactory::CreateBackend( |
540 NetLog* net_log, | 547 NetLog* net_log, |
541 std::unique_ptr<disk_cache::Backend>* backend, | 548 std::unique_ptr<disk_cache::Backend>* backend, |
542 const CompletionCallback& callback) { | 549 const CompletionCallback& callback) { |
543 backend->reset(new MockDiskCache()); | 550 backend->reset(new MockDiskCache()); |
544 return OK; | 551 return OK; |
545 } | 552 } |
546 | 553 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 return test_mode; | 647 return test_mode; |
641 | 648 |
642 return g_test_mode; | 649 return g_test_mode; |
643 } | 650 } |
644 | 651 |
645 // Static. | 652 // Static. |
646 void MockHttpCache::SetTestMode(int test_mode) { | 653 void MockHttpCache::SetTestMode(int test_mode) { |
647 g_test_mode = test_mode; | 654 g_test_mode = test_mode; |
648 } | 655 } |
649 | 656 |
657 bool MockHttpCache::IsWriterPresent(const std::string& key) { | |
658 HttpCache::ActiveEntry* entry = http_cache_.FindActiveEntry(key); | |
659 if (entry) | |
660 return entry->writer; | |
661 return false; | |
662 } | |
663 | |
664 bool MockHttpCache::IsHeadersTransactionPresent(const std::string& key) { | |
665 HttpCache::ActiveEntry* entry = http_cache_.FindActiveEntry(key); | |
666 if (entry) | |
667 return entry->headers_transaction; | |
668 return false; | |
669 } | |
670 | |
671 int MockHttpCache::GetCountReaders(const std::string& key) { | |
jkarlin
2017/04/20 15:05:40
return size_t
| |
672 HttpCache::ActiveEntry* entry = http_cache_.FindActiveEntry(key); | |
673 if (entry) | |
674 return entry->readers.size(); | |
675 return false; | |
676 } | |
677 | |
678 int MockHttpCache::GetCountAddToEntryQueue(const std::string& key) { | |
jkarlin
2017/04/20 15:05:40
return size_t
| |
679 HttpCache::ActiveEntry* entry = http_cache_.FindActiveEntry(key); | |
680 if (entry) | |
681 return entry->add_to_entry_queue.size(); | |
682 return false; | |
683 } | |
684 | |
685 int MockHttpCache::GetCountDoneHeadersQueue(const std::string& key) { | |
jkarlin
2017/04/20 15:05:40
return size_t
| |
686 HttpCache::ActiveEntry* entry = http_cache_.FindActiveEntry(key); | |
687 if (entry) | |
688 return entry->done_headers_queue.size(); | |
689 return false; | |
690 } | |
691 | |
650 //----------------------------------------------------------------------------- | 692 //----------------------------------------------------------------------------- |
651 | 693 |
652 int MockDiskCacheNoCB::CreateEntry(const std::string& key, | 694 int MockDiskCacheNoCB::CreateEntry(const std::string& key, |
653 disk_cache::Entry** entry, | 695 disk_cache::Entry** entry, |
654 const CompletionCallback& callback) { | 696 const CompletionCallback& callback) { |
655 return ERR_IO_PENDING; | 697 return ERR_IO_PENDING; |
656 } | 698 } |
657 | 699 |
658 //----------------------------------------------------------------------------- | 700 //----------------------------------------------------------------------------- |
659 | 701 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 if (!callback_.is_null()) { | 738 if (!callback_.is_null()) { |
697 if (!fail_) | 739 if (!fail_) |
698 backend_->reset(new MockDiskCache()); | 740 backend_->reset(new MockDiskCache()); |
699 CompletionCallback cb = callback_; | 741 CompletionCallback cb = callback_; |
700 callback_.Reset(); | 742 callback_.Reset(); |
701 cb.Run(Result()); // This object can be deleted here. | 743 cb.Run(Result()); // This object can be deleted here. |
702 } | 744 } |
703 } | 745 } |
704 | 746 |
705 } // namespace net | 747 } // namespace net |
OLD | NEW |