| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/net/url_request_failed_dns_job.h" | 5 #include "content/browser/net/url_request_failed_dns_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 9 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 #include "net/url_request/url_request.h" | 12 #include "net/url_request/url_request.h" |
| 12 #include "net/url_request/url_request_filter.h" | 13 #include "net/url_request/url_request_filter.h" |
| 13 | 14 |
| 14 const char URLRequestFailedDnsJob::kTestUrl[] = | 15 const char URLRequestFailedDnsJob::kTestUrl[] = |
| 15 "http://url.handled.by.fake.dns/"; | 16 "http://url.handled.by.fake.dns/"; |
| 16 | 17 |
| 17 URLRequestFailedDnsJob::URLRequestFailedDnsJob(net::URLRequest* request) | 18 URLRequestFailedDnsJob::URLRequestFailedDnsJob(net::URLRequest* request) |
| 18 : net::URLRequestJob(request), | 19 : net::URLRequestJob(request), |
| 19 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} | 20 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} |
| 20 | 21 |
| 21 URLRequestFailedDnsJob::~URLRequestFailedDnsJob() {} | 22 URLRequestFailedDnsJob::~URLRequestFailedDnsJob() {} |
| 22 | 23 |
| 23 void URLRequestFailedDnsJob::Start() { | 24 void URLRequestFailedDnsJob::Start() { |
| 24 MessageLoop::current()->PostTask( | 25 MessageLoop::current()->PostTask( |
| 25 FROM_HERE, | 26 FROM_HERE, |
| 26 method_factory_.NewRunnableMethod( | 27 base::Bind(&URLRequestFailedDnsJob::StartAsync, |
| 27 &URLRequestFailedDnsJob::StartAsync)); | 28 weak_factory_.GetWeakPtr())); |
| 28 } | 29 } |
| 29 | 30 |
| 30 // static | 31 // static |
| 31 void URLRequestFailedDnsJob::AddUrlHandler() { | 32 void URLRequestFailedDnsJob::AddUrlHandler() { |
| 32 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 33 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
| 33 filter->AddUrlHandler(GURL(kTestUrl), | 34 filter->AddUrlHandler(GURL(kTestUrl), |
| 34 &URLRequestFailedDnsJob::Factory); | 35 &URLRequestFailedDnsJob::Factory); |
| 35 } | 36 } |
| 36 | 37 |
| 37 /*static */ | 38 /*static */ |
| 38 net::URLRequestJob* URLRequestFailedDnsJob::Factory(net::URLRequest* request, | 39 net::URLRequestJob* URLRequestFailedDnsJob::Factory(net::URLRequest* request, |
| 39 const std::string& scheme) { | 40 const std::string& scheme) { |
| 40 return new URLRequestFailedDnsJob(request); | 41 return new URLRequestFailedDnsJob(request); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void URLRequestFailedDnsJob::StartAsync() { | 44 void URLRequestFailedDnsJob::StartAsync() { |
| 44 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 45 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 45 net::ERR_NAME_NOT_RESOLVED)); | 46 net::ERR_NAME_NOT_RESOLVED)); |
| 46 } | 47 } |
| OLD | NEW |