Chromium Code Reviews| Index: net/url_request/test_url_fetcher_factory.cc |
| diff --git a/net/url_request/test_url_fetcher_factory.cc b/net/url_request/test_url_fetcher_factory.cc |
| index 44f7d9379a9ea6de72fd4d00120e79833af5747a..e133e1d031850777488b93c9aa7084aa962e3980 100644 |
| --- a/net/url_request/test_url_fetcher_factory.cc |
| +++ b/net/url_request/test_url_fetcher_factory.cc |
| @@ -279,60 +279,59 @@ void TestURLFetcherFactory::SetDelegateForTests( |
| delegate_for_tests_ = delegate_for_tests; |
| } |
| -// This class is used by the FakeURLFetcherFactory below. |
| -class FakeURLFetcher : public TestURLFetcher { |
| - public: |
| - // Normal URL fetcher constructor but also takes in a pre-baked response. |
| - FakeURLFetcher(const GURL& url, |
| - URLFetcherDelegate* d, |
| - const std::string& response_data, bool success) |
| - : TestURLFetcher(0, url, d), |
| - ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| - set_status(URLRequestStatus( |
| - success ? URLRequestStatus::SUCCESS : URLRequestStatus::FAILED, |
| - 0)); |
| - set_response_code(success ? 200 : 500); |
| - SetResponseString(response_data); |
| - } |
| - |
| - // Start the request. This will call the given delegate asynchronously |
| - // with the pre-baked response as parameter. |
| - virtual void Start() OVERRIDE { |
| - MessageLoop::current()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&FakeURLFetcher::RunDelegate, weak_factory_.GetWeakPtr())); |
| - } |
| - |
| - virtual const GURL& GetURL() const OVERRIDE { |
| - return TestURLFetcher::GetOriginalURL(); |
| - } |
| +FakeURLFetcher::FakeURLFetcher(const GURL& url, |
| + URLFetcherDelegate* d, |
| + const std::string& response_data, |
| + bool success) |
| + : TestURLFetcher(0, url, d), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| + set_status(URLRequestStatus( |
| + success ? URLRequestStatus::SUCCESS : URLRequestStatus::FAILED, |
| + 0)); |
| + set_response_code(success ? 200 : 500); |
| + SetResponseString(response_data); |
| +} |
| - private: |
| - virtual ~FakeURLFetcher() { |
| - } |
| +FakeURLFetcher::~FakeURLFetcher() {} |
| - // This is the method which actually calls the delegate that is passed in the |
| - // constructor. |
| - void RunDelegate() { |
| - delegate()->OnURLFetchComplete(this); |
| - } |
| +void FakeURLFetcher::Start() { |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&FakeURLFetcher::RunDelegate, weak_factory_.GetWeakPtr())); |
| +} |
| - base::WeakPtrFactory<FakeURLFetcher> weak_factory_; |
| +void FakeURLFetcher::RunDelegate() { |
| + delegate()->OnURLFetchComplete(this); |
| +} |
| - DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher); |
| -}; |
| +const GURL& FakeURLFetcher::GetURL() const { |
| + return TestURLFetcher::GetOriginalURL(); |
| +} |
| -FakeURLFetcherFactory::FakeURLFetcherFactory() |
| +FakeURLFetcherFactory::FakeURLFetcherFactory( |
| + URLFetcherFactory* default_factory) |
| : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| - default_factory_(NULL) { |
| + creator_(base::Bind(&DefaultFakeURLFetcherCreator)), |
| + default_factory_(default_factory) { |
| } |
| FakeURLFetcherFactory::FakeURLFetcherFactory( |
| - URLFetcherFactory* default_factory) |
| + URLFetcherFactory* default_factory, |
| + const FakeURLFetcherCreator& creator) |
| : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| + creator_(creator), |
| default_factory_(default_factory) { |
| } |
| +scoped_ptr<FakeURLFetcher> FakeURLFetcherFactory::DefaultFakeURLFetcherCreator( |
| + const GURL& url, |
| + URLFetcherDelegate* delegate, |
| + const std::string& response, |
| + bool success) { |
| + return scoped_ptr<FakeURLFetcher> (new FakeURLFetcher(url, delegate, |
|
akalin
2013/02/14 14:52:06
no space after >
make sure to fix indent on next
Noam Samuel (WRONG ACCOUNT)
2013/02/14 18:08:11
Done.
|
| + response, success)); |
| +} |
| + |
| FakeURLFetcherFactory::~FakeURLFetcherFactory() {} |
| URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( |
| @@ -350,7 +349,10 @@ URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( |
| return default_factory_->CreateURLFetcher(id, url, request_type, d); |
| } |
| } |
| - return new FakeURLFetcher(url, d, it->second.first, it->second.second); |
| + |
| + scoped_ptr<FakeURLFetcher> fake_fetcher = |
| + creator_.Run(url, d, it->second.first, it->second.second); |
| + return fake_fetcher.release(); |
|
akalin
2013/02/14 14:52:06
add TODO to make CreateURLFetcher return a scoped_
Noam Samuel (WRONG ACCOUNT)
2013/02/14 18:08:11
Done.
|
| } |
| void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, |