| 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/test/url_request/url_request_failed_job.h" | 5 #include "net/test/url_request/url_request_failed_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 } // namespace | 78 } // namespace |
| 79 | 79 |
| 80 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, | 80 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, |
| 81 NetworkDelegate* network_delegate, | 81 NetworkDelegate* network_delegate, |
| 82 FailurePhase phase, | 82 FailurePhase phase, |
| 83 int net_error) | 83 int net_error) |
| 84 : URLRequestJob(request, network_delegate), | 84 : URLRequestJob(request, network_delegate), |
| 85 phase_(phase), | 85 phase_(phase), |
| 86 net_error_(net_error), | 86 net_error_(net_error), |
| 87 total_received_bytes_(0), | |
| 88 weak_factory_(this) { | 87 weak_factory_(this) { |
| 89 CHECK_GE(phase, URLRequestFailedJob::FailurePhase::START); | 88 CHECK_GE(phase, URLRequestFailedJob::FailurePhase::START); |
| 90 CHECK_LE(phase, URLRequestFailedJob::FailurePhase::READ_ASYNC); | 89 CHECK_LE(phase, URLRequestFailedJob::FailurePhase::READ_ASYNC); |
| 91 CHECK_LT(net_error, OK); | 90 CHECK_LT(net_error, OK); |
| 92 } | 91 } |
| 93 | 92 |
| 94 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, | 93 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, |
| 95 NetworkDelegate* network_delegate, | 94 NetworkDelegate* network_delegate, |
| 96 int net_error) | 95 int net_error) |
| 97 : URLRequestFailedJob(request, network_delegate, START, net_error) { | 96 : URLRequestFailedJob(request, network_delegate, START, net_error) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 125 *info = response_info_; | 124 *info = response_info_; |
| 126 } | 125 } |
| 127 | 126 |
| 128 void URLRequestFailedJob::PopulateNetErrorDetails( | 127 void URLRequestFailedJob::PopulateNetErrorDetails( |
| 129 NetErrorDetails* details) const { | 128 NetErrorDetails* details) const { |
| 130 if (net_error_ == ERR_QUIC_PROTOCOL_ERROR) { | 129 if (net_error_ == ERR_QUIC_PROTOCOL_ERROR) { |
| 131 details->quic_connection_error = QUIC_INTERNAL_ERROR; | 130 details->quic_connection_error = QUIC_INTERNAL_ERROR; |
| 132 } | 131 } |
| 133 } | 132 } |
| 134 | 133 |
| 135 int64_t URLRequestFailedJob::GetTotalReceivedBytes() const { | |
| 136 return total_received_bytes_; | |
| 137 } | |
| 138 | |
| 139 // static | 134 // static |
| 140 void URLRequestFailedJob::AddUrlHandler() { | 135 void URLRequestFailedJob::AddUrlHandler() { |
| 141 return AddUrlHandlerForHostname(kMockHostname); | 136 return AddUrlHandlerForHostname(kMockHostname); |
| 142 } | 137 } |
| 143 | 138 |
| 144 // static | 139 // static |
| 145 void URLRequestFailedJob::AddUrlHandlerForHostname( | 140 void URLRequestFailedJob::AddUrlHandlerForHostname( |
| 146 const std::string& hostname) { | 141 const std::string& hostname) { |
| 147 URLRequestFilter* filter = URLRequestFilter::GetInstance(); | 142 URLRequestFilter* filter = URLRequestFilter::GetInstance(); |
| 148 // Add |hostname| to URLRequestFilter for HTTP and HTTPS. | 143 // Add |hostname| to URLRequestFilter for HTTP and HTTPS. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 183 } |
| 189 | 184 |
| 190 void URLRequestFailedJob::StartAsync() { | 185 void URLRequestFailedJob::StartAsync() { |
| 191 if (phase_ == START) { | 186 if (phase_ == START) { |
| 192 if (net_error_ != ERR_IO_PENDING) { | 187 if (net_error_ != ERR_IO_PENDING) { |
| 193 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); | 188 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); |
| 194 return; | 189 return; |
| 195 } | 190 } |
| 196 return; | 191 return; |
| 197 } | 192 } |
| 198 const std::string headers = "HTTP/1.1 200 OK"; | 193 response_info_.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); |
| 199 response_info_.headers = new net::HttpResponseHeaders(headers); | |
| 200 total_received_bytes_ = headers.size(); | |
| 201 NotifyHeadersComplete(); | 194 NotifyHeadersComplete(); |
| 202 } | 195 } |
| 203 | 196 |
| 204 } // namespace net | 197 } // namespace net |
| OLD | NEW |