summaryrefslogtreecommitdiffstats
path: root/net/socket
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 21:19:24 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 21:19:24 +0000
commita937a06d92a426395c006ef8437e57db6be928be (patch)
treec5f547a7c513e6e125a34ef069f3653b2f3a696e /net/socket
parent8c89e779666552bdfc748989f9870b6c7cf94cfd (diff)
downloadchromium_src-a937a06d92a426395c006ef8437e57db6be928be.zip
chromium_src-a937a06d92a426395c006ef8437e57db6be928be.tar.gz
chromium_src-a937a06d92a426395c006ef8437e57db6be928be.tar.bz2
Make ClientSocketHandle::Init() typesafe.
Introduce a REGISTER_SOCKET_PARAMS_FOR_POOL macro to register valid SocketParams for a ClientSocketPool subtype. Update HttpNetworkSession's ClientSocketPool to return the concrete TCPClientSocketPool instead of the parent interface. Renamed the member variable&accessor. Updated tests. BUG=http://crbug.com/13289 Review URL: http://codereview.chromium.org/173018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket')
-rw-r--r--net/socket/client_socket_handle.h6
-rw-r--r--net/socket/client_socket_pool.h16
-rw-r--r--net/socket/client_socket_pool_base_unittest.cc191
-rw-r--r--net/socket/socket_test_util.h11
-rw-r--r--net/socket/tcp_client_socket_pool.h8
-rw-r--r--net/socket/tcp_client_socket_pool_unittest.cc7
6 files changed, 137 insertions, 102 deletions
diff --git a/net/socket/client_socket_handle.h b/net/socket/client_socket_handle.h
index c58e832..ce0a001 100644
--- a/net/socket/client_socket_handle.h
+++ b/net/socket/client_socket_handle.h
@@ -130,8 +130,6 @@ class ClientSocketHandle {
};
// Template function implementation:
-// TODO(willchan): Register valid (SocketParams,PoolType) pairs to provide
-// type safety.
template <typename SocketParams, typename PoolType>
int ClientSocketHandle::Init(const std::string& group_name,
const SocketParams& socket_params,
@@ -140,6 +138,10 @@ int ClientSocketHandle::Init(const std::string& group_name,
PoolType* pool,
LoadLog* load_log) {
CHECK(!group_name.empty());
+ // Note that this will result in a link error if the SocketParams has not been
+ // registered for the PoolType via REGISTER_SOCKET_PARAMS_FOR_POOL (defined in
+ // client_socket_pool.h).
+ CheckIsValidSocketParamsForPool<PoolType, SocketParams>();
ResetInternal(true);
pool_ = pool;
group_name_ = group_name;
diff --git a/net/socket/client_socket_pool.h b/net/socket/client_socket_pool.h
index ffb34b7..2c55e91 100644
--- a/net/socket/client_socket_pool.h
+++ b/net/socket/client_socket_pool.h
@@ -91,6 +91,22 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> {
DISALLOW_COPY_AND_ASSIGN(ClientSocketPool);
};
+// Declaration, but no definition. ClientSocketPool subclasses should indicate
+// valid SocketParams via the REGISTER_SOCKET_PARAMS_FOR_POOL macro below, which
+// will provide a definition of CheckIsValidSocketParamsForPool for the
+// ClientSocketPool subtype and SocketParams pair. Trying to use a SocketParams
+// type that has not been registered with the corresponding ClientSocketPool
+// subtype will result in a link time error stating that
+// CheckIsValidSocketParamsForPool with those template parameters is undefined.
+template <typename PoolType, typename SocketParams>
+void CheckIsValidSocketParamsForPool();
+
+// Provides an empty definition for CheckIsValidSocketParamsForPool() which
+// should be optimized out by the compiler.
+#define REGISTER_SOCKET_PARAMS_FOR_POOL(pool_type, socket_params) \
+template<> \
+inline void CheckIsValidSocketParamsForPool<pool_type, socket_params>() {}
+
} // namespace net
#endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_
diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc
index 840ca36..93673c62 100644
--- a/net/socket/client_socket_pool_base_unittest.cc
+++ b/net/socket/client_socket_pool_base_unittest.cc
@@ -297,6 +297,12 @@ class TestClientSocketPool : public ClientSocketPool {
DISALLOW_COPY_AND_ASSIGN(TestClientSocketPool);
};
+} // namespace
+
+REGISTER_SOCKET_PARAMS_FOR_POOL(TestClientSocketPool, const void*);
+
+namespace {
+
void MockClientSocketFactory::SignalJobs() {
for (std::vector<TestConnectJob*>::iterator it = waiting_jobs_.begin();
it != waiting_jobs_.end(); ++it) {
@@ -355,7 +361,8 @@ class ClientSocketPoolBaseTest : public ClientSocketPoolTest {
}
int StartRequest(const std::string& group_name, int priority) {
- return StartRequestUsingPool(pool_.get(), group_name, priority);
+ return StartRequestUsingPool<TestClientSocketPool, const void*>(
+ pool_.get(), group_name, priority, NULL);
}
virtual void TearDown() {
@@ -376,6 +383,18 @@ class ClientSocketPoolBaseTest : public ClientSocketPoolTest {
scoped_refptr<TestClientSocketPool> pool_;
};
+// Helper function which explicitly specifies the template parameters, since
+// the compiler will infer (in this case, incorrectly) that NULL is of type int.
+int InitHandle(ClientSocketHandle* handle,
+ const std::string& group_name,
+ int priority,
+ CompletionCallback* callback,
+ TestClientSocketPool* pool,
+ LoadLog* load_log) {
+ return handle->Init<const void*, TestClientSocketPool>(
+ group_name, NULL, priority, callback, pool, load_log);
+}
+
// Even though a timeout is specified, it doesn't time out on a synchronous
// completion.
TEST_F(ClientSocketPoolBaseTest, ConnectJob_NoTimeoutOnSynchronousCompletion) {
@@ -416,8 +435,8 @@ TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) {
TestCompletionCallback callback;
ClientSocketHandle handle;
- EXPECT_EQ(OK, handle.Init("a", ignored_request_info_, kDefaultPriority,
- &callback, pool_.get(), NULL));
+ EXPECT_EQ(OK, InitHandle(&handle, "a", kDefaultPriority,
+ &callback, pool_.get(), NULL));
EXPECT_TRUE(handle.is_initialized());
EXPECT_TRUE(handle.socket());
handle.Reset();
@@ -428,8 +447,7 @@ TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
TestSocketRequest req(&request_order_, &completion_count_);
- int rv = req.handle()->Init(
- "a", ignored_request_info_, 0, &req, pool_.get(), NULL);
+ int rv = InitHandle(req.handle(), "a", 0, &req, pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle()));
EXPECT_EQ(OK, req.WaitForResult());
@@ -444,8 +462,8 @@ TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) {
connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob);
TestSocketRequest req(&request_order_, &completion_count_);
EXPECT_EQ(ERR_CONNECTION_FAILED,
- req.handle()->Init("a", ignored_request_info_,
- kDefaultPriority, &req, pool_.get(), NULL));
+ InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL));
}
TEST_F(ClientSocketPoolBaseTest, InitConnectionAsynchronousFailure) {
@@ -454,8 +472,8 @@ TEST_F(ClientSocketPoolBaseTest, InitConnectionAsynchronousFailure) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob);
TestSocketRequest req(&request_order_, &completion_count_);
EXPECT_EQ(ERR_IO_PENDING,
- req.handle()->Init("a", ignored_request_info_, kDefaultPriority,
- &req, pool_.get(), NULL));
+ InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL));
EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle()));
EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult());
}
@@ -746,8 +764,8 @@ TEST_F(ClientSocketPoolBaseTest, CancelRequestClearGroup) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
TestSocketRequest req(&request_order_, &completion_count_);
EXPECT_EQ(ERR_IO_PENDING,
- req.handle()->Init("a", ignored_request_info_,
- kDefaultPriority, &req, pool_.get(), NULL));
+ InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL));
req.handle()->Reset();
}
@@ -759,11 +777,11 @@ TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) {
TestSocketRequest req2(&request_order_, &completion_count_);
EXPECT_EQ(ERR_IO_PENDING,
- req.handle()->Init("a", ignored_request_info_,
- kDefaultPriority, &req, pool_.get(), NULL));
+ InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL));
EXPECT_EQ(ERR_IO_PENDING,
- req2.handle()->Init("a", ignored_request_info_,
- kDefaultPriority, &req2, pool_.get(), NULL));
+ InitHandle(req2.handle(), "a", kDefaultPriority, &req2,
+ pool_.get(), NULL));
req.handle()->Reset();
@@ -780,15 +798,15 @@ TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) {
TestSocketRequest req(&request_order_, &completion_count_);
EXPECT_EQ(ERR_IO_PENDING,
- handle.Init("a", ignored_request_info_,
- kDefaultPriority, &callback, pool_.get(), NULL));
+ InitHandle(&handle, "a", kDefaultPriority, &callback,
+ pool_.get(), NULL));
handle.Reset();
TestCompletionCallback callback2;
EXPECT_EQ(ERR_IO_PENDING,
- handle.Init("a", ignored_request_info_,
- kDefaultPriority, &callback2, pool_.get(), NULL));
+ InitHandle(&handle, "a", kDefaultPriority, &callback2,
+ pool_.get(), NULL));
EXPECT_EQ(OK, callback2.WaitForResult());
EXPECT_FALSE(callback.have_result());
@@ -834,7 +852,7 @@ TEST_F(ClientSocketPoolBaseTest, CancelRequest) {
class RequestSocketCallback : public CallbackRunner< Tuple1<int> > {
public:
RequestSocketCallback(ClientSocketHandle* handle,
- ClientSocketPool* pool,
+ TestClientSocketPool* pool,
TestConnectJobFactory* test_connect_job_factory,
TestConnectJob::JobType next_job_type)
: handle_(handle),
@@ -851,9 +869,8 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > {
test_connect_job_factory_->set_job_type(next_job_type_);
handle_->Reset();
within_callback_ = true;
- int rv = handle_->Init(
- "a", HostResolver::RequestInfo("www.google.com", 80),
- kDefaultPriority, this, pool_.get(), NULL);
+ int rv = InitHandle(
+ handle_, "a", kDefaultPriority, this, pool_.get(), NULL);
switch (next_job_type_) {
case TestConnectJob::kMockJob:
EXPECT_EQ(OK, rv);
@@ -874,7 +891,7 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > {
private:
ClientSocketHandle* const handle_;
- const scoped_refptr<ClientSocketPool> pool_;
+ const scoped_refptr<TestClientSocketPool> pool_;
bool within_callback_;
TestConnectJobFactory* const test_connect_job_factory_;
TestConnectJob::JobType next_job_type_;
@@ -889,9 +906,8 @@ TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) {
RequestSocketCallback callback(
&handle, pool_.get(), connect_job_factory_,
TestConnectJob::kMockPendingJob);
- int rv = handle.Init(
- "a", ignored_request_info_, kDefaultPriority, &callback,
- pool_.get(), NULL);
+ int rv = InitHandle(&handle, "a", kDefaultPriority, &callback,
+ pool_.get(), NULL);
ASSERT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -905,9 +921,8 @@ TEST_F(ClientSocketPoolBaseTest, RequestPendingJobThenSynchronous) {
ClientSocketHandle handle;
RequestSocketCallback callback(
&handle, pool_.get(), connect_job_factory_, TestConnectJob::kMockJob);
- int rv = handle.Init(
- "a", ignored_request_info_, kDefaultPriority, &callback,
- pool_.get(), NULL);
+ int rv = InitHandle(&handle, "a", kDefaultPriority, &callback,
+ pool_.get(), NULL);
ASSERT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -969,15 +984,15 @@ TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
TestSocketRequest req(&request_order_, &completion_count_);
- int rv = req.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req, pool_.get(), NULL);
+ int rv = InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
// Cancel the active request.
req.handle()->Reset();
- rv = req.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req, pool_.get(), NULL);
+ rv = InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, req.WaitForResult());
@@ -997,14 +1012,14 @@ TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) {
// Start job 1 (async error).
TestSocketRequest req1(&request_order_, &completion_count_);
- int rv = req1.handle()->Init("a", ignored_request_info_,
- kDefaultPriority, &req1, pool_.get(), NULL);
+ int rv = InitHandle(req1.handle(), "a", kDefaultPriority, &req1,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
// Start job 2 (async error).
TestSocketRequest req2(&request_order_, &completion_count_);
- rv = req2.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req2, pool_.get(), NULL);
+ rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
// The pending job is sync.
@@ -1012,8 +1027,8 @@ TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) {
// Request 3 does not have a ConnectJob yet. It's just pending.
TestSocketRequest req3(&request_order_, &completion_count_);
- rv = req3.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req3, pool_.get(), NULL);
+ rv = InitHandle(
+ req3.handle(), "a", kDefaultPriority, &req3, pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(ERR_CONNECTION_FAILED, req1.WaitForResult());
@@ -1040,8 +1055,8 @@ TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
TestSocketRequest req1(&request_order_, &completion_count_);
- int rv = req1.handle()->Init("a", ignored_request_info_, kDefaultPriority,
- &req1, pool_.get(), NULL);
+ int rv = InitHandle(req1.handle(), "a", kDefaultPriority, &req1,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, req1.WaitForResult());
@@ -1049,8 +1064,8 @@ TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) {
connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
TestSocketRequest req2(&request_order_, &completion_count_);
- rv = req2.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req2, pool_.get(), NULL);
+ rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
req1.handle()->Reset();
MessageLoop::current()->RunAllPending(); // Run the DoReleaseSocket()
@@ -1059,8 +1074,8 @@ TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) {
// will use the idle socket).
TestSocketRequest req3(&request_order_, &completion_count_);
- rv = req3.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req3, pool_.get(), NULL);
+ rv = InitHandle(req3.handle(), "a", kDefaultPriority, &req3,
+ pool_.get(), NULL);
EXPECT_EQ(OK, rv);
EXPECT_FALSE(req2.handle()->socket());
@@ -1155,8 +1170,8 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicSynchronous) {
TestCompletionCallback callback;
ClientSocketHandle handle;
- EXPECT_EQ(OK, handle.Init("a", ignored_request_info_, kDefaultPriority,
- &callback, pool_.get(), NULL));
+ EXPECT_EQ(OK, InitHandle(&handle, "a", kDefaultPriority, &callback,
+ pool_.get(), NULL));
EXPECT_TRUE(handle.is_initialized());
EXPECT_TRUE(handle.socket());
handle.Reset();
@@ -1167,8 +1182,7 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicAsynchronous) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
TestSocketRequest req(&request_order_, &completion_count_);
- int rv = req.handle()->Init("a", ignored_request_info_, 0, &req,
- pool_.get(), NULL);
+ int rv = InitHandle(req.handle(), "a", 0, &req, pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle()));
EXPECT_EQ(OK, req.WaitForResult());
@@ -1183,8 +1197,8 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, InitConnectionFailure) {
connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob);
TestSocketRequest req(&request_order_, &completion_count_);
EXPECT_EQ(ERR_CONNECTION_FAILED,
- req.handle()->Init("a", ignored_request_info_,
- kDefaultPriority, &req, pool_.get(), NULL));
+ InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL));
}
TEST_F(ClientSocketPoolBaseTest_LateBinding,
@@ -1194,8 +1208,8 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding,
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob);
TestSocketRequest req(&request_order_, &completion_count_);
EXPECT_EQ(ERR_IO_PENDING,
- req.handle()->Init("a", ignored_request_info_, kDefaultPriority,
- &req, pool_.get(), NULL));
+ InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL));
EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle()));
EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult());
}
@@ -1259,8 +1273,8 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, CancelRequestClearGroup) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
TestSocketRequest req(&request_order_, &completion_count_);
EXPECT_EQ(ERR_IO_PENDING,
- req.handle()->Init("a", ignored_request_info_,
- kDefaultPriority, &req, pool_.get(), NULL));
+ InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL));
req.handle()->Reset();
}
@@ -1272,11 +1286,11 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, TwoRequestsCancelOne) {
TestSocketRequest req2(&request_order_, &completion_count_);
EXPECT_EQ(ERR_IO_PENDING,
- req.handle()->Init("a", ignored_request_info_,
- kDefaultPriority, &req, pool_.get(), NULL));
+ InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL));
EXPECT_EQ(ERR_IO_PENDING,
- req2.handle()->Init("a", ignored_request_info_,
- kDefaultPriority, &req2, pool_.get(), NULL));
+ InitHandle(req2.handle(), "a", kDefaultPriority, &req2,
+ pool_.get(), NULL));
req.handle()->Reset();
@@ -1293,15 +1307,15 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, ConnectCancelConnect) {
TestSocketRequest req(&request_order_, &completion_count_);
EXPECT_EQ(ERR_IO_PENDING,
- handle.Init("a", ignored_request_info_,
- kDefaultPriority, &callback, pool_.get(), NULL));
+ InitHandle(&handle, "a", kDefaultPriority, &callback,
+ pool_.get(), NULL));
handle.Reset();
TestCompletionCallback callback2;
EXPECT_EQ(ERR_IO_PENDING,
- handle.Init("a", ignored_request_info_,
- kDefaultPriority, &callback2, pool_.get(), NULL));
+ InitHandle(&handle, "a", kDefaultPriority, &callback2,
+ pool_.get(), NULL));
EXPECT_EQ(OK, callback2.WaitForResult());
EXPECT_FALSE(callback.have_result());
@@ -1374,9 +1388,8 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, RequestPendingJobTwice) {
RequestSocketCallback callback(
&handle, pool_.get(), connect_job_factory_,
TestConnectJob::kMockPendingJob);
- int rv = handle.Init(
- "a", ignored_request_info_, kDefaultPriority, &callback,
- pool_.get(), NULL);
+ int rv = InitHandle(
+ &handle, "a", kDefaultPriority, &callback, pool_.get(), NULL);
ASSERT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, callback.WaitForResult());
@@ -1390,8 +1403,8 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, RequestPendingJobThenSynchronous) {
ClientSocketHandle handle;
RequestSocketCallback callback(
&handle, pool_.get(), connect_job_factory_, TestConnectJob::kMockJob);
- int rv = handle.Init(
- "a", ignored_request_info_, kDefaultPriority, &callback,
+ int rv = InitHandle(
+ &handle, "a", kDefaultPriority, &callback,
pool_.get(), NULL);
ASSERT_EQ(ERR_IO_PENDING, rv);
@@ -1457,15 +1470,15 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding,
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
TestSocketRequest req(&request_order_, &completion_count_);
- int rv = req.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req, pool_.get(), NULL);
+ int rv = InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
// Cancel the active request.
req.handle()->Reset();
- rv = req.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req, pool_.get(), NULL);
+ rv = InitHandle(req.handle(), "a", kDefaultPriority, &req,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, req.WaitForResult());
@@ -1483,8 +1496,8 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, ReleaseSockets) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
TestSocketRequest req1(&request_order_, &completion_count_);
- int rv = req1.handle()->Init("a", ignored_request_info_, kDefaultPriority,
- &req1, pool_.get(), NULL);
+ int rv = InitHandle(req1.handle(), "a", kDefaultPriority,
+ &req1, pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(OK, req1.WaitForResult());
@@ -1493,12 +1506,12 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, ReleaseSockets) {
connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob);
TestSocketRequest req2(&request_order_, &completion_count_);
- rv = req2.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req2, pool_.get(), NULL);
+ rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
TestSocketRequest req3(&request_order_, &completion_count_);
- rv = req3.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req3, pool_.get(), NULL);
+ rv = InitHandle(
+ req3.handle(), "a", kDefaultPriority, &req3, pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
// Both Requests 2 and 3 are pending. We release socket 1 which should
@@ -1529,21 +1542,21 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, PendingJobCompletionOrder) {
connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob);
TestSocketRequest req1(&request_order_, &completion_count_);
- int rv = req1.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req1, pool_.get(), NULL);
+ int rv = InitHandle(
+ req1.handle(), "a", kDefaultPriority, &req1, pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
TestSocketRequest req2(&request_order_, &completion_count_);
- rv = req2.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req2, pool_.get(), NULL);
+ rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
// The pending job is sync.
connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
TestSocketRequest req3(&request_order_, &completion_count_);
- rv = req3.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req3, pool_.get(), NULL);
+ rv = InitHandle(
+ req3.handle(), "a", kDefaultPriority, &req3, pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(ERR_CONNECTION_FAILED, req1.WaitForResult());
@@ -1562,16 +1575,16 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, DISABLED_LoadState) {
TestConnectJob::kMockAdvancingLoadStateJob);
TestSocketRequest req1(&request_order_, &completion_count_);
- int rv = req1.handle()->Init("a", ignored_request_info_, kDefaultPriority,
- &req1, pool_.get(), NULL);
+ int rv = InitHandle(
+ req1.handle(), "a", kDefaultPriority, &req1, pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(LOAD_STATE_IDLE, req1.handle()->GetLoadState());
MessageLoop::current()->RunAllPending();
TestSocketRequest req2(&request_order_, &completion_count_);
- rv = req2.handle()->Init(
- "a", ignored_request_info_, kDefaultPriority, &req2, pool_.get(), NULL);
+ rv = InitHandle(req2.handle(), "a", kDefaultPriority, &req2,
+ pool_.get(), NULL);
EXPECT_EQ(ERR_IO_PENDING, rv);
EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle()->GetLoadState());
EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle()->GetLoadState());
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index 8307d44..76d4df1f 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -329,22 +329,20 @@ class ClientSocketPoolTest : public testing::Test {
static const int kIndexOutOfBounds;
static const int kRequestNotFound;
- ClientSocketPoolTest() : ignored_request_info_("ignored", 80) {
- }
-
virtual void SetUp();
virtual void TearDown();
- template <typename PoolType>
+ template <typename PoolType, typename SocketParams>
int StartRequestUsingPool(PoolType* socket_pool,
const std::string& group_name,
- int priority) {
+ int priority,
+ const SocketParams& socket_params) {
DCHECK(socket_pool);
TestSocketRequest* request = new TestSocketRequest(&request_order_,
&completion_count_);
requests_.push_back(request);
int rv = request->handle()->Init(
- group_name, ignored_request_info_, priority, request,
+ group_name, socket_params, priority, request,
socket_pool, NULL);
if (rv != ERR_IO_PENDING)
request_order_.push_back(request);
@@ -364,7 +362,6 @@ class ClientSocketPoolTest : public testing::Test {
// Releases connections until there is nothing to release.
void ReleaseAllConnections(KeepAlive keep_alive);
- HostResolver::RequestInfo ignored_request_info_;
ScopedVector<TestSocketRequest> requests_;
std::vector<TestSocketRequest*> request_order_;
size_t completion_count_;
diff --git a/net/socket/tcp_client_socket_pool.h b/net/socket/tcp_client_socket_pool.h
index 4532000..1437225 100644
--- a/net/socket/tcp_client_socket_pool.h
+++ b/net/socket/tcp_client_socket_pool.h
@@ -12,6 +12,7 @@
#include "base/scoped_ptr.h"
#include "base/time.h"
#include "base/timer.h"
+#include "net/base/host_resolver.h"
#include "net/socket/client_socket_pool_base.h"
#include "net/socket/client_socket_pool.h"
@@ -104,6 +105,9 @@ class TCPClientSocketPool : public ClientSocketPool {
virtual LoadState GetLoadState(const std::string& group_name,
const ClientSocketHandle* handle) const;
+ protected:
+ virtual ~TCPClientSocketPool();
+
private:
typedef ClientSocketPoolBase<HostResolver::RequestInfo> PoolBase;
@@ -131,13 +135,13 @@ class TCPClientSocketPool : public ClientSocketPool {
DISALLOW_COPY_AND_ASSIGN(TCPConnectJobFactory);
};
- virtual ~TCPClientSocketPool();
-
PoolBase base_;
DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool);
};
+REGISTER_SOCKET_PARAMS_FOR_POOL(TCPClientSocketPool, HostResolver::RequestInfo)
+
} // namespace net
#endif // NET_SOCKET_TCP_CLIENT_SOCKET_POOL_H_
diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc
index 4d679f9..86388f5 100644
--- a/net/socket/tcp_client_socket_pool_unittest.cc
+++ b/net/socket/tcp_client_socket_pool_unittest.cc
@@ -189,7 +189,8 @@ class MockClientSocketFactory : public ClientSocketFactory {
class TCPClientSocketPoolTest : public ClientSocketPoolTest {
protected:
TCPClientSocketPoolTest()
- : host_resolver_(new MockHostResolver),
+ : ignored_request_info_("ignored", 80),
+ host_resolver_(new MockHostResolver),
pool_(new TCPClientSocketPool(kMaxSockets,
kMaxSocketsPerGroup,
host_resolver_,
@@ -197,9 +198,11 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest {
}
int StartRequest(const std::string& group_name, int priority) {
- return StartRequestUsingPool(pool_.get(), group_name, priority);
+ return StartRequestUsingPool(
+ pool_.get(), group_name, priority, ignored_request_info_);
}
+ HostResolver::RequestInfo ignored_request_info_;
scoped_refptr<MockHostResolver> host_resolver_;
MockClientSocketFactory client_socket_factory_;
scoped_refptr<TCPClientSocketPool> pool_;