| 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 e645329f7f99c112a3430f7286f279b8caa6b3ff..39178afc9e77cbe2fa92498c13c6df7cd6292a8b 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();
|
| }
|
|
|
| +
|
| +
|
| +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);
|
| + }
|
| +
|
| +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() {}
|
|
|