| 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 // This class simulates what wininet does when a dns lookup fails. | 4 // This class simulates what wininet does when a dns lookup fails. |
| 5 | 5 |
| 6 #include <algorithm> | 6 #include <algorithm> |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/test/net/url_request_abort_on_end_job.h" | 12 #include "content/test/net/url_request_abort_on_end_job.h" |
| 13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
| 16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 17 #include "net/url_request/url_request_filter.h" | 17 #include "net/url_request/url_request_filter.h" |
| 18 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" |
| 19 | 19 |
| 20 namespace content { |
| 20 namespace { | 21 namespace { |
| 21 const char kPageContent[] = "some data\r\n"; | 22 const char kPageContent[] = "some data\r\n"; |
| 22 } | 23 } |
| 23 | 24 |
| 24 const char URLRequestAbortOnEndJob::k400AbortOnEndUrl[] = | 25 const char URLRequestAbortOnEndJob::k400AbortOnEndUrl[] = |
| 25 "http://url.handled.by.abort.on.end/400"; | 26 "http://url.handled.by.abort.on.end/400"; |
| 26 | 27 |
| 27 // static | 28 // static |
| 28 void URLRequestAbortOnEndJob::AddUrlHandler() { | 29 void URLRequestAbortOnEndJob::AddUrlHandler() { |
| 29 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 30 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
| 30 filter->AddUrlHandler(GURL(k400AbortOnEndUrl), | 31 filter->AddUrlHandler(GURL(k400AbortOnEndUrl), |
| 31 &URLRequestAbortOnEndJob::Factory); | 32 &URLRequestAbortOnEndJob::Factory); |
| 32 } | 33 } |
| 33 | 34 |
| 34 // static | 35 // static |
| 35 net::URLRequestJob* URLRequestAbortOnEndJob::Factory( | 36 net::URLRequestJob* URLRequestAbortOnEndJob::Factory( |
| 36 net::URLRequest* request, | 37 net::URLRequest* request, |
| 37 net::NetworkDelegate* network_delegate, | 38 net::NetworkDelegate* network_delegate, |
| 38 const std::string& scheme) { | 39 const std::string& scheme) { |
| 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 40 return new URLRequestAbortOnEndJob(request, network_delegate); | 41 return new URLRequestAbortOnEndJob(request, network_delegate); |
| 41 } | 42 } |
| 42 | 43 |
| 43 // Private const version. | 44 // Private const version. |
| 44 void URLRequestAbortOnEndJob::GetResponseInfoConst( | 45 void URLRequestAbortOnEndJob::GetResponseInfoConst( |
| 45 net::HttpResponseInfo* info) const { | 46 net::HttpResponseInfo* info) const { |
| 46 // Send back mock headers. | 47 // Send back mock headers. |
| 47 std::string raw_headers; | 48 std::string raw_headers; |
| 48 if (LowerCaseEqualsASCII(k400AbortOnEndUrl, | 49 if (LowerCaseEqualsASCII(k400AbortOnEndUrl, |
| 49 request_->url().spec().c_str())) { | 50 request_->url().spec().c_str())) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 sent_data_ = true; | 99 sent_data_ = true; |
| 99 return true; | 100 return true; |
| 100 } | 101 } |
| 101 | 102 |
| 102 SetStatus(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 103 SetStatus(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 103 net::ERR_CONNECTION_ABORTED)); | 104 net::ERR_CONNECTION_ABORTED)); |
| 104 *bytes_read = -1; | 105 *bytes_read = -1; |
| 105 return false; | 106 return false; |
| 106 } | 107 } |
| 107 | 108 |
| 108 | 109 } // namespace content |
| OLD | NEW |