Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: content/test/test_url_fetcher_factory.cc

Issue 10392192: Remove content::URLFetcherDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cleanup Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/test/test_url_fetcher_factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/test/test_url_fetcher_factory.h" 5 #include "content/test/test_url_fetcher_factory.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "content/common/net/url_fetcher_impl.h" 13 #include "content/common/net/url_fetcher_impl.h"
14 #include "content/public/common/url_fetcher_delegate.h"
15 #include "net/base/host_port_pair.h" 14 #include "net/base/host_port_pair.h"
16 #include "net/http/http_response_headers.h" 15 #include "net/http/http_response_headers.h"
16 #include "net/url_request/url_fetcher_delegate.h"
17 #include "net/url_request/url_request_status.h" 17 #include "net/url_request/url_request_status.h"
18 18
19 ScopedURLFetcherFactory::ScopedURLFetcherFactory( 19 ScopedURLFetcherFactory::ScopedURLFetcherFactory(
20 content::URLFetcherFactory* factory) { 20 content::URLFetcherFactory* factory) {
21 DCHECK(!URLFetcherImpl::factory()); 21 DCHECK(!URLFetcherImpl::factory());
22 URLFetcherImpl::set_factory(factory); 22 URLFetcherImpl::set_factory(factory);
23 } 23 }
24 24
25 ScopedURLFetcherFactory::~ScopedURLFetcherFactory() { 25 ScopedURLFetcherFactory::~ScopedURLFetcherFactory() {
26 DCHECK(URLFetcherImpl::factory()); 26 DCHECK(URLFetcherImpl::factory());
27 URLFetcherImpl::set_factory(NULL); 27 URLFetcherImpl::set_factory(NULL);
28 } 28 }
29 29
30 TestURLFetcher::TestURLFetcher(int id, 30 TestURLFetcher::TestURLFetcher(int id,
31 const GURL& url, 31 const GURL& url,
32 content::URLFetcherDelegate* d) 32 net::URLFetcherDelegate* d)
33 : id_(id), 33 : id_(id),
34 original_url_(url), 34 original_url_(url),
35 delegate_(d), 35 delegate_(d),
36 did_receive_last_chunk_(false), 36 did_receive_last_chunk_(false),
37 fake_load_flags_(0), 37 fake_load_flags_(0),
38 fake_response_code_(-1), 38 fake_response_code_(-1),
39 fake_response_destination_(STRING), 39 fake_response_destination_(STRING),
40 fake_was_fetched_via_proxy_(false), 40 fake_was_fetched_via_proxy_(false),
41 fake_max_retries_(0) { 41 fake_max_retries_(0) {
42 } 42 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 TestURLFetcherFactory::TestURLFetcherFactory() 216 TestURLFetcherFactory::TestURLFetcherFactory()
217 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 217 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
218 } 218 }
219 219
220 TestURLFetcherFactory::~TestURLFetcherFactory() {} 220 TestURLFetcherFactory::~TestURLFetcherFactory() {}
221 221
222 content::URLFetcher* TestURLFetcherFactory::CreateURLFetcher( 222 content::URLFetcher* TestURLFetcherFactory::CreateURLFetcher(
223 int id, 223 int id,
224 const GURL& url, 224 const GURL& url,
225 content::URLFetcher::RequestType request_type, 225 content::URLFetcher::RequestType request_type,
226 content::URLFetcherDelegate* d) { 226 net::URLFetcherDelegate* d) {
227 TestURLFetcher* fetcher = new TestURLFetcher(id, url, d); 227 TestURLFetcher* fetcher = new TestURLFetcher(id, url, d);
228 fetchers_[id] = fetcher; 228 fetchers_[id] = fetcher;
229 return fetcher; 229 return fetcher;
230 } 230 }
231 231
232 TestURLFetcher* TestURLFetcherFactory::GetFetcherByID(int id) const { 232 TestURLFetcher* TestURLFetcherFactory::GetFetcherByID(int id) const {
233 Fetchers::const_iterator i = fetchers_.find(id); 233 Fetchers::const_iterator i = fetchers_.find(id);
234 return i == fetchers_.end() ? NULL : i->second; 234 return i == fetchers_.end() ? NULL : i->second;
235 } 235 }
236 236
237 void TestURLFetcherFactory::RemoveFetcherFromMap(int id) { 237 void TestURLFetcherFactory::RemoveFetcherFromMap(int id) {
238 Fetchers::iterator i = fetchers_.find(id); 238 Fetchers::iterator i = fetchers_.find(id);
239 DCHECK(i != fetchers_.end()); 239 DCHECK(i != fetchers_.end());
240 fetchers_.erase(i); 240 fetchers_.erase(i);
241 } 241 }
242 242
243 // This class is used by the FakeURLFetcherFactory below. 243 // This class is used by the FakeURLFetcherFactory below.
244 class FakeURLFetcher : public TestURLFetcher { 244 class FakeURLFetcher : public TestURLFetcher {
245 public: 245 public:
246 // Normal URL fetcher constructor but also takes in a pre-baked response. 246 // Normal URL fetcher constructor but also takes in a pre-baked response.
247 FakeURLFetcher(const GURL& url, 247 FakeURLFetcher(const GURL& url,
248 content::URLFetcherDelegate* d, 248 net::URLFetcherDelegate* d,
249 const std::string& response_data, bool success) 249 const std::string& response_data, bool success)
250 : TestURLFetcher(0, url, d), 250 : TestURLFetcher(0, url, d),
251 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 251 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
252 set_status(net::URLRequestStatus( 252 set_status(net::URLRequestStatus(
253 success ? net::URLRequestStatus::SUCCESS : 253 success ? net::URLRequestStatus::SUCCESS :
254 net::URLRequestStatus::FAILED, 254 net::URLRequestStatus::FAILED,
255 0)); 255 0));
256 set_response_code(success ? 200 : 500); 256 set_response_code(success ? 200 : 500);
257 SetResponseString(response_data); 257 SetResponseString(response_data);
258 } 258 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 294 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
295 default_factory_(default_factory) { 295 default_factory_(default_factory) {
296 } 296 }
297 297
298 FakeURLFetcherFactory::~FakeURLFetcherFactory() {} 298 FakeURLFetcherFactory::~FakeURLFetcherFactory() {}
299 299
300 content::URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( 300 content::URLFetcher* FakeURLFetcherFactory::CreateURLFetcher(
301 int id, 301 int id,
302 const GURL& url, 302 const GURL& url,
303 content::URLFetcher::RequestType request_type, 303 content::URLFetcher::RequestType request_type,
304 content::URLFetcherDelegate* d) { 304 net::URLFetcherDelegate* d) {
305 FakeResponseMap::const_iterator it = fake_responses_.find(url); 305 FakeResponseMap::const_iterator it = fake_responses_.find(url);
306 if (it == fake_responses_.end()) { 306 if (it == fake_responses_.end()) {
307 if (default_factory_ == NULL) { 307 if (default_factory_ == NULL) {
308 // If we don't have a baked response for that URL we return NULL. 308 // If we don't have a baked response for that URL we return NULL.
309 DLOG(ERROR) << "No baked response for URL: " << url.spec(); 309 DLOG(ERROR) << "No baked response for URL: " << url.spec();
310 return NULL; 310 return NULL;
311 } else { 311 } else {
312 return default_factory_->CreateURLFetcher(id, url, request_type, d); 312 return default_factory_->CreateURLFetcher(id, url, request_type, d);
313 } 313 }
314 } 314 }
(...skipping 12 matching lines...) Expand all
327 } 327 }
328 328
329 URLFetcherImplFactory::URLFetcherImplFactory() {} 329 URLFetcherImplFactory::URLFetcherImplFactory() {}
330 330
331 URLFetcherImplFactory::~URLFetcherImplFactory() {} 331 URLFetcherImplFactory::~URLFetcherImplFactory() {}
332 332
333 content::URLFetcher* URLFetcherImplFactory::CreateURLFetcher( 333 content::URLFetcher* URLFetcherImplFactory::CreateURLFetcher(
334 int id, 334 int id,
335 const GURL& url, 335 const GURL& url,
336 content::URLFetcher::RequestType request_type, 336 content::URLFetcher::RequestType request_type,
337 content::URLFetcherDelegate* d) { 337 net::URLFetcherDelegate* d) {
338 return new URLFetcherImpl(url, request_type, d); 338 return new URLFetcherImpl(url, request_type, d);
339 } 339 }
OLDNEW
« no previous file with comments | « content/test/test_url_fetcher_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698