| 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" |
| 11 #include "net/base/host_port_pair.h" | 11 #include "net/base/host_port_pair.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
| 14 #include "net/ftp/ftp_auth_cache.h" |
| 14 #include "net/ftp/ftp_response_info.h" | 15 #include "net/ftp/ftp_response_info.h" |
| 15 #include "net/ftp/ftp_transaction_factory.h" | 16 #include "net/ftp/ftp_transaction_factory.h" |
| 16 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
| 17 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
| 18 #include "net/url_request/url_request_error_job.h" | 19 #include "net/url_request/url_request_error_job.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| 22 URLRequestFtpJob::URLRequestFtpJob( | 23 URLRequestFtpJob::URLRequestFtpJob( |
| 23 URLRequest* request, | 24 URLRequest* request, |
| 24 NetworkDelegate* network_delegate, | 25 NetworkDelegate* network_delegate, |
| 25 FtpTransactionFactory* ftp_transaction_factory, | 26 FtpTransactionFactory* ftp_transaction_factory, |
| 26 FtpAuthCache* ftp_auth_cache) | 27 FtpAuthCache* ftp_auth_cache) |
| 27 : URLRequestJob(request, network_delegate), | 28 : URLRequestJob(request, network_delegate), |
| 28 read_in_progress_(false), | 29 read_in_progress_(false), |
| 29 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 30 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 30 ftp_transaction_factory_(ftp_transaction_factory), | 31 ftp_transaction_factory_(ftp_transaction_factory), |
| 31 ftp_auth_cache_(ftp_auth_cache) { | 32 ftp_auth_cache_(ftp_auth_cache) { |
| 32 DCHECK(ftp_transaction_factory); | 33 DCHECK(ftp_transaction_factory); |
| 33 DCHECK(ftp_auth_cache); | 34 DCHECK(ftp_auth_cache); |
| 34 } | 35 } |
| 35 | 36 |
| 36 // static | |
| 37 URLRequestJob* URLRequestFtpJob::Factory(URLRequest* request, | |
| 38 NetworkDelegate* network_delegate, | |
| 39 const std::string& scheme) { | |
| 40 DCHECK_EQ(scheme, "ftp"); | |
| 41 | |
| 42 int port = request->url().IntPort(); | |
| 43 if (request->url().has_port() && | |
| 44 !IsPortAllowedByFtp(port) && !IsPortAllowedByOverride(port)) { | |
| 45 return new URLRequestErrorJob(request, | |
| 46 network_delegate, | |
| 47 ERR_UNSAFE_PORT); | |
| 48 } | |
| 49 | |
| 50 return new URLRequestFtpJob(request, | |
| 51 network_delegate, | |
| 52 request->context()->ftp_transaction_factory(), | |
| 53 request->context()->ftp_auth_cache()); | |
| 54 } | |
| 55 | |
| 56 bool URLRequestFtpJob::GetMimeType(std::string* mime_type) const { | 37 bool URLRequestFtpJob::GetMimeType(std::string* mime_type) const { |
| 57 if (transaction_->GetResponseInfo()->is_directory_listing) { | 38 if (transaction_->GetResponseInfo()->is_directory_listing) { |
| 58 *mime_type = "text/vnd.chromium.ftp-dir"; | 39 *mime_type = "text/vnd.chromium.ftp-dir"; |
| 59 return true; | 40 return true; |
| 60 } | 41 } |
| 61 return false; | 42 return false; |
| 62 } | 43 } |
| 63 | 44 |
| 64 HostPortPair URLRequestFtpJob::GetSocketAddress() const { | 45 HostPortPair URLRequestFtpJob::GetSocketAddress() const { |
| 65 if (!transaction_.get()) { | 46 if (!transaction_.get()) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (rv == ERR_IO_PENDING) { | 236 if (rv == ERR_IO_PENDING) { |
| 256 read_in_progress_ = true; | 237 read_in_progress_ = true; |
| 257 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 238 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 258 } else { | 239 } else { |
| 259 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 240 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 260 } | 241 } |
| 261 return false; | 242 return false; |
| 262 } | 243 } |
| 263 | 244 |
| 264 } // namespace net | 245 } // namespace net |
| OLD | NEW |