| 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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 //----------------------------------------------------------------------------- | 501 //----------------------------------------------------------------------------- |
| 502 | 502 |
| 503 MockHttpCache::MockHttpCache() | 503 MockHttpCache::MockHttpCache() |
| 504 : http_cache_(new MockNetworkLayer(), NULL, new MockBackendFactory()) { | 504 : http_cache_(new MockNetworkLayer(), NULL, new MockBackendFactory()) { |
| 505 } | 505 } |
| 506 | 506 |
| 507 MockHttpCache::MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory) | 507 MockHttpCache::MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory) |
| 508 : http_cache_(new MockNetworkLayer(), NULL, disk_cache_factory) { | 508 : http_cache_(new MockNetworkLayer(), NULL, disk_cache_factory) { |
| 509 } | 509 } |
| 510 | 510 |
| 511 MockDiskCache* MockHttpCache::disk_cache() { | 511 disk_cache::Backend* MockHttpCache::backend() { |
| 512 net::TestCompletionCallback cb; | 512 net::TestCompletionCallback cb; |
| 513 disk_cache::Backend* backend; | 513 disk_cache::Backend* backend; |
| 514 int rv = http_cache_.GetBackend(&backend, cb.callback()); | 514 int rv = http_cache_.GetBackend(&backend, cb.callback()); |
| 515 rv = cb.GetResult(rv); | 515 rv = cb.GetResult(rv); |
| 516 return (rv == net::OK) ? static_cast<MockDiskCache*>(backend) : NULL; | 516 return (rv == net::OK) ? backend : NULL; |
| 517 } |
| 518 |
| 519 MockDiskCache* MockHttpCache::disk_cache() { |
| 520 return static_cast<MockDiskCache*>(backend()); |
| 517 } | 521 } |
| 518 | 522 |
| 519 int MockHttpCache::CreateTransaction(scoped_ptr<net::HttpTransaction>* trans) { | 523 int MockHttpCache::CreateTransaction(scoped_ptr<net::HttpTransaction>* trans) { |
| 520 return http_cache_.CreateTransaction(net::DEFAULT_PRIORITY, trans); | 524 return http_cache_.CreateTransaction(net::DEFAULT_PRIORITY, trans); |
| 521 } | 525 } |
| 522 | 526 |
| 523 void MockHttpCache::BypassCacheLock() { | 527 void MockHttpCache::BypassCacheLock() { |
| 524 http_cache_.BypassLockForTest(); | 528 http_cache_.BypassLockForTest(); |
| 525 } | 529 } |
| 526 | 530 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 557 int len = static_cast<int>(pickle.size()); | 561 int len = static_cast<int>(pickle.size()); |
| 558 | 562 |
| 559 int rv = disk_entry->WriteData(0, 0, data.get(), len, cb.callback(), true); | 563 int rv = disk_entry->WriteData(0, 0, data.get(), len, cb.callback(), true); |
| 560 rv = cb.GetResult(rv); | 564 rv = cb.GetResult(rv); |
| 561 return (rv == len); | 565 return (rv == len); |
| 562 } | 566 } |
| 563 | 567 |
| 564 bool MockHttpCache::OpenBackendEntry(const std::string& key, | 568 bool MockHttpCache::OpenBackendEntry(const std::string& key, |
| 565 disk_cache::Entry** entry) { | 569 disk_cache::Entry** entry) { |
| 566 net::TestCompletionCallback cb; | 570 net::TestCompletionCallback cb; |
| 567 int rv = disk_cache()->OpenEntry(key, entry, cb.callback()); | 571 int rv = backend()->OpenEntry(key, entry, cb.callback()); |
| 568 return (cb.GetResult(rv) == net::OK); | 572 return (cb.GetResult(rv) == net::OK); |
| 569 } | 573 } |
| 570 | 574 |
| 571 bool MockHttpCache::CreateBackendEntry(const std::string& key, | 575 bool MockHttpCache::CreateBackendEntry(const std::string& key, |
| 572 disk_cache::Entry** entry, | 576 disk_cache::Entry** entry, |
| 573 net::NetLog* net_log) { | 577 net::NetLog* net_log) { |
| 574 net::TestCompletionCallback cb; | 578 net::TestCompletionCallback cb; |
| 575 int rv = disk_cache()->CreateEntry(key, entry, cb.callback()); | 579 int rv = backend()->CreateEntry(key, entry, cb.callback()); |
| 576 return (cb.GetResult(rv) == net::OK); | 580 return (cb.GetResult(rv) == net::OK); |
| 577 } | 581 } |
| 578 | 582 |
| 579 // Static. | 583 // Static. |
| 580 int MockHttpCache::GetTestMode(int test_mode) { | 584 int MockHttpCache::GetTestMode(int test_mode) { |
| 581 if (!g_test_mode) | 585 if (!g_test_mode) |
| 582 return test_mode; | 586 return test_mode; |
| 583 | 587 |
| 584 return g_test_mode; | 588 return g_test_mode; |
| 585 } | 589 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 void MockBlockingBackendFactory::FinishCreation() { | 638 void MockBlockingBackendFactory::FinishCreation() { |
| 635 block_ = false; | 639 block_ = false; |
| 636 if (!callback_.is_null()) { | 640 if (!callback_.is_null()) { |
| 637 if (!fail_) | 641 if (!fail_) |
| 638 backend_->reset(new MockDiskCache()); | 642 backend_->reset(new MockDiskCache()); |
| 639 net::CompletionCallback cb = callback_; | 643 net::CompletionCallback cb = callback_; |
| 640 callback_.Reset(); | 644 callback_.Reset(); |
| 641 cb.Run(Result()); // This object can be deleted here. | 645 cb.Run(Result()); // This object can be deleted here. |
| 642 } | 646 } |
| 643 } | 647 } |
| OLD | NEW |