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..0bc93a76de919d4c3d038af73b63a0182ca35966 100644 |
| --- a/net/url_request/test_url_fetcher_factory.cc |
| +++ b/net/url_request/test_url_fetcher_factory.cc |
| @@ -279,60 +279,35 @@ 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(); |
| - } |
| - |
| - private: |
| - virtual ~FakeURLFetcher() { |
| - } |
| - |
| - // This is the method which actually calls the delegate that is passed in the |
| - // constructor. |
| - void RunDelegate() { |
| - delegate()->OnURLFetchComplete(this); |
| - } |
| - |
| - base::WeakPtrFactory<FakeURLFetcher> weak_factory_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher); |
| -}; |
| - |
| FakeURLFetcherFactory::FakeURLFetcherFactory() |
| : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| + creator_(base::Bind(&DefaultFakeURLFetcherCreator)), |
| default_factory_(NULL) { |
| } |
| FakeURLFetcherFactory::FakeURLFetcherFactory( |
| URLFetcherFactory* default_factory) |
| : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| + creator_(base::Bind(&DefaultFakeURLFetcherCreator)), |
| + default_factory_(default_factory) { |
| +} |
| + |
| +FakeURLFetcherFactory::FakeURLFetcherFactory( |
| + const FakeURLFetcherCreator& creator, |
| + URLFetcherFactory* default_factory) |
| + : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| + creator_(creator), |
| default_factory_(default_factory) { |
| } |
| +FakeURLFetcher* FakeURLFetcherFactory::DefaultFakeURLFetcherCreator( |
| + const GURL& url, |
| + URLFetcherDelegate* delegate, |
| + const std::string& response, |
| + bool success) { |
| + return new FakeURLFetcher(url, delegate, response, success); |
| +} |
| + |
| FakeURLFetcherFactory::~FakeURLFetcherFactory() {} |
| URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( |
| @@ -350,7 +325,7 @@ URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( |
| return default_factory_->CreateURLFetcher(id, url, request_type, d); |
| } |
| } |
| - return new FakeURLFetcher(url, d, it->second.first, it->second.second); |
| + return creator_.Run(url, d, it->second.first, it->second.second); |
| } |
| void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, |
| @@ -364,6 +339,37 @@ void FakeURLFetcherFactory::ClearFakeResponses() { |
| fake_responses_.clear(); |
| } |
| + |
|
akalin
2013/02/13 20:44:01
remove extra newline
Noam Samuel (WRONG ACCOUNT)
2013/02/13 21:37:46
Done.
|
| + |
| +FakeURLFetcher::FakeURLFetcher(const GURL& url, |
|
akalin
2013/02/13 20:44:01
move this above the FakeURLFetcherFactory methods
Noam Samuel (WRONG ACCOUNT)
2013/02/13 21:37:46
Done.
|
| + 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); |
| + } |
| + |
| +void FakeURLFetcher::Start() { |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&FakeURLFetcher::RunDelegate, weak_factory_.GetWeakPtr())); |
| +} |
| + |
| +FakeURLFetcher::~FakeURLFetcher() {} |
| + |
| +void FakeURLFetcher::RunDelegate() { |
| + delegate()->OnURLFetchComplete(this); |
| +} |
| + |
| + |
| +const GURL& FakeURLFetcher::GetURL() const { |
| + return TestURLFetcher::GetOriginalURL(); |
| +} |
| + |
| URLFetcherImplFactory::URLFetcherImplFactory() {} |
| URLFetcherImplFactory::~URLFetcherImplFactory() {} |