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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 329 } |
330 | 330 |
331 void FtpNetworkTransaction::ResetStateForRestart() { | 331 void FtpNetworkTransaction::ResetStateForRestart() { |
332 command_sent_ = COMMAND_NONE; | 332 command_sent_ = COMMAND_NONE; |
333 user_callback_.Reset(); | 333 user_callback_.Reset(); |
334 response_ = FtpResponseInfo(); | 334 response_ = FtpResponseInfo(); |
335 read_ctrl_buf_ = new IOBuffer(kCtrlBufLen); | 335 read_ctrl_buf_ = new IOBuffer(kCtrlBufLen); |
336 ctrl_response_buffer_.reset(new FtpCtrlResponseBuffer()); | 336 ctrl_response_buffer_.reset(new FtpCtrlResponseBuffer()); |
337 read_data_buf_ = NULL; | 337 read_data_buf_ = NULL; |
338 read_data_buf_len_ = 0; | 338 read_data_buf_len_ = 0; |
339 if (write_buf_) | 339 if (write_buf_.get()) |
340 write_buf_->SetOffset(0); | 340 write_buf_->SetOffset(0); |
341 last_error_ = OK; | 341 last_error_ = OK; |
342 data_connection_port_ = 0; | 342 data_connection_port_ = 0; |
343 ctrl_socket_.reset(); | 343 ctrl_socket_.reset(); |
344 data_socket_.reset(); | 344 data_socket_.reset(); |
345 next_state_ = STATE_NONE; | 345 next_state_ = STATE_NONE; |
346 } | 346 } |
347 | 347 |
348 void FtpNetworkTransaction::DoCallback(int rv) { | 348 void FtpNetworkTransaction::DoCallback(int rv) { |
349 DCHECK(rv != ERR_IO_PENDING); | 349 DCHECK(rv != ERR_IO_PENDING); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 } | 433 } |
434 | 434 |
435 // Used to prepare and send FTP command. | 435 // Used to prepare and send FTP command. |
436 int FtpNetworkTransaction::SendFtpCommand(const std::string& command, | 436 int FtpNetworkTransaction::SendFtpCommand(const std::string& command, |
437 Command cmd) { | 437 Command cmd) { |
438 // If we send a new command when we still have unprocessed responses | 438 // If we send a new command when we still have unprocessed responses |
439 // for previous commands, the response receiving code will have no way to know | 439 // for previous commands, the response receiving code will have no way to know |
440 // which responses are for which command. | 440 // which responses are for which command. |
441 DCHECK(!ctrl_response_buffer_->ResponseAvailable()); | 441 DCHECK(!ctrl_response_buffer_->ResponseAvailable()); |
442 | 442 |
443 DCHECK(!write_command_buf_); | 443 DCHECK(!write_command_buf_.get()); |
444 DCHECK(!write_buf_); | 444 DCHECK(!write_buf_.get()); |
445 | 445 |
446 if (!IsValidFTPCommandString(command)) { | 446 if (!IsValidFTPCommandString(command)) { |
447 // Callers should validate the command themselves and return a more specific | 447 // Callers should validate the command themselves and return a more specific |
448 // error code. | 448 // error code. |
449 NOTREACHED(); | 449 NOTREACHED(); |
450 return Stop(ERR_UNEXPECTED); | 450 return Stop(ERR_UNEXPECTED); |
451 } | 451 } |
452 | 452 |
453 command_sent_ = cmd; | 453 command_sent_ = cmd; |
454 | 454 |
455 write_command_buf_ = new IOBufferWithSize(command.length() + 2); | 455 write_command_buf_ = new IOBufferWithSize(command.length() + 2); |
456 write_buf_ = new DrainableIOBuffer(write_command_buf_, | 456 write_buf_ = new DrainableIOBuffer(write_command_buf_.get(), |
457 write_command_buf_->size()); | 457 write_command_buf_->size()); |
458 memcpy(write_command_buf_->data(), command.data(), command.length()); | 458 memcpy(write_command_buf_->data(), command.data(), command.length()); |
459 memcpy(write_command_buf_->data() + command.length(), kCRLF, 2); | 459 memcpy(write_command_buf_->data() + command.length(), kCRLF, 2); |
460 | 460 |
461 next_state_ = STATE_CTRL_WRITE; | 461 next_state_ = STATE_CTRL_WRITE; |
462 return OK; | 462 return OK; |
463 } | 463 } |
464 | 464 |
465 std::string FtpNetworkTransaction::GetRequestPathForFtpCommand( | 465 std::string FtpNetworkTransaction::GetRequestPathForFtpCommand( |
466 bool is_directory) const { | 466 bool is_directory) const { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 if (result == OK) { | 656 if (result == OK) { |
657 response_.socket_address = HostPortPair::FromIPEndPoint(ip_endpoint); | 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_.get(), kCtrlBufLen, io_callback_); |
667 } | 667 } |
668 | 668 |
669 int FtpNetworkTransaction::DoCtrlReadComplete(int result) { | 669 int FtpNetworkTransaction::DoCtrlReadComplete(int result) { |
670 if (result == 0) { | 670 if (result == 0) { |
671 // Some servers (for example Pure-FTPd) apparently close the control | 671 // Some servers (for example Pure-FTPd) apparently close the control |
672 // connection when anonymous login is not permitted. For more details | 672 // connection when anonymous login is not permitted. For more details |
673 // see http://crbug.com/25023. | 673 // see http://crbug.com/25023. |
674 if (command_sent_ == COMMAND_USER && | 674 if (command_sent_ == COMMAND_USER && |
675 credentials_.username() == ASCIIToUTF16("anonymous")) { | 675 credentials_.username() == ASCIIToUTF16("anonymous")) { |
676 response_.needs_auth = true; | 676 response_.needs_auth = true; |
(...skipping 10 matching lines...) Expand all Loading... |
687 next_state_ = STATE_CTRL_READ; | 687 next_state_ = STATE_CTRL_READ; |
688 return OK; | 688 return OK; |
689 } | 689 } |
690 | 690 |
691 return ProcessCtrlResponse(); | 691 return ProcessCtrlResponse(); |
692 } | 692 } |
693 | 693 |
694 int FtpNetworkTransaction::DoCtrlWrite() { | 694 int FtpNetworkTransaction::DoCtrlWrite() { |
695 next_state_ = STATE_CTRL_WRITE_COMPLETE; | 695 next_state_ = STATE_CTRL_WRITE_COMPLETE; |
696 | 696 |
697 return ctrl_socket_->Write(write_buf_, | 697 return ctrl_socket_->Write(write_buf_.get(), |
698 write_buf_->BytesRemaining(), | 698 write_buf_->BytesRemaining(), |
699 io_callback_); | 699 io_callback_); |
700 } | 700 } |
701 | 701 |
702 int FtpNetworkTransaction::DoCtrlWriteComplete(int result) { | 702 int FtpNetworkTransaction::DoCtrlWriteComplete(int result) { |
703 if (result < 0) | 703 if (result < 0) |
704 return result; | 704 return result; |
705 | 705 |
706 write_buf_->DidConsume(result); | 706 write_buf_->DidConsume(result); |
707 if (write_buf_->BytesRemaining() == 0) { | 707 if (write_buf_->BytesRemaining() == 0) { |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 next_state_ = STATE_CTRL_READ; | 1239 next_state_ = STATE_CTRL_READ; |
1240 return OK; | 1240 return OK; |
1241 } | 1241 } |
1242 | 1242 |
1243 // We are no longer connected to the server, so just finish the transaction. | 1243 // We are no longer connected to the server, so just finish the transaction. |
1244 return Stop(OK); | 1244 return Stop(OK); |
1245 } | 1245 } |
1246 | 1246 |
1247 next_state_ = STATE_DATA_READ_COMPLETE; | 1247 next_state_ = STATE_DATA_READ_COMPLETE; |
1248 read_data_buf_->data()[0] = 0; | 1248 read_data_buf_->data()[0] = 0; |
1249 return data_socket_->Read(read_data_buf_, read_data_buf_len_, io_callback_); | 1249 return data_socket_-> |
| 1250 Read(read_data_buf_.get(), read_data_buf_len_, io_callback_); |
1250 } | 1251 } |
1251 | 1252 |
1252 int FtpNetworkTransaction::DoDataReadComplete(int result) { | 1253 int FtpNetworkTransaction::DoDataReadComplete(int result) { |
1253 return result; | 1254 return result; |
1254 } | 1255 } |
1255 | 1256 |
1256 // We're using a histogram as a group of counters, with one bucket for each | 1257 // We're using a histogram as a group of counters, with one bucket for each |
1257 // enumeration value. We're only interested in the values of the counters. | 1258 // enumeration value. We're only interested in the values of the counters. |
1258 // Ignore the shape, average, and standard deviation of the histograms because | 1259 // Ignore the shape, average, and standard deviation of the histograms because |
1259 // they are meaningless. | 1260 // they are meaningless. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 if (!had_error_type[type]) { | 1336 if (!had_error_type[type]) { |
1336 had_error_type[type] = true; | 1337 had_error_type[type] = true; |
1337 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", | 1338 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", |
1338 type, NUM_OF_NET_ERROR_TYPES); | 1339 type, NUM_OF_NET_ERROR_TYPES); |
1339 } | 1340 } |
1340 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", | 1341 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", |
1341 type, NUM_OF_NET_ERROR_TYPES); | 1342 type, NUM_OF_NET_ERROR_TYPES); |
1342 } | 1343 } |
1343 | 1344 |
1344 } // namespace net | 1345 } // namespace net |
OLD | NEW |