| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // 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/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/base/connection_type_histograms.h" | 9 #include "net/base/connection_type_histograms.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 int FtpNetworkTransaction::RestartIgnoringLastError( | 77 int FtpNetworkTransaction::RestartIgnoringLastError( |
| 78 CompletionCallback* callback) { | 78 CompletionCallback* callback) { |
| 79 return ERR_FAILED; | 79 return ERR_FAILED; |
| 80 } | 80 } |
| 81 | 81 |
| 82 int FtpNetworkTransaction::Read(IOBuffer* buf, | 82 int FtpNetworkTransaction::Read(IOBuffer* buf, |
| 83 int buf_len, | 83 int buf_len, |
| 84 CompletionCallback* callback) { | 84 CompletionCallback* callback) { |
| 85 DCHECK(buf); | 85 DCHECK(buf); |
| 86 DCHECK(buf_len > 0); | 86 DCHECK_GT(buf_len, 0); |
| 87 | |
| 88 if (data_socket_ == NULL) | |
| 89 return 0; // Data socket closed, no more data left. | |
| 90 | |
| 91 if (!data_socket_->IsConnected()) | |
| 92 return 0; // Data socket disconnected, no more data left. | |
| 93 | 87 |
| 94 read_data_buf_ = buf; | 88 read_data_buf_ = buf; |
| 95 read_data_buf_len_ = buf_len; | 89 read_data_buf_len_ = buf_len; |
| 96 | 90 |
| 97 next_state_ = STATE_DATA_READ; | 91 next_state_ = STATE_DATA_READ; |
| 98 | |
| 99 int rv = DoLoop(OK); | 92 int rv = DoLoop(OK); |
| 100 if (rv == ERR_IO_PENDING) | 93 if (rv == ERR_IO_PENDING) |
| 101 user_callback_ = callback; | 94 user_callback_ = callback; |
| 102 else if (rv == 0) | |
| 103 data_socket_->Disconnect(); | |
| 104 return rv; | 95 return rv; |
| 105 } | 96 } |
| 106 | 97 |
| 107 const FtpResponseInfo* FtpNetworkTransaction::GetResponseInfo() const { | 98 const FtpResponseInfo* FtpNetworkTransaction::GetResponseInfo() const { |
| 108 return &response_; | 99 return &response_; |
| 109 } | 100 } |
| 110 | 101 |
| 111 LoadState FtpNetworkTransaction::GetLoadState() const { | 102 LoadState FtpNetworkTransaction::GetLoadState() const { |
| 112 return LOAD_STATE_IDLE; | 103 return LOAD_STATE_IDLE; |
| 113 } | 104 } |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 int FtpNetworkTransaction::DoCtrlWriteLIST() { | 820 int FtpNetworkTransaction::DoCtrlWriteLIST() { |
| 830 std::string command = "LIST"; | 821 std::string command = "LIST"; |
| 831 next_state_ = STATE_CTRL_READ; | 822 next_state_ = STATE_CTRL_READ; |
| 832 return SendFtpCommand(command, COMMAND_LIST); | 823 return SendFtpCommand(command, COMMAND_LIST); |
| 833 } | 824 } |
| 834 | 825 |
| 835 int FtpNetworkTransaction::ProcessResponseLIST( | 826 int FtpNetworkTransaction::ProcessResponseLIST( |
| 836 const FtpCtrlResponse& response) { | 827 const FtpCtrlResponse& response) { |
| 837 switch (GetErrorClass(response.status_code)) { | 828 switch (GetErrorClass(response.status_code)) { |
| 838 case ERROR_CLASS_INITIATED: | 829 case ERROR_CLASS_INITIATED: |
| 839 next_state_ = STATE_CTRL_READ; | 830 response_.is_directory_listing = true; |
| 840 break; | 831 break; |
| 841 case ERROR_CLASS_OK: | 832 case ERROR_CLASS_OK: |
| 842 response_.is_directory_listing = true; | 833 response_.is_directory_listing = true; |
| 843 next_state_ = STATE_CTRL_WRITE_QUIT; | 834 next_state_ = STATE_CTRL_WRITE_QUIT; |
| 844 break; | 835 break; |
| 845 case ERROR_CLASS_PENDING: | 836 case ERROR_CLASS_PENDING: |
| 846 return Stop(ERR_FAILED); | 837 return Stop(ERR_FAILED); |
| 847 case ERROR_CLASS_ERROR_RETRY: | 838 case ERROR_CLASS_ERROR_RETRY: |
| 848 return Stop(ERR_FAILED); | 839 return Stop(ERR_FAILED); |
| 849 case ERROR_CLASS_ERROR: | 840 case ERROR_CLASS_ERROR: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 if (retr_failed_) { | 891 if (retr_failed_) { |
| 901 next_state_ = STATE_CTRL_WRITE_CWD; | 892 next_state_ = STATE_CTRL_WRITE_CWD; |
| 902 } else { | 893 } else { |
| 903 next_state_ = STATE_CTRL_WRITE_SIZE; | 894 next_state_ = STATE_CTRL_WRITE_SIZE; |
| 904 } | 895 } |
| 905 return OK; | 896 return OK; |
| 906 } | 897 } |
| 907 | 898 |
| 908 int FtpNetworkTransaction::DoDataRead() { | 899 int FtpNetworkTransaction::DoDataRead() { |
| 909 DCHECK(read_data_buf_); | 900 DCHECK(read_data_buf_); |
| 910 DCHECK(read_data_buf_len_ > 0); | 901 DCHECK_GT(read_data_buf_len_, 0); |
| 902 |
| 903 if (data_socket_ == NULL || !data_socket_->IsConnected()) { |
| 904 // No more data so send QUIT Command now and wait for response. |
| 905 return Stop(OK); |
| 906 } |
| 911 | 907 |
| 912 next_state_ = STATE_DATA_READ_COMPLETE; | 908 next_state_ = STATE_DATA_READ_COMPLETE; |
| 913 read_data_buf_->data()[0] = 0; | 909 read_data_buf_->data()[0] = 0; |
| 914 return data_socket_->Read(read_data_buf_, read_data_buf_len_, | 910 return data_socket_->Read(read_data_buf_, read_data_buf_len_, |
| 915 &io_callback_); | 911 &io_callback_); |
| 916 } | 912 } |
| 917 | 913 |
| 918 int FtpNetworkTransaction::DoDataReadComplete(int result) { | 914 int FtpNetworkTransaction::DoDataReadComplete(int result) { |
| 919 return result; | 915 return result; |
| 920 } | 916 } |
| 921 | 917 |
| 922 } // namespace net | 918 } // namespace net |
| OLD | NEW |