Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: net/ftp/ftp_network_transaction.cc

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/ftp/ftp_network_layer.cc ('k') | net/http/http_auth_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 332 }
333 333
334 void FtpNetworkTransaction::ResetStateForRestart() { 334 void FtpNetworkTransaction::ResetStateForRestart() {
335 command_sent_ = COMMAND_NONE; 335 command_sent_ = COMMAND_NONE;
336 user_callback_.Reset(); 336 user_callback_.Reset();
337 response_ = FtpResponseInfo(); 337 response_ = FtpResponseInfo();
338 read_ctrl_buf_ = new IOBuffer(kCtrlBufLen); 338 read_ctrl_buf_ = new IOBuffer(kCtrlBufLen);
339 ctrl_response_buffer_.reset(new FtpCtrlResponseBuffer(net_log_)); 339 ctrl_response_buffer_.reset(new FtpCtrlResponseBuffer(net_log_));
340 read_data_buf_ = NULL; 340 read_data_buf_ = NULL;
341 read_data_buf_len_ = 0; 341 read_data_buf_len_ = 0;
342 if (write_buf_) 342 if (write_buf_.get())
343 write_buf_->SetOffset(0); 343 write_buf_->SetOffset(0);
344 last_error_ = OK; 344 last_error_ = OK;
345 data_connection_port_ = 0; 345 data_connection_port_ = 0;
346 ctrl_socket_.reset(); 346 ctrl_socket_.reset();
347 data_socket_.reset(); 347 data_socket_.reset();
348 next_state_ = STATE_NONE; 348 next_state_ = STATE_NONE;
349 state_after_data_connect_complete_ = STATE_CTRL_WRITE_SIZE; 349 state_after_data_connect_complete_ = STATE_CTRL_WRITE_SIZE;
350 } 350 }
351 351
352 void FtpNetworkTransaction::ResetDataConnectionAfterError(State next_state) { 352 void FtpNetworkTransaction::ResetDataConnectionAfterError(State next_state) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 452
453 // Used to prepare and send FTP command. 453 // Used to prepare and send FTP command.
454 int FtpNetworkTransaction::SendFtpCommand(const std::string& command, 454 int FtpNetworkTransaction::SendFtpCommand(const std::string& command,
455 const std::string& command_for_log, 455 const std::string& command_for_log,
456 Command cmd) { 456 Command cmd) {
457 // If we send a new command when we still have unprocessed responses 457 // If we send a new command when we still have unprocessed responses
458 // for previous commands, the response receiving code will have no way to know 458 // for previous commands, the response receiving code will have no way to know
459 // which responses are for which command. 459 // which responses are for which command.
460 DCHECK(!ctrl_response_buffer_->ResponseAvailable()); 460 DCHECK(!ctrl_response_buffer_->ResponseAvailable());
461 461
462 DCHECK(!write_command_buf_); 462 DCHECK(!write_command_buf_.get());
463 DCHECK(!write_buf_); 463 DCHECK(!write_buf_.get());
464 464
465 if (!IsValidFTPCommandString(command)) { 465 if (!IsValidFTPCommandString(command)) {
466 // Callers should validate the command themselves and return a more specific 466 // Callers should validate the command themselves and return a more specific
467 // error code. 467 // error code.
468 NOTREACHED(); 468 NOTREACHED();
469 return Stop(ERR_UNEXPECTED); 469 return Stop(ERR_UNEXPECTED);
470 } 470 }
471 471
472 command_sent_ = cmd; 472 command_sent_ = cmd;
473 473
474 write_command_buf_ = new IOBufferWithSize(command.length() + 2); 474 write_command_buf_ = new IOBufferWithSize(command.length() + 2);
475 write_buf_ = new DrainableIOBuffer(write_command_buf_, 475 write_buf_ = new DrainableIOBuffer(write_command_buf_.get(),
476 write_command_buf_->size()); 476 write_command_buf_->size());
477 memcpy(write_command_buf_->data(), command.data(), command.length()); 477 memcpy(write_command_buf_->data(), command.data(), command.length());
478 memcpy(write_command_buf_->data() + command.length(), kCRLF, 2); 478 memcpy(write_command_buf_->data() + command.length(), kCRLF, 2);
479 479
480 net_log_.AddEvent(NetLog::TYPE_FTP_COMMAND_SENT, 480 net_log_.AddEvent(NetLog::TYPE_FTP_COMMAND_SENT,
481 NetLog::StringCallback("command", &command_for_log)); 481 NetLog::StringCallback("command", &command_for_log));
482 482
483 next_state_ = STATE_CTRL_WRITE; 483 next_state_ = STATE_CTRL_WRITE;
484 return OK; 484 return OK;
485 } 485 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 // all future protocols should just use EPSV. 690 // all future protocols should just use EPSV.
691 use_epsv_ = false; 691 use_epsv_ = false;
692 } 692 }
693 } 693 }
694 } 694 }
695 return result; 695 return result;
696 } 696 }
697 697
698 int FtpNetworkTransaction::DoCtrlRead() { 698 int FtpNetworkTransaction::DoCtrlRead() {
699 next_state_ = STATE_CTRL_READ_COMPLETE; 699 next_state_ = STATE_CTRL_READ_COMPLETE;
700 return ctrl_socket_->Read(read_ctrl_buf_, 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() == ASCIIToUTF16("anonymous")) {
710 response_.needs_auth = true; 710 response_.needs_auth = true;
(...skipping 10 matching lines...) Expand all
721 next_state_ = STATE_CTRL_READ; 721 next_state_ = STATE_CTRL_READ;
722 return OK; 722 return OK;
723 } 723 }
724 724
725 return ProcessCtrlResponse(); 725 return ProcessCtrlResponse();
726 } 726 }
727 727
728 int FtpNetworkTransaction::DoCtrlWrite() { 728 int FtpNetworkTransaction::DoCtrlWrite() {
729 next_state_ = STATE_CTRL_WRITE_COMPLETE; 729 next_state_ = STATE_CTRL_WRITE_COMPLETE;
730 730
731 return ctrl_socket_->Write(write_buf_, 731 return ctrl_socket_->Write(
732 write_buf_->BytesRemaining(), 732 write_buf_.get(), write_buf_->BytesRemaining(), io_callback_);
733 io_callback_);
734 } 733 }
735 734
736 int FtpNetworkTransaction::DoCtrlWriteComplete(int result) { 735 int FtpNetworkTransaction::DoCtrlWriteComplete(int result) {
737 if (result < 0) 736 if (result < 0)
738 return result; 737 return result;
739 738
740 write_buf_->DidConsume(result); 739 write_buf_->DidConsume(result);
741 if (write_buf_->BytesRemaining() == 0) { 740 if (write_buf_->BytesRemaining() == 0) {
742 // Clear the write buffer. 741 // Clear the write buffer.
743 write_buf_ = NULL; 742 write_buf_ = NULL;
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 RecordDataConnectionError(result); 1275 RecordDataConnectionError(result);
1277 1276
1278 if (result != OK) 1277 if (result != OK)
1279 return Stop(result); 1278 return Stop(result);
1280 1279
1281 next_state_ = state_after_data_connect_complete_; 1280 next_state_ = state_after_data_connect_complete_;
1282 return OK; 1281 return OK;
1283 } 1282 }
1284 1283
1285 int FtpNetworkTransaction::DoDataRead() { 1284 int FtpNetworkTransaction::DoDataRead() {
1286 DCHECK(read_data_buf_); 1285 DCHECK(read_data_buf_.get());
1287 DCHECK_GT(read_data_buf_len_, 0); 1286 DCHECK_GT(read_data_buf_len_, 0);
1288 1287
1289 if (data_socket_ == NULL || !data_socket_->IsConnected()) { 1288 if (data_socket_ == NULL || !data_socket_->IsConnected()) {
1290 // If we don't destroy the data socket completely, some servers will wait 1289 // If we don't destroy the data socket completely, some servers will wait
1291 // for us (http://crbug.com/21127). The half-closed TCP connection needs 1290 // for us (http://crbug.com/21127). The half-closed TCP connection needs
1292 // to be closed on our side too. 1291 // to be closed on our side too.
1293 data_socket_.reset(); 1292 data_socket_.reset();
1294 1293
1295 if (ctrl_socket_->IsConnected()) { 1294 if (ctrl_socket_->IsConnected()) {
1296 // Wait for the server's response, we should get it before sending QUIT. 1295 // Wait for the server's response, we should get it before sending QUIT.
1297 next_state_ = STATE_CTRL_READ; 1296 next_state_ = STATE_CTRL_READ;
1298 return OK; 1297 return OK;
1299 } 1298 }
1300 1299
1301 // We are no longer connected to the server, so just finish the transaction. 1300 // We are no longer connected to the server, so just finish the transaction.
1302 return Stop(OK); 1301 return Stop(OK);
1303 } 1302 }
1304 1303
1305 next_state_ = STATE_DATA_READ_COMPLETE; 1304 next_state_ = STATE_DATA_READ_COMPLETE;
1306 read_data_buf_->data()[0] = 0; 1305 read_data_buf_->data()[0] = 0;
1307 return data_socket_->Read(read_data_buf_, read_data_buf_len_, io_callback_); 1306 return data_socket_->Read(
1307 read_data_buf_.get(), read_data_buf_len_, io_callback_);
1308 } 1308 }
1309 1309
1310 int FtpNetworkTransaction::DoDataReadComplete(int result) { 1310 int FtpNetworkTransaction::DoDataReadComplete(int result) {
1311 return result; 1311 return result;
1312 } 1312 }
1313 1313
1314 // We're using a histogram as a group of counters, with one bucket for each 1314 // We're using a histogram as a group of counters, with one bucket for each
1315 // enumeration value. We're only interested in the values of the counters. 1315 // enumeration value. We're only interested in the values of the counters.
1316 // Ignore the shape, average, and standard deviation of the histograms because 1316 // Ignore the shape, average, and standard deviation of the histograms because
1317 // they are meaningless. 1317 // they are meaningless.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « net/ftp/ftp_network_layer.cc ('k') | net/http/http_auth_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698