diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 18:43:55 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 18:43:55 +0000 |
commit | 83039bbf2f2ec0e918f7000b5212d104f60f2bb7 (patch) | |
tree | b22dbd0051b57a437a588772a874271f0d02ffdb /net/ftp | |
parent | e7456a206fe5b50aeb322ebabd6c26adc869a5fd (diff) | |
download | chromium_src-83039bbf2f2ec0e918f7000b5212d104f60f2bb7.zip chromium_src-83039bbf2f2ec0e918f7000b5212d104f60f2bb7.tar.gz chromium_src-83039bbf2f2ec0e918f7000b5212d104f60f2bb7.tar.bz2 |
Migrate net/socket/socket.h, net/socket/stream_socket.h to base::Bind().
This changes Socket::Read(), Socket::Write, and StreamSocket::Connect() to use CompletionCallback and fixes all users.
BUG=none
TEST=existing.
Review URL: http://codereview.chromium.org/8824006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp')
-rw-r--r-- | net/ftp/ftp_network_transaction.cc | 36 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction.h | 14 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction_unittest.cc | 27 | ||||
-rw-r--r-- | net/ftp/ftp_transaction.h | 12 |
4 files changed, 46 insertions, 43 deletions
diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc index f5ef45e..322764f 100644 --- a/net/ftp/ftp_network_transaction.cc +++ b/net/ftp/ftp_network_transaction.cc @@ -206,8 +206,8 @@ FtpNetworkTransaction::FtpNetworkTransaction( ClientSocketFactory* socket_factory) : command_sent_(COMMAND_NONE), ALLOW_THIS_IN_INITIALIZER_LIST( - io_callback_(this, &FtpNetworkTransaction::OnIOComplete)), - user_callback_(NULL), + io_callback_(base::Bind(&FtpNetworkTransaction::OnIOComplete, + base::Unretained(this)))), session_(session), request_(NULL), resolver_(session->host_resolver()), @@ -239,12 +239,12 @@ int FtpNetworkTransaction::Stop(int error) { } int FtpNetworkTransaction::RestartIgnoringLastError( - OldCompletionCallback* callback) { + const CompletionCallback& callback) { return ERR_NOT_IMPLEMENTED; } int FtpNetworkTransaction::Start(const FtpRequestInfo* request_info, - OldCompletionCallback* callback, + const CompletionCallback& callback, const BoundNetLog& net_log) { net_log_ = net_log; request_ = request_info; @@ -269,7 +269,7 @@ int FtpNetworkTransaction::Start(const FtpRequestInfo* request_info, } int FtpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { ResetStateForRestart(); credentials_ = credentials; @@ -283,7 +283,7 @@ int FtpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials, int FtpNetworkTransaction::Read(IOBuffer* buf, int buf_len, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { DCHECK(buf); DCHECK_GT(buf_len, 0); @@ -330,7 +330,7 @@ uint64 FtpNetworkTransaction::GetUploadProgress() const { void FtpNetworkTransaction::ResetStateForRestart() { command_sent_ = COMMAND_NONE; - user_callback_ = NULL; + user_callback_.Reset(); response_ = FtpResponseInfo(); read_ctrl_buf_ = new IOBuffer(kCtrlBufLen); ctrl_response_buffer_.reset(new FtpCtrlResponseBuffer()); @@ -347,12 +347,12 @@ void FtpNetworkTransaction::ResetStateForRestart() { void FtpNetworkTransaction::DoCallback(int rv) { DCHECK(rv != ERR_IO_PENDING); - DCHECK(user_callback_); + DCHECK(!user_callback_.is_null()); // Since Run may result in Read being called, clear callback_ up front. - OldCompletionCallback* c = user_callback_; - user_callback_ = NULL; - c->Run(rv); + CompletionCallback c = user_callback_; + user_callback_.Reset(); + c.Run(rv); } void FtpNetworkTransaction::OnIOComplete(int result) { @@ -645,7 +645,7 @@ int FtpNetworkTransaction::DoCtrlConnect() { next_state_ = STATE_CTRL_CONNECT_COMPLETE; ctrl_socket_.reset(socket_factory_->CreateTransportClientSocket( addresses_, net_log_.net_log(), net_log_.source())); - return ctrl_socket_->Connect(&io_callback_); + return ctrl_socket_->Connect(io_callback_); } int FtpNetworkTransaction::DoCtrlConnectComplete(int result) { @@ -663,10 +663,7 @@ int FtpNetworkTransaction::DoCtrlConnectComplete(int result) { int FtpNetworkTransaction::DoCtrlRead() { next_state_ = STATE_CTRL_READ_COMPLETE; - return ctrl_socket_->Read( - read_ctrl_buf_, - kCtrlBufLen, - &io_callback_); + return ctrl_socket_->Read(read_ctrl_buf_, kCtrlBufLen, io_callback_); } int FtpNetworkTransaction::DoCtrlReadComplete(int result) { @@ -699,7 +696,7 @@ int FtpNetworkTransaction::DoCtrlWrite() { return ctrl_socket_->Write(write_buf_, write_buf_->BytesRemaining(), - &io_callback_); + io_callback_); } int FtpNetworkTransaction::DoCtrlWriteComplete(int result) { @@ -1200,7 +1197,7 @@ int FtpNetworkTransaction::DoDataConnect() { data_address.SetPort(data_connection_port_); data_socket_.reset(socket_factory_->CreateTransportClientSocket( data_address, net_log_.net_log(), net_log_.source())); - return data_socket_->Connect(&io_callback_); + return data_socket_->Connect(io_callback_); } int FtpNetworkTransaction::DoDataConnectComplete(int result) { @@ -1247,8 +1244,7 @@ int FtpNetworkTransaction::DoDataRead() { next_state_ = STATE_DATA_READ_COMPLETE; read_data_buf_->data()[0] = 0; - return data_socket_->Read(read_data_buf_, read_data_buf_len_, - &io_callback_); + return data_socket_->Read(read_data_buf_, read_data_buf_len_, io_callback_); } int FtpNetworkTransaction::DoDataReadComplete(int result) { diff --git a/net/ftp/ftp_network_transaction.h b/net/ftp/ftp_network_transaction.h index 7d32d55..3fec79d 100644 --- a/net/ftp/ftp_network_transaction.h +++ b/net/ftp/ftp_network_transaction.h @@ -34,16 +34,16 @@ class NET_EXPORT_PRIVATE FtpNetworkTransaction : public FtpTransaction { virtual ~FtpNetworkTransaction(); virtual int Stop(int error); - virtual int RestartIgnoringLastError(OldCompletionCallback* callback); + virtual int RestartIgnoringLastError(const CompletionCallback& callback); // FtpTransaction methods: virtual int Start(const FtpRequestInfo* request_info, - OldCompletionCallback* callback, + const CompletionCallback& callback, const BoundNetLog& net_log) OVERRIDE; virtual int RestartWithAuth(const AuthCredentials& credentials, - OldCompletionCallback* callback) OVERRIDE; - virtual int Read(IOBuffer* buf, int buf_len, OldCompletionCallback* callback) - OVERRIDE; + const CompletionCallback& callback) OVERRIDE; + virtual int Read(IOBuffer* buf, int buf_len, + const CompletionCallback& callback) OVERRIDE; virtual const FtpResponseInfo* GetResponseInfo() const OVERRIDE; virtual LoadState GetLoadState() const OVERRIDE; virtual uint64 GetUploadProgress() const OVERRIDE; @@ -189,8 +189,8 @@ class NET_EXPORT_PRIVATE FtpNetworkTransaction : public FtpTransaction { Command command_sent_; - OldCompletionCallbackImpl<FtpNetworkTransaction> io_callback_; - OldCompletionCallback* user_callback_; + CompletionCallback io_callback_; + CompletionCallback user_callback_; scoped_refptr<FtpNetworkSession> session_; diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc index 5d686e0..08be329 100644 --- a/net/ftp/ftp_network_transaction_unittest.cc +++ b/net/ftp/ftp_network_transaction_unittest.cc @@ -782,20 +782,23 @@ class FtpNetworkTransactionTest : public PlatformTest { FtpRequestInfo request_info = GetRequestInfo(request); EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); ASSERT_EQ(ERR_IO_PENDING, - transaction_.Start(&request_info, &callback_, BoundNetLog())); + transaction_.Start(&request_info, callback_.callback(), + BoundNetLog())); EXPECT_NE(LOAD_STATE_IDLE, transaction_.GetLoadState()); ASSERT_EQ(expected_result, callback_.WaitForResult()); if (expected_result == OK) { scoped_refptr<IOBuffer> io_buffer(new IOBuffer(kBufferSize)); memset(io_buffer->data(), 0, kBufferSize); ASSERT_EQ(ERR_IO_PENDING, - transaction_.Read(io_buffer.get(), kBufferSize, &callback_)); + transaction_.Read(io_buffer.get(), kBufferSize, + callback_.callback())); ASSERT_EQ(static_cast<int>(mock_data.length()), callback_.WaitForResult()); EXPECT_EQ(mock_data, std::string(io_buffer->data(), mock_data.length())); // Do another Read to detect that the data socket is now closed. - int rv = transaction_.Read(io_buffer.get(), kBufferSize, &callback_); + int rv = transaction_.Read(io_buffer.get(), kBufferSize, + callback_.callback()); if (rv == ERR_IO_PENDING) { EXPECT_EQ(0, callback_.WaitForResult()); } else { @@ -820,7 +823,7 @@ class FtpNetworkTransactionTest : public PlatformTest { scoped_refptr<FtpNetworkSession> session_; MockClientSocketFactory mock_socket_factory_; FtpNetworkTransaction transaction_; - TestOldCompletionCallback callback_; + TestCompletionCallback callback_; }; TEST_F(FtpNetworkTransactionTest, FailedLookup) { @@ -828,7 +831,8 @@ TEST_F(FtpNetworkTransactionTest, FailedLookup) { host_resolver_->rules()->AddSimulatedFailure("badhost"); EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); ASSERT_EQ(ERR_IO_PENDING, - transaction_.Start(&request_info, &callback_, BoundNetLog())); + transaction_.Start(&request_info, callback_.callback(), + BoundNetLog())); ASSERT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState()); } @@ -1051,7 +1055,8 @@ TEST_F(FtpNetworkTransactionTest, DownloadTransactionEvilPasvUnsafeHost) { // Start the transaction. ASSERT_EQ(ERR_IO_PENDING, - transaction_.Start(&request_info, &callback_, BoundNetLog())); + transaction_.Start(&request_info, callback_.callback(), + BoundNetLog())); ASSERT_EQ(OK, callback_.WaitForResult()); // The transaction fires the callback when we can start reading data. That @@ -1175,7 +1180,8 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartUser) { FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); ASSERT_EQ(ERR_IO_PENDING, - transaction_.Start(&request_info, &callback_, BoundNetLog())); + transaction_.Start(&request_info, callback_.callback(), + BoundNetLog())); ASSERT_EQ(ERR_FTP_FAILED, callback_.WaitForResult()); MockRead ctrl_reads[] = { @@ -1194,7 +1200,7 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartUser) { AuthCredentials( ASCIIToUTF16("foo\nownz0red"), ASCIIToUTF16("innocent")), - &callback_)); + callback_.callback())); EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); } @@ -1208,7 +1214,8 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) { FtpRequestInfo request_info = GetRequestInfo("ftp://host/file"); ASSERT_EQ(ERR_IO_PENDING, - transaction_.Start(&request_info, &callback_, BoundNetLog())); + transaction_.Start(&request_info, callback_.callback(), + BoundNetLog())); ASSERT_EQ(ERR_FTP_FAILED, callback_.WaitForResult()); MockRead ctrl_reads[] = { @@ -1228,7 +1235,7 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) { transaction_.RestartWithAuth( AuthCredentials(ASCIIToUTF16("innocent"), ASCIIToUTF16("foo\nownz0red")), - &callback_)); + callback_.callback())); EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); } diff --git a/net/ftp/ftp_transaction.h b/net/ftp/ftp_transaction.h index 269c8bb..4fec784 100644 --- a/net/ftp/ftp_transaction.h +++ b/net/ftp/ftp_transaction.h @@ -29,7 +29,7 @@ class NET_EXPORT_PRIVATE FtpTransaction { // Returns OK if the transaction could be started synchronously, which means // that the request was served from the cache (only supported for directory // listings). ERR_IO_PENDING is returned to indicate that the - // OldCompletionCallback will be notified once response info is available or if + // CompletionCallback will be notified once response info is available or if // an IO error occurs. Any other return value indicates that the transaction // could not be started. // @@ -40,21 +40,21 @@ class NET_EXPORT_PRIVATE FtpTransaction { // // Profiling information for the request is saved to |net_log| if non-NULL. virtual int Start(const FtpRequestInfo* request_info, - OldCompletionCallback* callback, + const CompletionCallback& callback, const BoundNetLog& net_log) = 0; // Restarts the FTP transaction with authentication credentials. virtual int RestartWithAuth(const AuthCredentials& credentials, - OldCompletionCallback* callback) = 0; + const CompletionCallback& callback) = 0; // Once response info is available for the transaction, response data may be // read by calling this method. // // Response data is copied into the given buffer and the number of bytes // copied is returned. ERR_IO_PENDING is returned if response data is not - // yet available. The OldCompletionCallback is notified when the data copy + // yet available. The CompletionCallback is notified when the data copy // completes, and it is passed the number of bytes that were successfully - // copied. Or, if a read error occurs, the OldCompletionCallback is notified of + // copied. Or, if a read error occurs, the CompletionCallback is notified of // the error. Any other negative return value indicates that the transaction // could not be read. // @@ -62,7 +62,7 @@ class NET_EXPORT_PRIVATE FtpTransaction { // virtual int Read(IOBuffer* buf, int buf_len, - OldCompletionCallback* callback) = 0; + const CompletionCallback& callback) = 0; // Returns the response info for this transaction or NULL if the response // info is not available. |