OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 205 |
206 int FtpNetworkTransaction::Start(const FtpRequestInfo* request_info, | 206 int FtpNetworkTransaction::Start(const FtpRequestInfo* request_info, |
207 CompletionCallback* callback, | 207 CompletionCallback* callback, |
208 const BoundNetLog& net_log) { | 208 const BoundNetLog& net_log) { |
209 net_log_ = net_log; | 209 net_log_ = net_log; |
210 request_ = request_info; | 210 request_ = request_info; |
211 | 211 |
212 if (request_->url.has_username()) { | 212 if (request_->url.has_username()) { |
213 GetIdentityFromURL(request_->url, &username_, &password_); | 213 GetIdentityFromURL(request_->url, &username_, &password_); |
214 } else { | 214 } else { |
215 username_ = L"anonymous"; | 215 username_ = ASCIIToUTF16("anonymous"); |
216 password_ = L"chrome@example.com"; | 216 password_ = ASCIIToUTF16("chrome@example.com"); |
217 } | 217 } |
218 | 218 |
219 DetectTypecode(); | 219 DetectTypecode(); |
220 | 220 |
221 next_state_ = STATE_CTRL_RESOLVE_HOST; | 221 next_state_ = STATE_CTRL_RESOLVE_HOST; |
222 int rv = DoLoop(OK); | 222 int rv = DoLoop(OK); |
223 if (rv == ERR_IO_PENDING) | 223 if (rv == ERR_IO_PENDING) |
224 user_callback_ = callback; | 224 user_callback_ = callback; |
225 return rv; | 225 return rv; |
226 } | 226 } |
227 | 227 |
228 int FtpNetworkTransaction::Stop(int error) { | 228 int FtpNetworkTransaction::Stop(int error) { |
229 if (command_sent_ == COMMAND_QUIT) | 229 if (command_sent_ == COMMAND_QUIT) |
230 return error; | 230 return error; |
231 | 231 |
232 next_state_ = STATE_CTRL_WRITE_QUIT; | 232 next_state_ = STATE_CTRL_WRITE_QUIT; |
233 last_error_ = error; | 233 last_error_ = error; |
234 return OK; | 234 return OK; |
235 } | 235 } |
236 | 236 |
237 int FtpNetworkTransaction::RestartWithAuth(const std::wstring& username, | 237 int FtpNetworkTransaction::RestartWithAuth(const string16& username, |
238 const std::wstring& password, | 238 const string16& password, |
239 CompletionCallback* callback) { | 239 CompletionCallback* callback) { |
240 ResetStateForRestart(); | 240 ResetStateForRestart(); |
241 | 241 |
242 username_ = username; | 242 username_ = username; |
243 password_ = password; | 243 password_ = password; |
244 | 244 |
245 next_state_ = STATE_CTRL_RESOLVE_HOST; | 245 next_state_ = STATE_CTRL_RESOLVE_HOST; |
246 int rv = DoLoop(OK); | 246 int rv = DoLoop(OK); |
247 if (rv == ERR_IO_PENDING) | 247 if (rv == ERR_IO_PENDING) |
248 user_callback_ = callback; | 248 user_callback_ = callback; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 read_ctrl_buf_, | 646 read_ctrl_buf_, |
647 kCtrlBufLen, | 647 kCtrlBufLen, |
648 &io_callback_); | 648 &io_callback_); |
649 } | 649 } |
650 | 650 |
651 int FtpNetworkTransaction::DoCtrlReadComplete(int result) { | 651 int FtpNetworkTransaction::DoCtrlReadComplete(int result) { |
652 if (result == 0) { | 652 if (result == 0) { |
653 // Some servers (for example Pure-FTPd) apparently close the control | 653 // Some servers (for example Pure-FTPd) apparently close the control |
654 // connection when anonymous login is not permitted. For more details | 654 // connection when anonymous login is not permitted. For more details |
655 // see http://crbug.com/25023. | 655 // see http://crbug.com/25023. |
656 if (command_sent_ == COMMAND_USER && username_ == L"anonymous") | 656 if (command_sent_ == COMMAND_USER && username_ == ASCIIToUTF16("anonymous")) |
657 response_.needs_auth = true; | 657 response_.needs_auth = true; |
658 return Stop(ERR_EMPTY_RESPONSE); | 658 return Stop(ERR_EMPTY_RESPONSE); |
659 } | 659 } |
660 if (result < 0) | 660 if (result < 0) |
661 return Stop(result); | 661 return Stop(result); |
662 | 662 |
663 ctrl_response_buffer_->ConsumeData(read_ctrl_buf_->data(), result); | 663 ctrl_response_buffer_->ConsumeData(read_ctrl_buf_->data(), result); |
664 | 664 |
665 if (!ctrl_response_buffer_->ResponseAvailable()) { | 665 if (!ctrl_response_buffer_->ResponseAvailable()) { |
666 // Read more data from the control socket. | 666 // Read more data from the control socket. |
(...skipping 26 matching lines...) Expand all Loading... |
693 } else { | 693 } else { |
694 next_state_ = STATE_CTRL_WRITE; | 694 next_state_ = STATE_CTRL_WRITE; |
695 } | 695 } |
696 return OK; | 696 return OK; |
697 } | 697 } |
698 | 698 |
699 // FTP Commands and responses | 699 // FTP Commands and responses |
700 | 700 |
701 // USER Command. | 701 // USER Command. |
702 int FtpNetworkTransaction::DoCtrlWriteUSER() { | 702 int FtpNetworkTransaction::DoCtrlWriteUSER() { |
703 std::string command = "USER " + WideToUTF8(username_); | 703 std::string command = "USER " + UTF16ToUTF8(username_); |
704 | 704 |
705 if (!IsValidFTPCommandString(command)) | 705 if (!IsValidFTPCommandString(command)) |
706 return Stop(ERR_MALFORMED_IDENTITY); | 706 return Stop(ERR_MALFORMED_IDENTITY); |
707 | 707 |
708 next_state_ = STATE_CTRL_READ; | 708 next_state_ = STATE_CTRL_READ; |
709 return SendFtpCommand(command, COMMAND_USER); | 709 return SendFtpCommand(command, COMMAND_USER); |
710 } | 710 } |
711 | 711 |
712 int FtpNetworkTransaction::ProcessResponseUSER( | 712 int FtpNetworkTransaction::ProcessResponseUSER( |
713 const FtpCtrlResponse& response) { | 713 const FtpCtrlResponse& response) { |
(...skipping 11 matching lines...) Expand all Loading... |
725 return Stop(GetNetErrorCodeForFtpResponseCode(response.status_code)); | 725 return Stop(GetNetErrorCodeForFtpResponseCode(response.status_code)); |
726 default: | 726 default: |
727 NOTREACHED(); | 727 NOTREACHED(); |
728 return Stop(ERR_UNEXPECTED); | 728 return Stop(ERR_UNEXPECTED); |
729 } | 729 } |
730 return OK; | 730 return OK; |
731 } | 731 } |
732 | 732 |
733 // PASS command. | 733 // PASS command. |
734 int FtpNetworkTransaction::DoCtrlWritePASS() { | 734 int FtpNetworkTransaction::DoCtrlWritePASS() { |
735 std::string command = "PASS " + WideToUTF8(password_); | 735 std::string command = "PASS " + UTF16ToUTF8(password_); |
736 | 736 |
737 if (!IsValidFTPCommandString(command)) | 737 if (!IsValidFTPCommandString(command)) |
738 return Stop(ERR_MALFORMED_IDENTITY); | 738 return Stop(ERR_MALFORMED_IDENTITY); |
739 | 739 |
740 next_state_ = STATE_CTRL_READ; | 740 next_state_ = STATE_CTRL_READ; |
741 return SendFtpCommand(command, COMMAND_PASS); | 741 return SendFtpCommand(command, COMMAND_PASS); |
742 } | 742 } |
743 | 743 |
744 int FtpNetworkTransaction::ProcessResponsePASS( | 744 int FtpNetworkTransaction::ProcessResponsePASS( |
745 const FtpCtrlResponse& response) { | 745 const FtpCtrlResponse& response) { |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 if (!had_error_type[type]) { | 1318 if (!had_error_type[type]) { |
1319 had_error_type[type] = true; | 1319 had_error_type[type] = true; |
1320 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", | 1320 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", |
1321 type, NUM_OF_NET_ERROR_TYPES); | 1321 type, NUM_OF_NET_ERROR_TYPES); |
1322 } | 1322 } |
1323 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", | 1323 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", |
1324 type, NUM_OF_NET_ERROR_TYPES); | 1324 type, NUM_OF_NET_ERROR_TYPES); |
1325 } | 1325 } |
1326 | 1326 |
1327 } // namespace net | 1327 } // namespace net |
OLD | NEW |