| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 scoped_ptr<disk_cache::Backend::Iterator> MockDiskCache::CreateIterator() { | 488 scoped_ptr<disk_cache::Backend::Iterator> MockDiskCache::CreateIterator() { |
| 489 return scoped_ptr<Iterator>(new NotImplementedIterator()); | 489 return scoped_ptr<Iterator>(new NotImplementedIterator()); |
| 490 } | 490 } |
| 491 | 491 |
| 492 void MockDiskCache::GetStats(base::StringPairs* stats) { | 492 void MockDiskCache::GetStats(base::StringPairs* stats) { |
| 493 } | 493 } |
| 494 | 494 |
| 495 void MockDiskCache::OnExternalCacheHit(const std::string& key) { | 495 void MockDiskCache::OnExternalCacheHit(const std::string& key) { |
| 496 } | 496 } |
| 497 | 497 |
| 498 void MockDiskCache::ResetCounts() { |
| 499 open_count_ = 0; |
| 500 create_count_ = 0; |
| 501 } |
| 502 |
| 498 void MockDiskCache::ReleaseAll() { | 503 void MockDiskCache::ReleaseAll() { |
| 499 EntryMap::iterator it = entries_.begin(); | 504 EntryMap::iterator it = entries_.begin(); |
| 500 for (; it != entries_.end(); ++it) | 505 for (; it != entries_.end(); ++it) |
| 501 it->second->Release(); | 506 it->second->Release(); |
| 502 entries_.clear(); | 507 entries_.clear(); |
| 503 } | 508 } |
| 504 | 509 |
| 505 void MockDiskCache::CallbackLater(const CompletionCallback& callback, | 510 void MockDiskCache::CallbackLater(const CompletionCallback& callback, |
| 506 int result) { | 511 int result) { |
| 507 base::ThreadTaskRunnerHandle::Get()->PostTask( | 512 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 } | 549 } |
| 545 | 550 |
| 546 void MockHttpCache::BypassCacheLock() { | 551 void MockHttpCache::BypassCacheLock() { |
| 547 http_cache_.BypassLockForTest(); | 552 http_cache_.BypassLockForTest(); |
| 548 } | 553 } |
| 549 | 554 |
| 550 void MockHttpCache::FailConditionalizations() { | 555 void MockHttpCache::FailConditionalizations() { |
| 551 http_cache_.FailConditionalizationForTest(); | 556 http_cache_.FailConditionalizationForTest(); |
| 552 } | 557 } |
| 553 | 558 |
| 559 void MockHttpCache::ResetCounts() { |
| 560 disk_cache()->ResetCounts(); |
| 561 network_layer()->ResetTransactionCount(); |
| 562 } |
| 563 |
| 554 bool MockHttpCache::ReadResponseInfo(disk_cache::Entry* disk_entry, | 564 bool MockHttpCache::ReadResponseInfo(disk_cache::Entry* disk_entry, |
| 555 HttpResponseInfo* response_info, | 565 HttpResponseInfo* response_info, |
| 556 bool* response_truncated) { | 566 bool* response_truncated) { |
| 557 int size = disk_entry->GetDataSize(0); | 567 int size = disk_entry->GetDataSize(0); |
| 558 | 568 |
| 559 TestCompletionCallback cb; | 569 TestCompletionCallback cb; |
| 560 scoped_refptr<IOBuffer> buffer(new IOBuffer(size)); | 570 scoped_refptr<IOBuffer> buffer(new IOBuffer(size)); |
| 561 int rv = disk_entry->ReadData(0, 0, buffer.get(), size, cb.callback()); | 571 int rv = disk_entry->ReadData(0, 0, buffer.get(), size, cb.callback()); |
| 562 rv = cb.GetResult(rv); | 572 rv = cb.GetResult(rv); |
| 563 EXPECT_EQ(size, rv); | 573 EXPECT_EQ(size, rv); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 if (!callback_.is_null()) { | 671 if (!callback_.is_null()) { |
| 662 if (!fail_) | 672 if (!fail_) |
| 663 backend_->reset(new MockDiskCache()); | 673 backend_->reset(new MockDiskCache()); |
| 664 CompletionCallback cb = callback_; | 674 CompletionCallback cb = callback_; |
| 665 callback_.Reset(); | 675 callback_.Reset(); |
| 666 cb.Run(Result()); // This object can be deleted here. | 676 cb.Run(Result()); // This object can be deleted here. |
| 667 } | 677 } |
| 668 } | 678 } |
| 669 | 679 |
| 670 } // namespace net | 680 } // namespace net |
| OLD | NEW |