| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 CHECK_LT(net_error, OK); | 90 CHECK_LT(net_error, OK); |
| 91 } | 91 } |
| 92 | 92 |
| 93 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, | 93 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, |
| 94 NetworkDelegate* network_delegate, | 94 NetworkDelegate* network_delegate, |
| 95 int net_error) | 95 int net_error) |
| 96 : URLRequestFailedJob(request, network_delegate, START, net_error) { | 96 : URLRequestFailedJob(request, network_delegate, START, net_error) { |
| 97 } | 97 } |
| 98 | 98 |
| 99 void URLRequestFailedJob::Start() { | 99 void URLRequestFailedJob::Start() { |
| 100 if (phase_ == START) { |
| 101 if (net_error_ != ERR_IO_PENDING) { |
| 102 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); |
| 103 return; |
| 104 } |
| 105 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 106 return; |
| 107 } |
| 108 response_info_.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); |
| 109 NotifyHeadersComplete(); |
| 110 } |
| 111 |
| 112 bool URLRequestFailedJob::ReadRawData(IOBuffer* buf, |
| 113 int buf_size, |
| 114 int* bytes_read) { |
| 115 CHECK(phase_ == READ_SYNC || phase_ == READ_ASYNC); |
| 116 if (net_error_ != ERR_IO_PENDING && phase_ == READ_SYNC) { |
| 117 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); |
| 118 return false; |
| 119 } |
| 120 |
| 121 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 122 |
| 123 if (net_error_ == ERR_IO_PENDING) |
| 124 return false; |
| 125 |
| 126 DCHECK_EQ(READ_ASYNC, phase_); |
| 127 DCHECK_NE(ERR_IO_PENDING, net_error_); |
| 128 |
| 100 base::ThreadTaskRunnerHandle::Get()->PostTask( | 129 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 101 FROM_HERE, | 130 FROM_HERE, |
| 102 base::Bind(&URLRequestFailedJob::StartAsync, weak_factory_.GetWeakPtr())); | 131 base::Bind(&URLRequestFailedJob::NotifyDone, weak_factory_.GetWeakPtr(), |
| 103 } | 132 URLRequestStatus(URLRequestStatus::FAILED, net_error_))); |
| 104 | 133 return false; |
| 105 int URLRequestFailedJob::ReadRawData(IOBuffer* buf, int buf_size) { | |
| 106 CHECK(phase_ == READ_SYNC || phase_ == READ_ASYNC); | |
| 107 if (net_error_ == ERR_IO_PENDING || phase_ == READ_SYNC) | |
| 108 return net_error_; | |
| 109 | |
| 110 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 111 FROM_HERE, base::Bind(&URLRequestFailedJob::ReadRawDataComplete, | |
| 112 weak_factory_.GetWeakPtr(), net_error_)); | |
| 113 return ERR_IO_PENDING; | |
| 114 } | 134 } |
| 115 | 135 |
| 116 int URLRequestFailedJob::GetResponseCode() const { | 136 int URLRequestFailedJob::GetResponseCode() const { |
| 117 // If we have headers, get the response code from them. | 137 // If we have headers, get the response code from them. |
| 118 if (response_info_.headers) | 138 if (response_info_.headers) |
| 119 return response_info_.headers->response_code(); | 139 return response_info_.headers->response_code(); |
| 120 return URLRequestJob::GetResponseCode(); | 140 return URLRequestJob::GetResponseCode(); |
| 121 } | 141 } |
| 122 | 142 |
| 123 void URLRequestFailedJob::GetResponseInfo(HttpResponseInfo* info) { | 143 void URLRequestFailedJob::GetResponseInfo(HttpResponseInfo* info) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // static | 188 // static |
| 169 GURL URLRequestFailedJob::GetMockHttpsUrlForHostname( | 189 GURL URLRequestFailedJob::GetMockHttpsUrlForHostname( |
| 170 int net_error, | 190 int net_error, |
| 171 const std::string& hostname) { | 191 const std::string& hostname) { |
| 172 return GetMockUrl("https", hostname, START, net_error); | 192 return GetMockUrl("https", hostname, START, net_error); |
| 173 } | 193 } |
| 174 | 194 |
| 175 URLRequestFailedJob::~URLRequestFailedJob() { | 195 URLRequestFailedJob::~URLRequestFailedJob() { |
| 176 } | 196 } |
| 177 | 197 |
| 178 void URLRequestFailedJob::StartAsync() { | |
| 179 if (phase_ == START) { | |
| 180 if (net_error_ != ERR_IO_PENDING) { | |
| 181 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); | |
| 182 return; | |
| 183 } | |
| 184 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | |
| 185 return; | |
| 186 } | |
| 187 response_info_.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); | |
| 188 NotifyHeadersComplete(); | |
| 189 } | |
| 190 | |
| 191 } // namespace net | 198 } // namespace net |
| OLD | NEW |