| 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/url_request/test_url_fetcher_factory.h" | 5 #include "net/url_request/test_url_fetcher_factory.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 delegate_for_tests_(NULL), | 326 delegate_for_tests_(NULL), |
| 327 remove_fetcher_on_delete_(false) { | 327 remove_fetcher_on_delete_(false) { |
| 328 } | 328 } |
| 329 | 329 |
| 330 TestURLFetcherFactory::~TestURLFetcherFactory() {} | 330 TestURLFetcherFactory::~TestURLFetcherFactory() {} |
| 331 | 331 |
| 332 std::unique_ptr<URLFetcher> TestURLFetcherFactory::CreateURLFetcher( | 332 std::unique_ptr<URLFetcher> TestURLFetcherFactory::CreateURLFetcher( |
| 333 int id, | 333 int id, |
| 334 const GURL& url, | 334 const GURL& url, |
| 335 URLFetcher::RequestType request_type, | 335 URLFetcher::RequestType request_type, |
| 336 URLFetcherDelegate* d) { | 336 URLFetcherDelegate* d, |
| 337 NetworkTrafficAnnotationTag traffic_annotation) { |
| 337 TestURLFetcher* fetcher = new TestURLFetcher(id, url, d); | 338 TestURLFetcher* fetcher = new TestURLFetcher(id, url, d); |
| 338 if (remove_fetcher_on_delete_) | 339 if (remove_fetcher_on_delete_) |
| 339 fetcher->set_owner(this); | 340 fetcher->set_owner(this); |
| 340 fetcher->SetDelegateForTests(delegate_for_tests_); | 341 fetcher->SetDelegateForTests(delegate_for_tests_); |
| 341 fetchers_[id] = fetcher; | 342 fetchers_[id] = fetcher; |
| 342 return std::unique_ptr<URLFetcher>(fetcher); | 343 return std::unique_ptr<URLFetcher>(fetcher); |
| 343 } | 344 } |
| 344 | 345 |
| 345 TestURLFetcher* TestURLFetcherFactory::GetFetcherByID(int id) const { | 346 TestURLFetcher* TestURLFetcherFactory::GetFetcherByID(int id) const { |
| 346 Fetchers::const_iterator i = fetchers_.find(id); | 347 Fetchers::const_iterator i = fetchers_.find(id); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 return std::unique_ptr<FakeURLFetcher>( | 436 return std::unique_ptr<FakeURLFetcher>( |
| 436 new FakeURLFetcher(url, delegate, response_data, response_code, status)); | 437 new FakeURLFetcher(url, delegate, response_data, response_code, status)); |
| 437 } | 438 } |
| 438 | 439 |
| 439 FakeURLFetcherFactory::~FakeURLFetcherFactory() {} | 440 FakeURLFetcherFactory::~FakeURLFetcherFactory() {} |
| 440 | 441 |
| 441 std::unique_ptr<URLFetcher> FakeURLFetcherFactory::CreateURLFetcher( | 442 std::unique_ptr<URLFetcher> FakeURLFetcherFactory::CreateURLFetcher( |
| 442 int id, | 443 int id, |
| 443 const GURL& url, | 444 const GURL& url, |
| 444 URLFetcher::RequestType request_type, | 445 URLFetcher::RequestType request_type, |
| 445 URLFetcherDelegate* d) { | 446 URLFetcherDelegate* d, |
| 447 NetworkTrafficAnnotationTag traffic_annotation) { |
| 446 FakeResponseMap::const_iterator it = fake_responses_.find(url); | 448 FakeResponseMap::const_iterator it = fake_responses_.find(url); |
| 447 if (it == fake_responses_.end()) { | 449 if (it == fake_responses_.end()) { |
| 448 if (default_factory_ == NULL) { | 450 if (default_factory_ == NULL) { |
| 449 // If we don't have a baked response for that URL we return NULL. | 451 // If we don't have a baked response for that URL we return NULL. |
| 450 DLOG(ERROR) << "No baked response for URL: " << url.spec(); | 452 DLOG(ERROR) << "No baked response for URL: " << url.spec(); |
| 451 return NULL; | 453 return NULL; |
| 452 } else { | 454 } else { |
| 453 return default_factory_->CreateURLFetcher(id, url, request_type, d); | 455 return default_factory_->CreateURLFetcher(id, url, request_type, d, |
| 456 traffic_annotation); |
| 454 } | 457 } |
| 455 } | 458 } |
| 456 | 459 |
| 457 std::unique_ptr<URLFetcher> fake_fetcher = | 460 std::unique_ptr<URLFetcher> fake_fetcher = |
| 458 creator_.Run(url, d, it->second.response_data, it->second.response_code, | 461 creator_.Run(url, d, it->second.response_data, it->second.response_code, |
| 459 it->second.status); | 462 it->second.status); |
| 460 return fake_fetcher; | 463 return fake_fetcher; |
| 461 } | 464 } |
| 462 | 465 |
| 463 void FakeURLFetcherFactory::SetFakeResponse( | 466 void FakeURLFetcherFactory::SetFakeResponse( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 478 } | 481 } |
| 479 | 482 |
| 480 URLFetcherImplFactory::URLFetcherImplFactory() {} | 483 URLFetcherImplFactory::URLFetcherImplFactory() {} |
| 481 | 484 |
| 482 URLFetcherImplFactory::~URLFetcherImplFactory() {} | 485 URLFetcherImplFactory::~URLFetcherImplFactory() {} |
| 483 | 486 |
| 484 std::unique_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher( | 487 std::unique_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher( |
| 485 int id, | 488 int id, |
| 486 const GURL& url, | 489 const GURL& url, |
| 487 URLFetcher::RequestType request_type, | 490 URLFetcher::RequestType request_type, |
| 488 URLFetcherDelegate* d) { | 491 URLFetcherDelegate* d, |
| 492 NetworkTrafficAnnotationTag traffic_annotation) { |
| 489 return std::unique_ptr<URLFetcher>( | 493 return std::unique_ptr<URLFetcher>( |
| 490 new URLFetcherImpl(url, request_type, d, TRAFFIC_ANNOTATION_FOR_TESTS)); | 494 new URLFetcherImpl(url, request_type, d, traffic_annotation)); |
| 491 } | 495 } |
| 492 | 496 |
| 493 } // namespace net | 497 } // namespace net |
| OLD | NEW |