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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 473 |
474 void MockDiskCache::CallbackLater(const net::CompletionCallback& callback, | 474 void MockDiskCache::CallbackLater(const net::CompletionCallback& callback, |
475 int result) { | 475 int result) { |
476 base::MessageLoop::current()->PostTask( | 476 base::MessageLoop::current()->PostTask( |
477 FROM_HERE, base::Bind(&CallbackForwader, callback, result)); | 477 FROM_HERE, base::Bind(&CallbackForwader, callback, result)); |
478 } | 478 } |
479 | 479 |
480 //----------------------------------------------------------------------------- | 480 //----------------------------------------------------------------------------- |
481 | 481 |
482 int MockBackendFactory::CreateBackend(net::NetLog* net_log, | 482 int MockBackendFactory::CreateBackend(net::NetLog* net_log, |
483 disk_cache::Backend** backend, | 483 scoped_ptr<disk_cache::Backend>* backend, |
484 const net::CompletionCallback& callback) { | 484 const net::CompletionCallback& callback) { |
485 *backend = new MockDiskCache(); | 485 backend->reset(new MockDiskCache()); |
486 return net::OK; | 486 return net::OK; |
487 } | 487 } |
488 | 488 |
489 //----------------------------------------------------------------------------- | 489 //----------------------------------------------------------------------------- |
490 | 490 |
491 MockHttpCache::MockHttpCache() | 491 MockHttpCache::MockHttpCache() |
492 : http_cache_(new MockNetworkLayer(), NULL, new MockBackendFactory()) { | 492 : http_cache_(new MockNetworkLayer(), NULL, new MockBackendFactory()) { |
493 } | 493 } |
494 | 494 |
495 MockHttpCache::MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory) | 495 MockHttpCache::MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 | 569 |
570 int MockDiskCacheNoCB::CreateEntry(const std::string& key, | 570 int MockDiskCacheNoCB::CreateEntry(const std::string& key, |
571 disk_cache::Entry** entry, | 571 disk_cache::Entry** entry, |
572 const net::CompletionCallback& callback) { | 572 const net::CompletionCallback& callback) { |
573 return net::ERR_IO_PENDING; | 573 return net::ERR_IO_PENDING; |
574 } | 574 } |
575 | 575 |
576 //----------------------------------------------------------------------------- | 576 //----------------------------------------------------------------------------- |
577 | 577 |
578 int MockBackendNoCbFactory::CreateBackend( | 578 int MockBackendNoCbFactory::CreateBackend( |
579 net::NetLog* net_log, disk_cache::Backend** backend, | 579 net::NetLog* net_log, scoped_ptr<disk_cache::Backend>* backend, |
580 const net::CompletionCallback& callback) { | 580 const net::CompletionCallback& callback) { |
581 *backend = new MockDiskCacheNoCB(); | 581 backend->reset(new MockDiskCacheNoCB()); |
582 return net::OK; | 582 return net::OK; |
583 } | 583 } |
584 | 584 |
585 //----------------------------------------------------------------------------- | 585 //----------------------------------------------------------------------------- |
586 | 586 |
587 MockBlockingBackendFactory::MockBlockingBackendFactory() | 587 MockBlockingBackendFactory::MockBlockingBackendFactory() |
588 : backend_(NULL), | 588 : backend_(NULL), |
589 block_(true), | 589 block_(true), |
590 fail_(false) { | 590 fail_(false) { |
591 } | 591 } |
592 | 592 |
593 MockBlockingBackendFactory::~MockBlockingBackendFactory() { | 593 MockBlockingBackendFactory::~MockBlockingBackendFactory() { |
594 } | 594 } |
595 | 595 |
596 int MockBlockingBackendFactory::CreateBackend( | 596 int MockBlockingBackendFactory::CreateBackend( |
597 net::NetLog* net_log, disk_cache::Backend** backend, | 597 net::NetLog* net_log, scoped_ptr<disk_cache::Backend>* backend, |
598 const net::CompletionCallback& callback) { | 598 const net::CompletionCallback& callback) { |
599 if (!block_) { | 599 if (!block_) { |
600 if (!fail_) | 600 if (!fail_) |
601 *backend = new MockDiskCache(); | 601 backend->reset(new MockDiskCache()); |
602 return Result(); | 602 return Result(); |
603 } | 603 } |
604 | 604 |
605 backend_ = backend; | 605 backend_ = backend; |
606 callback_ = callback; | 606 callback_ = callback; |
607 return net::ERR_IO_PENDING; | 607 return net::ERR_IO_PENDING; |
608 } | 608 } |
609 | 609 |
610 void MockBlockingBackendFactory::FinishCreation() { | 610 void MockBlockingBackendFactory::FinishCreation() { |
611 block_ = false; | 611 block_ = false; |
612 if (!callback_.is_null()) { | 612 if (!callback_.is_null()) { |
613 if (!fail_) | 613 if (!fail_) |
614 *backend_ = new MockDiskCache(); | 614 backend_->reset(new MockDiskCache()); |
615 net::CompletionCallback cb = callback_; | 615 net::CompletionCallback cb = callback_; |
616 callback_.Reset(); | 616 callback_.Reset(); |
617 cb.Run(Result()); // This object can be deleted here. | 617 cb.Run(Result()); // This object can be deleted here. |
618 } | 618 } |
619 } | 619 } |
OLD | NEW |