| 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) { | |
| 538 auto it = entries_.find(key); | |
| 539 if (it == entries_.end()) | |
| 540 return false; | |
| 541 return it->second->is_doomed(); | |
| 542 } | |
| 543 | |
| 544 //----------------------------------------------------------------------------- | 537 //----------------------------------------------------------------------------- |
| 545 | 538 |
| 546 int MockBackendFactory::CreateBackend( | 539 int MockBackendFactory::CreateBackend( |
| 547 NetLog* net_log, | 540 NetLog* net_log, |
| 548 std::unique_ptr<disk_cache::Backend>* backend, | 541 std::unique_ptr<disk_cache::Backend>* backend, |
| 549 const CompletionCallback& callback) { | 542 const CompletionCallback& callback) { |
| 550 backend->reset(new MockDiskCache()); | 543 backend->reset(new MockDiskCache()); |
| 551 return OK; | 544 return OK; |
| 552 } | 545 } |
| 553 | 546 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 return test_mode; | 640 return test_mode; |
| 648 | 641 |
| 649 return g_test_mode; | 642 return g_test_mode; |
| 650 } | 643 } |
| 651 | 644 |
| 652 // Static. | 645 // Static. |
| 653 void MockHttpCache::SetTestMode(int test_mode) { | 646 void MockHttpCache::SetTestMode(int test_mode) { |
| 654 g_test_mode = test_mode; | 647 g_test_mode = test_mode; |
| 655 } | 648 } |
| 656 | 649 |
| 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) { | |
| 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) { | |
| 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) { | |
| 686 HttpCache::ActiveEntry* entry = http_cache_.FindActiveEntry(key); | |
| 687 if (entry) | |
| 688 return entry->done_headers_queue.size(); | |
| 689 return false; | |
| 690 } | |
| 691 | |
| 692 //----------------------------------------------------------------------------- | 650 //----------------------------------------------------------------------------- |
| 693 | 651 |
| 694 int MockDiskCacheNoCB::CreateEntry(const std::string& key, | 652 int MockDiskCacheNoCB::CreateEntry(const std::string& key, |
| 695 disk_cache::Entry** entry, | 653 disk_cache::Entry** entry, |
| 696 const CompletionCallback& callback) { | 654 const CompletionCallback& callback) { |
| 697 return ERR_IO_PENDING; | 655 return ERR_IO_PENDING; |
| 698 } | 656 } |
| 699 | 657 |
| 700 //----------------------------------------------------------------------------- | 658 //----------------------------------------------------------------------------- |
| 701 | 659 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 if (!callback_.is_null()) { | 696 if (!callback_.is_null()) { |
| 739 if (!fail_) | 697 if (!fail_) |
| 740 backend_->reset(new MockDiskCache()); | 698 backend_->reset(new MockDiskCache()); |
| 741 CompletionCallback cb = callback_; | 699 CompletionCallback cb = callback_; |
| 742 callback_.Reset(); | 700 callback_.Reset(); |
| 743 cb.Run(Result()); // This object can be deleted here. | 701 cb.Run(Result()); // This object can be deleted here. |
| 744 } | 702 } |
| 745 } | 703 } |
| 746 | 704 |
| 747 } // namespace net | 705 } // namespace net |
| OLD | NEW |