| 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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 int FtpNetworkTransaction::DoCtrlConnect() { | 644 int FtpNetworkTransaction::DoCtrlConnect() { |
| 645 next_state_ = STATE_CTRL_CONNECT_COMPLETE; | 645 next_state_ = STATE_CTRL_CONNECT_COMPLETE; |
| 646 ctrl_socket_.reset(socket_factory_->CreateTransportClientSocket( | 646 ctrl_socket_.reset(socket_factory_->CreateTransportClientSocket( |
| 647 addresses_, net_log_.net_log(), net_log_.source())); | 647 addresses_, net_log_.net_log(), net_log_.source())); |
| 648 return ctrl_socket_->Connect(io_callback_); | 648 return ctrl_socket_->Connect(io_callback_); |
| 649 } | 649 } |
| 650 | 650 |
| 651 int FtpNetworkTransaction::DoCtrlConnectComplete(int result) { | 651 int FtpNetworkTransaction::DoCtrlConnectComplete(int result) { |
| 652 if (result == OK) { | 652 if (result == OK) { |
| 653 // Put the peer's IP address and port into the response. | 653 // Put the peer's IP address and port into the response. |
| 654 AddressList address; | 654 IPEndPoint ip_endpoint; |
| 655 result = ctrl_socket_->GetPeerAddress(&address); | 655 result = ctrl_socket_->GetPeerAddress(&ip_endpoint); |
| 656 if (result == OK) { | 656 if (result == OK) { |
| 657 response_.socket_address = HostPortPair::FromIPEndPoint(address.front()); | 657 response_.socket_address = HostPortPair::FromIPEndPoint(ip_endpoint); |
| 658 next_state_ = STATE_CTRL_READ; | 658 next_state_ = STATE_CTRL_READ; |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 return result; | 661 return result; |
| 662 } | 662 } |
| 663 | 663 |
| 664 int FtpNetworkTransaction::DoCtrlRead() { | 664 int FtpNetworkTransaction::DoCtrlRead() { |
| 665 next_state_ = STATE_CTRL_READ_COMPLETE; | 665 next_state_ = STATE_CTRL_READ_COMPLETE; |
| 666 return ctrl_socket_->Read(read_ctrl_buf_, kCtrlBufLen, io_callback_); | 666 return ctrl_socket_->Read(read_ctrl_buf_, kCtrlBufLen, io_callback_); |
| 667 } | 667 } |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 int FtpNetworkTransaction::ProcessResponseQUIT( | 1181 int FtpNetworkTransaction::ProcessResponseQUIT( |
| 1182 const FtpCtrlResponse& response) { | 1182 const FtpCtrlResponse& response) { |
| 1183 ctrl_socket_->Disconnect(); | 1183 ctrl_socket_->Disconnect(); |
| 1184 return last_error_; | 1184 return last_error_; |
| 1185 } | 1185 } |
| 1186 | 1186 |
| 1187 // Data Connection | 1187 // Data Connection |
| 1188 | 1188 |
| 1189 int FtpNetworkTransaction::DoDataConnect() { | 1189 int FtpNetworkTransaction::DoDataConnect() { |
| 1190 next_state_ = STATE_DATA_CONNECT_COMPLETE; | 1190 next_state_ = STATE_DATA_CONNECT_COMPLETE; |
| 1191 IPEndPoint ip_endpoint; |
| 1191 AddressList data_address; | 1192 AddressList data_address; |
| 1192 // Connect to the same host as the control socket to prevent PASV port | 1193 // Connect to the same host as the control socket to prevent PASV port |
| 1193 // scanning attacks. | 1194 // scanning attacks. |
| 1194 int rv = ctrl_socket_->GetPeerAddress(&data_address); | 1195 int rv = ctrl_socket_->GetPeerAddress(&ip_endpoint); |
| 1195 if (rv != OK) | 1196 if (rv != OK) |
| 1196 return Stop(rv); | 1197 return Stop(rv); |
| 1197 data_address = AddressList::CreateFromIPAddress( | 1198 data_address = AddressList::CreateFromIPAddress( |
| 1198 data_address.front().address(), data_connection_port_); | 1199 ip_endpoint.address(), data_connection_port_); |
| 1199 data_socket_.reset(socket_factory_->CreateTransportClientSocket( | 1200 data_socket_.reset(socket_factory_->CreateTransportClientSocket( |
| 1200 data_address, net_log_.net_log(), net_log_.source())); | 1201 data_address, net_log_.net_log(), net_log_.source())); |
| 1201 return data_socket_->Connect(io_callback_); | 1202 return data_socket_->Connect(io_callback_); |
| 1202 } | 1203 } |
| 1203 | 1204 |
| 1204 int FtpNetworkTransaction::DoDataConnectComplete(int result) { | 1205 int FtpNetworkTransaction::DoDataConnectComplete(int result) { |
| 1205 if (result != OK && use_epsv_) { | 1206 if (result != OK && use_epsv_) { |
| 1206 // It's possible we hit a broken server, sadly. They can break in different | 1207 // It's possible we hit a broken server, sadly. They can break in different |
| 1207 // ways. Some time out, some reset a connection. Fall back to PASV. | 1208 // ways. Some time out, some reset a connection. Fall back to PASV. |
| 1208 // TODO(phajdan.jr): remember it for future transactions with this server. | 1209 // TODO(phajdan.jr): remember it for future transactions with this server. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 if (!had_error_type[type]) { | 1335 if (!had_error_type[type]) { |
| 1335 had_error_type[type] = true; | 1336 had_error_type[type] = true; |
| 1336 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", | 1337 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", |
| 1337 type, NUM_OF_NET_ERROR_TYPES); | 1338 type, NUM_OF_NET_ERROR_TYPES); |
| 1338 } | 1339 } |
| 1339 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", | 1340 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", |
| 1340 type, NUM_OF_NET_ERROR_TYPES); | 1341 type, NUM_OF_NET_ERROR_TYPES); |
| 1341 } | 1342 } |
| 1342 | 1343 |
| 1343 } // namespace net | 1344 } // namespace net |
| OLD | NEW |