| 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/url_request/url_request_ftp_job.h" | 5 #include "net/url_request/url_request_ftp_job.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "net/url_request/url_request_error_job.h" | 21 #include "net/url_request/url_request_error_job.h" |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 | 24 |
| 25 URLRequestFtpJob::URLRequestFtpJob( | 25 URLRequestFtpJob::URLRequestFtpJob( |
| 26 URLRequest* request, | 26 URLRequest* request, |
| 27 NetworkDelegate* network_delegate, | 27 NetworkDelegate* network_delegate, |
| 28 FtpTransactionFactory* ftp_transaction_factory, | 28 FtpTransactionFactory* ftp_transaction_factory, |
| 29 FtpAuthCache* ftp_auth_cache) | 29 FtpAuthCache* ftp_auth_cache) |
| 30 : URLRequestJob(request, network_delegate), | 30 : URLRequestJob(request, network_delegate), |
| 31 priority_(DEFAULT_PRIORITY), |
| 31 pac_request_(NULL), | 32 pac_request_(NULL), |
| 32 response_info_(NULL), | 33 response_info_(NULL), |
| 33 read_in_progress_(false), | 34 read_in_progress_(false), |
| 34 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 35 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 35 ftp_transaction_factory_(ftp_transaction_factory), | 36 ftp_transaction_factory_(ftp_transaction_factory), |
| 36 ftp_auth_cache_(ftp_auth_cache) { | 37 ftp_auth_cache_(ftp_auth_cache) { |
| 37 DCHECK(ftp_transaction_factory); | 38 DCHECK(ftp_transaction_factory); |
| 38 DCHECK(ftp_auth_cache); | 39 DCHECK(ftp_auth_cache); |
| 39 } | 40 } |
| 40 | 41 |
| 42 URLRequestFtpJob::~URLRequestFtpJob() { |
| 43 if (pac_request_) |
| 44 request_->context()->proxy_service()->CancelPacRequest(pac_request_); |
| 45 } |
| 46 |
| 41 // static | 47 // static |
| 42 URLRequestJob* URLRequestFtpJob::Factory(URLRequest* request, | 48 URLRequestJob* URLRequestFtpJob::Factory(URLRequest* request, |
| 43 NetworkDelegate* network_delegate, | 49 NetworkDelegate* network_delegate, |
| 44 const std::string& scheme) { | 50 const std::string& scheme) { |
| 45 DCHECK_EQ(scheme, "ftp"); | 51 DCHECK_EQ(scheme, "ftp"); |
| 46 | 52 |
| 47 int port = request->url().IntPort(); | 53 int port = request->url().IntPort(); |
| 48 if (request->url().has_port() && | 54 if (request->url().has_port() && |
| 49 !IsPortAllowedByFtp(port) && !IsPortAllowedByOverride(port)) { | 55 !IsPortAllowedByFtp(port) && !IsPortAllowedByOverride(port)) { |
| 50 return new URLRequestErrorJob(request, | 56 return new URLRequestErrorJob(request, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (!ftp_transaction_) | 94 if (!ftp_transaction_) |
| 89 return HostPortPair(); | 95 return HostPortPair(); |
| 90 return ftp_transaction_->GetResponseInfo()->socket_address; | 96 return ftp_transaction_->GetResponseInfo()->socket_address; |
| 91 } else { | 97 } else { |
| 92 if (!http_transaction_) | 98 if (!http_transaction_) |
| 93 return HostPortPair(); | 99 return HostPortPair(); |
| 94 return http_transaction_->GetResponseInfo()->socket_address; | 100 return http_transaction_->GetResponseInfo()->socket_address; |
| 95 } | 101 } |
| 96 } | 102 } |
| 97 | 103 |
| 98 URLRequestFtpJob::~URLRequestFtpJob() { | 104 void URLRequestFtpJob::SetPriority(RequestPriority priority) { |
| 99 if (pac_request_) | 105 priority_ = priority; |
| 100 request_->context()->proxy_service()->CancelPacRequest(pac_request_); | 106 if (http_transaction_) |
| 107 http_transaction_->SetPriority(priority); |
| 108 } |
| 109 |
| 110 void URLRequestFtpJob::Start() { |
| 111 DCHECK(!pac_request_); |
| 112 DCHECK(!ftp_transaction_); |
| 113 DCHECK(!http_transaction_); |
| 114 |
| 115 int rv = OK; |
| 116 if (request_->load_flags() & LOAD_BYPASS_PROXY) { |
| 117 proxy_info_.UseDirect(); |
| 118 } else { |
| 119 rv = request_->context()->proxy_service()->ResolveProxy( |
| 120 request_->url(), |
| 121 &proxy_info_, |
| 122 base::Bind(&URLRequestFtpJob::OnResolveProxyComplete, |
| 123 base::Unretained(this)), |
| 124 &pac_request_, |
| 125 request_->net_log()); |
| 126 |
| 127 if (rv == ERR_IO_PENDING) |
| 128 return; |
| 129 } |
| 130 OnResolveProxyComplete(rv); |
| 131 } |
| 132 |
| 133 void URLRequestFtpJob::Kill() { |
| 134 if (ftp_transaction_) |
| 135 ftp_transaction_.reset(); |
| 136 if (http_transaction_) |
| 137 http_transaction_.reset(); |
| 138 URLRequestJob::Kill(); |
| 139 weak_factory_.InvalidateWeakPtrs(); |
| 101 } | 140 } |
| 102 | 141 |
| 103 void URLRequestFtpJob::OnResolveProxyComplete(int result) { | 142 void URLRequestFtpJob::OnResolveProxyComplete(int result) { |
| 104 pac_request_ = NULL; | 143 pac_request_ = NULL; |
| 105 | 144 |
| 106 if (result != OK) { | 145 if (result != OK) { |
| 107 OnStartCompletedAsync(result); | 146 OnStartCompletedAsync(result); |
| 108 return; | 147 return; |
| 109 } | 148 } |
| 110 | 149 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 LOAD_DO_NOT_SAVE_COOKIES | | 200 LOAD_DO_NOT_SAVE_COOKIES | |
| 162 LOAD_DO_NOT_SEND_AUTH_DATA | | 201 LOAD_DO_NOT_SEND_AUTH_DATA | |
| 163 LOAD_DO_NOT_SEND_COOKIES); | 202 LOAD_DO_NOT_SEND_COOKIES); |
| 164 | 203 |
| 165 http_request_info_.url = request_->url(); | 204 http_request_info_.url = request_->url(); |
| 166 http_request_info_.method = request_->method(); | 205 http_request_info_.method = request_->method(); |
| 167 http_request_info_.load_flags = request_->load_flags(); | 206 http_request_info_.load_flags = request_->load_flags(); |
| 168 http_request_info_.request_id = request_->identifier(); | 207 http_request_info_.request_id = request_->identifier(); |
| 169 | 208 |
| 170 int rv = request_->context()->http_transaction_factory()->CreateTransaction( | 209 int rv = request_->context()->http_transaction_factory()->CreateTransaction( |
| 171 request_->priority(), &http_transaction_, NULL); | 210 priority_, &http_transaction_, NULL); |
| 172 if (rv == OK) { | 211 if (rv == OK) { |
| 173 rv = http_transaction_->Start( | 212 rv = http_transaction_->Start( |
| 174 &http_request_info_, | 213 &http_request_info_, |
| 175 base::Bind(&URLRequestFtpJob::OnStartCompleted, | 214 base::Bind(&URLRequestFtpJob::OnStartCompleted, |
| 176 base::Unretained(this)), | 215 base::Unretained(this)), |
| 177 request_->net_log()); | 216 request_->net_log()); |
| 178 if (rv == ERR_IO_PENDING) | 217 if (rv == ERR_IO_PENDING) |
| 179 return; | 218 return; |
| 180 } | 219 } |
| 181 // The transaction started synchronously, but we need to notify the | 220 // The transaction started synchronously, but we need to notify the |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 int rv = ftp_transaction_->RestartWithAuth( | 292 int rv = ftp_transaction_->RestartWithAuth( |
| 254 server_auth_->credentials, | 293 server_auth_->credentials, |
| 255 base::Bind(&URLRequestFtpJob::OnStartCompleted, | 294 base::Bind(&URLRequestFtpJob::OnStartCompleted, |
| 256 base::Unretained(this))); | 295 base::Unretained(this))); |
| 257 if (rv == ERR_IO_PENDING) | 296 if (rv == ERR_IO_PENDING) |
| 258 return; | 297 return; |
| 259 | 298 |
| 260 OnStartCompletedAsync(rv); | 299 OnStartCompletedAsync(rv); |
| 261 } | 300 } |
| 262 | 301 |
| 263 void URLRequestFtpJob::Start() { | |
| 264 DCHECK(!pac_request_); | |
| 265 DCHECK(!ftp_transaction_); | |
| 266 DCHECK(!http_transaction_); | |
| 267 | |
| 268 int rv = OK; | |
| 269 if (request_->load_flags() & LOAD_BYPASS_PROXY) { | |
| 270 proxy_info_.UseDirect(); | |
| 271 } else { | |
| 272 rv = request_->context()->proxy_service()->ResolveProxy( | |
| 273 request_->url(), | |
| 274 &proxy_info_, | |
| 275 base::Bind(&URLRequestFtpJob::OnResolveProxyComplete, | |
| 276 base::Unretained(this)), | |
| 277 &pac_request_, | |
| 278 request_->net_log()); | |
| 279 | |
| 280 if (rv == ERR_IO_PENDING) | |
| 281 return; | |
| 282 } | |
| 283 OnResolveProxyComplete(rv); | |
| 284 } | |
| 285 | |
| 286 void URLRequestFtpJob::Kill() { | |
| 287 if (ftp_transaction_) | |
| 288 ftp_transaction_.reset(); | |
| 289 if (http_transaction_) | |
| 290 http_transaction_.reset(); | |
| 291 URLRequestJob::Kill(); | |
| 292 weak_factory_.InvalidateWeakPtrs(); | |
| 293 } | |
| 294 | |
| 295 LoadState URLRequestFtpJob::GetLoadState() const { | 302 LoadState URLRequestFtpJob::GetLoadState() const { |
| 296 if (proxy_info_.is_direct()) { | 303 if (proxy_info_.is_direct()) { |
| 297 return ftp_transaction_ ? | 304 return ftp_transaction_ ? |
| 298 ftp_transaction_->GetLoadState() : LOAD_STATE_IDLE; | 305 ftp_transaction_->GetLoadState() : LOAD_STATE_IDLE; |
| 299 } else { | 306 } else { |
| 300 return http_transaction_ ? | 307 return http_transaction_ ? |
| 301 http_transaction_->GetLoadState() : LOAD_STATE_IDLE; | 308 http_transaction_->GetLoadState() : LOAD_STATE_IDLE; |
| 302 } | 309 } |
| 303 } | 310 } |
| 304 | 311 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 if (rv == ERR_IO_PENDING) { | 386 if (rv == ERR_IO_PENDING) { |
| 380 read_in_progress_ = true; | 387 read_in_progress_ = true; |
| 381 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 388 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 382 } else { | 389 } else { |
| 383 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 390 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 384 } | 391 } |
| 385 return false; | 392 return false; |
| 386 } | 393 } |
| 387 | 394 |
| 388 } // namespace net | 395 } // namespace net |
| OLD | NEW |