summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-21 21:21:13 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-21 21:21:13 +0000
commit6ea7b15b65fdfab0875475b8c33e38dd1ed98889 (patch)
tree6330991da0acf534ce1e0dbbaabd4bc2f3a0ef48 /net
parentb08ff47c9265ae172091ed75a14a73696fb5c2dc (diff)
downloadchromium_src-6ea7b15b65fdfab0875475b8c33e38dd1ed98889.zip
chromium_src-6ea7b15b65fdfab0875475b8c33e38dd1ed98889.tar.gz
chromium_src-6ea7b15b65fdfab0875475b8c33e38dd1ed98889.tar.bz2
base::Bind: Finish converting net/socket.
BUG=none TEST=none R=groby Review URL: http://codereview.chromium.org/9008004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115405 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/socket/client_socket_pool.h2
-rw-r--r--net/socket/client_socket_pool_base_unittest.cc55
-rw-r--r--net/socket/ssl_server_socket.h2
-rw-r--r--net/socket/ssl_server_socket_nss.cc13
-rw-r--r--net/socket/ssl_server_socket_nss.h4
-rw-r--r--net/socket/ssl_server_socket_unittest.cc13
-rw-r--r--net/socket/web_socket_server_socket.cc31
-rw-r--r--net/socket/web_socket_server_socket.h2
-rw-r--r--net/socket/web_socket_server_socket_unittest.cc23
9 files changed, 69 insertions, 76 deletions
diff --git a/net/socket/client_socket_pool.h b/net/socket/client_socket_pool.h
index c8e84d0..8c0c97f 100644
--- a/net/socket/client_socket_pool.h
+++ b/net/socket/client_socket_pool.h
@@ -98,7 +98,7 @@ class NET_EXPORT ClientSocketPool {
// Called to cancel a RequestSocket call that returned ERR_IO_PENDING. The
// same handle parameter must be passed to this method as was passed to the
- // RequestSocket call being cancelled. The associated OldCompletionCallback is
+ // RequestSocket call being cancelled. The associated CompletionCallback is
// not run. However, for performance, we will let one ConnectJob complete
// and go idle.
virtual void CancelRequest(const std::string& group_name,
diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc
index be1fdcd..9a25172 100644
--- a/net/socket/client_socket_pool_base_unittest.cc
+++ b/net/socket/client_socket_pool_base_unittest.cc
@@ -10,6 +10,7 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/stringprintf.h"
#include "base/string_number_conversions.h"
@@ -202,7 +203,7 @@ class TestConnectJob : public ConnectJob {
BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)),
job_type_(job_type),
client_socket_factory_(client_socket_factory),
- method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
load_state_(LOAD_STATE_IDLE),
store_additional_error_state_(false) {}
@@ -253,22 +254,22 @@ class TestConnectJob : public ConnectJob {
// time functions, so this change would be rather invasive.
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &TestConnectJob::DoConnect,
- true /* successful */,
- true /* async */,
- false /* recoverable */),
+ base::Bind(base::IgnoreResult(&TestConnectJob::DoConnect),
+ weak_factory_.GetWeakPtr(),
+ true /* successful */,
+ true /* async */,
+ false /* recoverable */),
kPendingConnectDelay);
return ERR_IO_PENDING;
case kMockPendingFailingJob:
set_load_state(LOAD_STATE_CONNECTING);
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &TestConnectJob::DoConnect,
- false /* error */,
- true /* async */,
- false /* recoverable */),
+ base::Bind(base::IgnoreResult(&TestConnectJob::DoConnect),
+ weak_factory_.GetWeakPtr(),
+ false /* error */,
+ true /* async */,
+ false /* recoverable */),
2);
return ERR_IO_PENDING;
case kMockWaitingJob:
@@ -277,9 +278,8 @@ class TestConnectJob : public ConnectJob {
return ERR_IO_PENDING;
case kMockAdvancingLoadStateJob:
MessageLoop::current()->PostTask(
- FROM_HERE,
- method_factory_.NewRunnableMethod(
- &TestConnectJob::AdvanceLoadState, load_state_));
+ FROM_HERE, base::Bind(&TestConnectJob::AdvanceLoadState,
+ weak_factory_.GetWeakPtr(), load_state_));
return ERR_IO_PENDING;
case kMockRecoverableJob:
return DoConnect(false /* error */, false /* sync */,
@@ -288,11 +288,11 @@ class TestConnectJob : public ConnectJob {
set_load_state(LOAD_STATE_CONNECTING);
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &TestConnectJob::DoConnect,
- false /* error */,
- true /* async */,
- true /* recoverable */),
+ base::Bind(base::IgnoreResult(&TestConnectJob::DoConnect),
+ weak_factory_.GetWeakPtr(),
+ false /* error */,
+ true /* async */,
+ true /* recoverable */),
2);
return ERR_IO_PENDING;
case kMockAdditionalErrorStateJob:
@@ -304,11 +304,11 @@ class TestConnectJob : public ConnectJob {
store_additional_error_state_ = true;
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- method_factory_.NewRunnableMethod(
- &TestConnectJob::DoConnect,
- false /* error */,
- true /* async */,
- false /* recoverable */),
+ base::Bind(base::IgnoreResult(&TestConnectJob::DoConnect),
+ weak_factory_.GetWeakPtr(),
+ false /* error */,
+ true /* async */,
+ false /* recoverable */),
2);
return ERR_IO_PENDING;
default:
@@ -347,16 +347,15 @@ class TestConnectJob : public ConnectJob {
state = static_cast<LoadState>(tmp);
set_load_state(state);
MessageLoop::current()->PostTask(
- FROM_HERE,
- method_factory_.NewRunnableMethod(&TestConnectJob::AdvanceLoadState,
- state));
+ FROM_HERE, base::Bind(&TestConnectJob::AdvanceLoadState,
+ weak_factory_.GetWeakPtr(), state));
}
}
bool waiting_success_;
const JobType job_type_;
MockClientSocketFactory* const client_socket_factory_;
- ScopedRunnableMethodFactory<TestConnectJob> method_factory_;
+ base::WeakPtrFactory<TestConnectJob> weak_factory_;
LoadState load_state_;
bool store_additional_error_state_;
diff --git a/net/socket/ssl_server_socket.h b/net/socket/ssl_server_socket.h
index 3a90c7a..5737974 100644
--- a/net/socket/ssl_server_socket.h
+++ b/net/socket/ssl_server_socket.h
@@ -28,7 +28,7 @@ class SSLServerSocket : public SSLSocket {
// if the process completes asynchronously. If Disconnect is called before
// completion then the callback will be silently, as for other StreamSocket
// calls.
- virtual int Handshake(OldCompletionCallback* callback) = 0;
+ virtual int Handshake(const CompletionCallback& callback) = 0;
};
// Creates an SSL server socket over an already-connected transport socket.
diff --git a/net/socket/ssl_server_socket_nss.cc b/net/socket/ssl_server_socket_nss.cc
index 9135464..0ff6559 100644
--- a/net/socket/ssl_server_socket_nss.cc
+++ b/net/socket/ssl_server_socket_nss.cc
@@ -60,7 +60,6 @@ SSLServerSocketNSS::SSLServerSocketNSS(
const SSLConfig& ssl_config)
: transport_send_busy_(false),
transport_recv_busy_(false),
- user_handshake_callback_(NULL),
nss_fd_(NULL),
nss_bufs_(NULL),
transport_socket_(transport_socket),
@@ -86,7 +85,7 @@ SSLServerSocketNSS::~SSLServerSocketNSS() {
}
}
-int SSLServerSocketNSS::Handshake(OldCompletionCallback* callback) {
+int SSLServerSocketNSS::Handshake(const CompletionCallback& callback) {
net_log_.BeginEvent(NetLog::TYPE_SSL_SERVER_HANDSHAKE, NULL);
int rv = Init();
@@ -145,7 +144,7 @@ int SSLServerSocketNSS::Connect(const CompletionCallback& callback) {
int SSLServerSocketNSS::Read(IOBuffer* buf, int buf_len,
const CompletionCallback& callback) {
DCHECK(user_read_callback_.is_null());
- DCHECK(!user_handshake_callback_);
+ DCHECK(user_handshake_callback_.is_null());
DCHECK(!user_read_buf_);
DCHECK(nss_bufs_);
@@ -466,7 +465,7 @@ void SSLServerSocketNSS::OnHandshakeIOComplete(int result) {
if (rv != ERR_IO_PENDING) {
net_log_.EndEventWithNetErrorCode(net::NetLog::TYPE_SSL_SERVER_HANDSHAKE,
rv);
- if (user_handshake_callback_)
+ if (!user_handshake_callback_.is_null())
DoHandshakeCallback(rv);
}
}
@@ -705,9 +704,9 @@ int SSLServerSocketNSS::DoHandshake() {
void SSLServerSocketNSS::DoHandshakeCallback(int rv) {
DCHECK_NE(rv, ERR_IO_PENDING);
- OldCompletionCallback* c = user_handshake_callback_;
- user_handshake_callback_ = NULL;
- c->Run(rv > OK ? OK : rv);
+ CompletionCallback c = user_handshake_callback_;
+ user_handshake_callback_.Reset();
+ c.Run(rv > OK ? OK : rv);
}
void SSLServerSocketNSS::DoReadCallback(int rv) {
diff --git a/net/socket/ssl_server_socket_nss.h b/net/socket/ssl_server_socket_nss.h
index 1d716a1..626d136 100644
--- a/net/socket/ssl_server_socket_nss.h
+++ b/net/socket/ssl_server_socket_nss.h
@@ -32,7 +32,7 @@ class SSLServerSocketNSS : public SSLServerSocket {
virtual ~SSLServerSocketNSS();
// SSLServerSocket interface.
- virtual int Handshake(OldCompletionCallback* callback) OVERRIDE;
+ virtual int Handshake(const CompletionCallback& callback) OVERRIDE;
virtual int ExportKeyingMaterial(const base::StringPiece& label,
const base::StringPiece& context,
unsigned char *out,
@@ -105,7 +105,7 @@ class SSLServerSocketNSS : public SSLServerSocket {
BoundNetLog net_log_;
- OldCompletionCallback* user_handshake_callback_;
+ CompletionCallback user_handshake_callback_;
CompletionCallback user_read_callback_;
CompletionCallback user_write_callback_;
diff --git a/net/socket/ssl_server_socket_unittest.cc b/net/socket/ssl_server_socket_unittest.cc
index f5034c2..86f444c 100644
--- a/net/socket/ssl_server_socket_unittest.cc
+++ b/net/socket/ssl_server_socket_unittest.cc
@@ -29,6 +29,7 @@
#include "net/base/address_list.h"
#include "net/base/cert_status_flags.h"
#include "net/base/cert_verifier.h"
+#include "net/base/completion_callback.h"
#include "net/base/host_port_pair.h"
#include "net/base/io_buffer.h"
#include "net/base/ip_endpoint.h"
@@ -326,9 +327,9 @@ TEST_F(SSLServerSocketTest, Handshake) {
Initialize();
TestCompletionCallback connect_callback;
- TestOldCompletionCallback handshake_callback;
+ TestCompletionCallback handshake_callback;
- int server_ret = server_socket_->Handshake(&handshake_callback);
+ int server_ret = server_socket_->Handshake(handshake_callback.callback());
EXPECT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING);
int client_ret = client_socket_->Connect(connect_callback.callback());
@@ -351,13 +352,13 @@ TEST_F(SSLServerSocketTest, DataTransfer) {
Initialize();
TestCompletionCallback connect_callback;
- TestOldCompletionCallback handshake_callback;
+ TestCompletionCallback handshake_callback;
// Establish connection.
int client_ret = client_socket_->Connect(connect_callback.callback());
ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING);
- int server_ret = server_socket_->Handshake(&handshake_callback);
+ int server_ret = server_socket_->Handshake(handshake_callback.callback());
ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING);
client_ret = connect_callback.GetResult(client_ret);
@@ -435,12 +436,12 @@ TEST_F(SSLServerSocketTest, ExportKeyingMaterial) {
Initialize();
TestCompletionCallback connect_callback;
- TestOldCompletionCallback handshake_callback;
+ TestCompletionCallback handshake_callback;
int client_ret = client_socket_->Connect(connect_callback.callback());
ASSERT_TRUE(client_ret == net::OK || client_ret == net::ERR_IO_PENDING);
- int server_ret = server_socket_->Handshake(&handshake_callback);
+ int server_ret = server_socket_->Handshake(handshake_callback.callback());
ASSERT_TRUE(server_ret == net::OK || server_ret == net::ERR_IO_PENDING);
if (client_ret == net::ERR_IO_PENDING) {
diff --git a/net/socket/web_socket_server_socket.cc b/net/socket/web_socket_server_socket.cc
index 899bb3e..e299bbc 100644
--- a/net/socket/web_socket_server_socket.cc
+++ b/net/socket/web_socket_server_socket.cc
@@ -17,13 +17,15 @@
#endif
#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/md5.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/string_util.h"
-#include "base/task.h"
#include "googleurl/src/gurl.h"
#include "net/base/completion_callback.h"
#include "net/base/io_buffer.h"
@@ -120,7 +122,7 @@ class WebSocketServerSocketImpl : public net::WebSocketServerSocket {
handshake_buf_, kHandshakeLimitBytes)),
is_transport_read_pending_(false),
is_transport_write_pending_(false),
- method_factory_(this) {
+ weak_factory_(this) {
DCHECK(transport_socket);
DCHECK(delegate);
}
@@ -315,17 +317,12 @@ class WebSocketServerSocketImpl : public net::WebSocketServerSocket {
}
// WebSocketServerSocket implementation.
- virtual int Accept(net::OldCompletionCallback* callback) {
+ virtual int Accept(const net::CompletionCallback& callback) OVERRIDE {
if (phase_ != PHASE_NYMPH)
return net::ERR_UNEXPECTED;
phase_ = PHASE_HANDSHAKE;
- net::CompletionCallback cb;
- if (callback) {
- cb = base::Bind(&net::OldCompletionCallbackAdapter, callback);
- }
pending_reqs_.push_front(PendingReq(
- PendingReq::TYPE_READ_METADATA, fill_handshake_buf_.get(),
- cb));
+ PendingReq::TYPE_READ_METADATA, fill_handshake_buf_.get(), callback));
ConsiderTransportRead();
return net::ERR_IO_PENDING;
}
@@ -360,9 +357,9 @@ class WebSocketServerSocketImpl : public net::WebSocketServerSocket {
// PostTask rather than direct call in order to:
// (1) guarantee calling callback after returning from Read();
// (2) avoid potential stack overflow;
- MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &WebSocketServerSocketImpl::OnRead, rv));
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&WebSocketServerSocketImpl::OnRead,
+ weak_factory_.GetWeakPtr(), rv));
}
}
@@ -388,9 +385,9 @@ class WebSocketServerSocketImpl : public net::WebSocketServerSocket {
// PostTask rather than direct call in order to:
// (1) guarantee calling callback after returning from Read();
// (2) avoid potential stack overflow;
- MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &WebSocketServerSocketImpl::OnWrite, rv));
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&WebSocketServerSocketImpl::OnWrite,
+ weak_factory_.GetWeakPtr(), rv));
}
}
@@ -877,14 +874,14 @@ class WebSocketServerSocketImpl : public net::WebSocketServerSocket {
scoped_refptr<net::DrainableIOBuffer> fill_handshake_buf_;
scoped_refptr<net::DrainableIOBuffer> process_handshake_buf_;
- // Pending io requests we need to complete.
+ // Pending IO requests we need to complete.
std::deque<PendingReq> pending_reqs_;
// Whether transport requests are pending.
bool is_transport_read_pending_;
bool is_transport_write_pending_;
- ScopedRunnableMethodFactory<WebSocketServerSocketImpl> method_factory_;
+ base::WeakPtrFactory<WebSocketServerSocketImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(WebSocketServerSocketImpl);
};
diff --git a/net/socket/web_socket_server_socket.h b/net/socket/web_socket_server_socket.h
index 2415575..036e516 100644
--- a/net/socket/web_socket_server_socket.h
+++ b/net/socket/web_socket_server_socket.h
@@ -50,7 +50,7 @@ class WebSocketServerSocket : public Socket {
// Returns either ERR_IO_PENDING, in which case the given callback will be
// called in the future with the real result, or it completes synchronously,
// returning the result immediately.
- virtual int Accept(OldCompletionCallback* callback) = 0;
+ virtual int Accept(const CompletionCallback& callback) = 0;
};
// Creates websocket server socket atop of already connected socket. This
diff --git a/net/socket/web_socket_server_socket_unittest.cc b/net/socket/web_socket_server_socket_unittest.cc
index d64cf19..ef02a0d 100644
--- a/net/socket/web_socket_server_socket_unittest.cc
+++ b/net/socket/web_socket_server_socket_unittest.cc
@@ -7,7 +7,8 @@
#include <stdlib.h>
#include <algorithm>
-#include "base/callback_old.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
#include "base/string_util.h"
@@ -221,8 +222,6 @@ class ReadWriteTracker {
net::WebSocketServerSocket* ws, int bytes_to_read, int bytes_to_write)
: ws_(ws),
buf_size_(1 << 14),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- accept_callback_(this, &ReadWriteTracker::OnAccept)),
read_buf_(new net::IOBuffer(buf_size_)),
write_buf_(new net::IOBuffer(buf_size_)),
bytes_remaining_to_read_(bytes_to_read),
@@ -230,7 +229,8 @@ class ReadWriteTracker {
read_initiated_(false),
write_initiated_(false),
got_final_zero_(false) {
- int rv = ws_->Accept(&accept_callback_);
+ int rv = ws_->Accept(
+ base::Bind(&ReadWriteTracker::OnAccept, base::Unretained(this)));
if (rv != net::ERR_IO_PENDING)
OnAccept(rv);
}
@@ -306,7 +306,6 @@ class ReadWriteTracker {
private:
net::WebSocketServerSocket* const ws_;
int const buf_size_;
- net::OldCompletionCallbackImpl<ReadWriteTracker> accept_callback_;
scoped_refptr<net::IOBuffer> read_buf_;
scoped_refptr<net::IOBuffer> write_buf_;
int bytes_remaining_to_read_;
@@ -327,10 +326,6 @@ class WebSocketServerSocketTest : public testing::Test {
virtual void SetUp() {
count_ = 0;
- accept_callback_[0].reset(NewCallback<WebSocketServerSocketTest, int>(
- this, &WebSocketServerSocketTest::OnAccept0));
- accept_callback_[1].reset(NewCallback<WebSocketServerSocketTest, int>(
- this, &WebSocketServerSocketTest::OnAccept1));
}
virtual void TearDown() {
@@ -350,7 +345,6 @@ class WebSocketServerSocketTest : public testing::Test {
}
int count_;
- scoped_ptr<net::OldCompletionCallback> accept_callback_[2];
};
TEST_F(WebSocketServerSocketTest, Handshake) {
@@ -385,7 +379,8 @@ TEST_F(WebSocketServerSocketTest, Handshake) {
ASSERT_TRUE(ws != NULL);
kill_list.push_back(ws);
- int rv = ws->Accept(accept_callback_[0].get());
+ int rv = ws->Accept(base::Bind(&WebSocketServerSocketTest::OnAccept0,
+ base::Unretained(this)));
if (rv != ERR_IO_PENDING)
OnAccept0(rv);
}
@@ -440,7 +435,8 @@ TEST_F(WebSocketServerSocketTest, BadCred) {
ASSERT_TRUE(ws != NULL);
kill_list.push_back(ws);
- int rv = ws->Accept(accept_callback_[1].get());
+ int rv = ws->Accept(base::Bind(&WebSocketServerSocketTest::OnAccept1,
+ base::Unretained(this)));
if (rv != ERR_IO_PENDING)
OnAccept1(rv);
}
@@ -497,7 +493,8 @@ TEST_F(WebSocketServerSocketTest, ReorderedHandshake) {
ASSERT_TRUE(ws != NULL);
kill_list.push_back(ws);
- int rv = ws->Accept(accept_callback_[0].get());
+ int rv = ws->Accept(base::Bind(&WebSocketServerSocketTest::OnAccept0,
+ base::Unretained(this)));
if (rv != ERR_IO_PENDING)
OnAccept0(rv);
}