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/ftp/ftp_network_transaction.h" | 5 #include "net/ftp/ftp_network_transaction.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 request_ = request_info; | 249 request_ = request_info; |
250 | 250 |
251 ctrl_response_buffer_.reset(new FtpCtrlResponseBuffer(net_log_)); | 251 ctrl_response_buffer_.reset(new FtpCtrlResponseBuffer(net_log_)); |
252 | 252 |
253 if (request_->url.has_username()) { | 253 if (request_->url.has_username()) { |
254 base::string16 username; | 254 base::string16 username; |
255 base::string16 password; | 255 base::string16 password; |
256 GetIdentityFromURL(request_->url, &username, &password); | 256 GetIdentityFromURL(request_->url, &username, &password); |
257 credentials_.Set(username, password); | 257 credentials_.Set(username, password); |
258 } else { | 258 } else { |
259 credentials_.Set(ASCIIToUTF16("anonymous"), | 259 credentials_.Set(base::ASCIIToUTF16("anonymous"), |
260 ASCIIToUTF16("chrome@example.com")); | 260 base::ASCIIToUTF16("chrome@example.com")); |
261 } | 261 } |
262 | 262 |
263 DetectTypecode(); | 263 DetectTypecode(); |
264 | 264 |
265 next_state_ = STATE_CTRL_RESOLVE_HOST; | 265 next_state_ = STATE_CTRL_RESOLVE_HOST; |
266 int rv = DoLoop(OK); | 266 int rv = DoLoop(OK); |
267 if (rv == ERR_IO_PENDING) | 267 if (rv == ERR_IO_PENDING) |
268 user_callback_ = callback; | 268 user_callback_ = callback; |
269 return rv; | 269 return rv; |
270 } | 270 } |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 next_state_ = STATE_CTRL_READ_COMPLETE; | 699 next_state_ = STATE_CTRL_READ_COMPLETE; |
700 return ctrl_socket_->Read(read_ctrl_buf_.get(), kCtrlBufLen, io_callback_); | 700 return ctrl_socket_->Read(read_ctrl_buf_.get(), kCtrlBufLen, io_callback_); |
701 } | 701 } |
702 | 702 |
703 int FtpNetworkTransaction::DoCtrlReadComplete(int result) { | 703 int FtpNetworkTransaction::DoCtrlReadComplete(int result) { |
704 if (result == 0) { | 704 if (result == 0) { |
705 // Some servers (for example Pure-FTPd) apparently close the control | 705 // Some servers (for example Pure-FTPd) apparently close the control |
706 // connection when anonymous login is not permitted. For more details | 706 // connection when anonymous login is not permitted. For more details |
707 // see http://crbug.com/25023. | 707 // see http://crbug.com/25023. |
708 if (command_sent_ == COMMAND_USER && | 708 if (command_sent_ == COMMAND_USER && |
709 credentials_.username() == ASCIIToUTF16("anonymous")) { | 709 credentials_.username() == base::ASCIIToUTF16("anonymous")) { |
710 response_.needs_auth = true; | 710 response_.needs_auth = true; |
711 } | 711 } |
712 return Stop(ERR_EMPTY_RESPONSE); | 712 return Stop(ERR_EMPTY_RESPONSE); |
713 } | 713 } |
714 if (result < 0) | 714 if (result < 0) |
715 return Stop(result); | 715 return Stop(result); |
716 | 716 |
717 ctrl_response_buffer_->ConsumeData(read_ctrl_buf_->data(), result); | 717 ctrl_response_buffer_->ConsumeData(read_ctrl_buf_->data(), result); |
718 | 718 |
719 if (!ctrl_response_buffer_->ResponseAvailable()) { | 719 if (!ctrl_response_buffer_->ResponseAvailable()) { |
(...skipping 26 matching lines...) Expand all Loading... |
746 } else { | 746 } else { |
747 next_state_ = STATE_CTRL_WRITE; | 747 next_state_ = STATE_CTRL_WRITE; |
748 } | 748 } |
749 return OK; | 749 return OK; |
750 } | 750 } |
751 | 751 |
752 // FTP Commands and responses | 752 // FTP Commands and responses |
753 | 753 |
754 // USER Command. | 754 // USER Command. |
755 int FtpNetworkTransaction::DoCtrlWriteUSER() { | 755 int FtpNetworkTransaction::DoCtrlWriteUSER() { |
756 std::string command = "USER " + UTF16ToUTF8(credentials_.username()); | 756 std::string command = "USER " + base::UTF16ToUTF8(credentials_.username()); |
757 | 757 |
758 if (!IsValidFTPCommandString(command)) | 758 if (!IsValidFTPCommandString(command)) |
759 return Stop(ERR_MALFORMED_IDENTITY); | 759 return Stop(ERR_MALFORMED_IDENTITY); |
760 | 760 |
761 next_state_ = STATE_CTRL_READ; | 761 next_state_ = STATE_CTRL_READ; |
762 return SendFtpCommand(command, "USER ***", COMMAND_USER); | 762 return SendFtpCommand(command, "USER ***", COMMAND_USER); |
763 } | 763 } |
764 | 764 |
765 int FtpNetworkTransaction::ProcessResponseUSER( | 765 int FtpNetworkTransaction::ProcessResponseUSER( |
766 const FtpCtrlResponse& response) { | 766 const FtpCtrlResponse& response) { |
(...skipping 10 matching lines...) Expand all Loading... |
777 return Stop(GetNetErrorCodeForFtpResponseCode(response.status_code)); | 777 return Stop(GetNetErrorCodeForFtpResponseCode(response.status_code)); |
778 default: | 778 default: |
779 NOTREACHED(); | 779 NOTREACHED(); |
780 return Stop(ERR_UNEXPECTED); | 780 return Stop(ERR_UNEXPECTED); |
781 } | 781 } |
782 return OK; | 782 return OK; |
783 } | 783 } |
784 | 784 |
785 // PASS command. | 785 // PASS command. |
786 int FtpNetworkTransaction::DoCtrlWritePASS() { | 786 int FtpNetworkTransaction::DoCtrlWritePASS() { |
787 std::string command = "PASS " + UTF16ToUTF8(credentials_.password()); | 787 std::string command = "PASS " + base::UTF16ToUTF8(credentials_.password()); |
788 | 788 |
789 if (!IsValidFTPCommandString(command)) | 789 if (!IsValidFTPCommandString(command)) |
790 return Stop(ERR_MALFORMED_IDENTITY); | 790 return Stop(ERR_MALFORMED_IDENTITY); |
791 | 791 |
792 next_state_ = STATE_CTRL_READ; | 792 next_state_ = STATE_CTRL_READ; |
793 return SendFtpCommand(command, "PASS ***", COMMAND_PASS); | 793 return SendFtpCommand(command, "PASS ***", COMMAND_PASS); |
794 } | 794 } |
795 | 795 |
796 int FtpNetworkTransaction::ProcessResponsePASS( | 796 int FtpNetworkTransaction::ProcessResponsePASS( |
797 const FtpCtrlResponse& response) { | 797 const FtpCtrlResponse& response) { |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 if (!had_error_type[type]) { | 1393 if (!had_error_type[type]) { |
1394 had_error_type[type] = true; | 1394 had_error_type[type] = true; |
1395 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", | 1395 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", |
1396 type, NUM_OF_NET_ERROR_TYPES); | 1396 type, NUM_OF_NET_ERROR_TYPES); |
1397 } | 1397 } |
1398 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", | 1398 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", |
1399 type, NUM_OF_NET_ERROR_TYPES); | 1399 type, NUM_OF_NET_ERROR_TYPES); |
1400 } | 1400 } |
1401 | 1401 |
1402 } // namespace net | 1402 } // namespace net |
OLD | NEW |