diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 04:47:24 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 04:47:24 +0000 |
commit | 5e2a9596a1e11e20412d41600ef1b6493c5bfb81 (patch) | |
tree | d6928c5c3e443d5618c570501b359e09d252da9a | |
parent | d7a43ce2396a994acd9938804b54ab1743081c9b (diff) | |
download | chromium_src-5e2a9596a1e11e20412d41600ef1b6493c5bfb81.zip chromium_src-5e2a9596a1e11e20412d41600ef1b6493c5bfb81.tar.gz chromium_src-5e2a9596a1e11e20412d41600ef1b6493c5bfb81.tar.bz2 |
Make ClientSocketPool an interface. Move ClientSocketPool code into TCPClientSocketPool. Strictly a refactoring.
BUG=http://www.crbug.com/13289
TEST=still builds and tests pass
Review URL: http://codereview.chromium.org/119184
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17710 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/base/client_socket_handle.cc | 1 | ||||
-rw-r--r-- | net/base/client_socket_pool.h | 172 | ||||
-rw-r--r-- | net/base/tcp_client_socket_pool.cc (renamed from net/base/client_socket_pool.cc) | 71 | ||||
-rw-r--r-- | net/base/tcp_client_socket_pool.h | 191 | ||||
-rw-r--r-- | net/base/tcp_client_socket_pool_unittest.cc (renamed from net/base/client_socket_pool_unittest.cc) | 29 | ||||
-rw-r--r-- | net/http/http_network_session.h | 4 | ||||
-rw-r--r-- | net/net.gyp | 5 |
7 files changed, 267 insertions, 206 deletions
diff --git a/net/base/client_socket_handle.cc b/net/base/client_socket_handle.cc index 49de998..81841fa 100644 --- a/net/base/client_socket_handle.cc +++ b/net/base/client_socket_handle.cc @@ -5,6 +5,7 @@ #include "net/base/client_socket_handle.h" #include "base/compiler_specific.h" +#include "base/logging.h" #include "net/base/client_socket.h" #include "net/base/client_socket_pool.h" #include "net/base/net_errors.h" diff --git a/net/base/client_socket_pool.h b/net/base/client_socket_pool.h index 0ee3ffe..599b7a9 100644 --- a/net/base/client_socket_pool.h +++ b/net/base/client_socket_pool.h @@ -10,17 +10,12 @@ #include <string> #include "base/ref_counted.h" -#include "base/scoped_ptr.h" -#include "base/timer.h" -#include "net/base/address_list.h" #include "net/base/completion_callback.h" -#include "net/base/host_resolver.h" #include "net/base/load_states.h" namespace net { class ClientSocket; -class ClientSocketFactory; class ClientSocketHandle; // A ClientSocketPool is used to restrict the number of sockets open at a time. @@ -28,9 +23,6 @@ class ClientSocketHandle; // class ClientSocketPool : public base::RefCounted<ClientSocketPool> { public: - ClientSocketPool(int max_sockets_per_group, - ClientSocketFactory* client_socket_factory); - // Requests a connected socket for a group_name. // // There are four possible results from calling this function: @@ -53,173 +45,47 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> { // If ERR_IO_PENDING is returned, then the callback will be used to notify the // client of completion. // - int RequestSocket(const std::string& group_name, - const std::string& host, - int port, - int priority, - ClientSocketHandle* handle, - CompletionCallback* callback); + virtual int RequestSocket(const std::string& group_name, + const std::string& host, + int port, + int priority, + ClientSocketHandle* handle, + CompletionCallback* callback) = 0; // 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 CompletionCallback is // not run. - void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle); + virtual void CancelRequest(const std::string& group_name, + const ClientSocketHandle* handle) = 0; // Called to release a socket once the socket is no longer needed. If the // socket still has an established connection, then it will be added to the // set of idle sockets to be used to satisfy future RequestSocket calls. // Otherwise, the ClientSocket is destroyed. - void ReleaseSocket(const std::string& group_name, ClientSocket* socket); + virtual void ReleaseSocket(const std::string& group_name, + ClientSocket* socket) = 0; // Called to close any idle connections held by the connection manager. - void CloseIdleSockets(); + virtual void CloseIdleSockets() = 0; // The total number of idle sockets in the pool. - int idle_socket_count() const { - return idle_socket_count_; - } + virtual int idle_socket_count() const = 0; // The total number of idle sockets in a connection group. - int IdleSocketCountInGroup(const std::string& group_name) const; + virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; // Determine the LoadState of a connecting ClientSocketHandle. - LoadState GetLoadState(const std::string& group_name, - const ClientSocketHandle* handle) const; + virtual LoadState GetLoadState(const std::string& group_name, + const ClientSocketHandle* handle) const = 0; + + protected: + ClientSocketPool() {} + virtual ~ClientSocketPool() {} private: friend class base::RefCounted<ClientSocketPool>; - // A Request is allocated per call to RequestSocket that results in - // ERR_IO_PENDING. - struct Request { - ClientSocketHandle* handle; - CompletionCallback* callback; - int priority; - std::string host; - int port; - LoadState load_state; - }; - - // Entry for a persistent socket which became idle at time |start_time|. - struct IdleSocket { - ClientSocket* socket; - base::TimeTicks start_time; - - // An idle socket should be removed if it can't be reused, or has been idle - // for too long. |now| is the current time value (TimeTicks::Now()). - // - // An idle socket can't be reused if it is disconnected or has received - // data unexpectedly (hence no longer idle). The unread data would be - // mistaken for the beginning of the next response if we were to reuse the - // socket for a new request. - bool ShouldCleanup(base::TimeTicks now) const; - }; - - typedef std::deque<Request> RequestQueue; - typedef std::map<const ClientSocketHandle*, Request> RequestMap; - - // A Group is allocated per group_name when there are idle sockets or pending - // requests. Otherwise, the Group object is removed from the map. - struct Group { - Group() : active_socket_count(0) {} - std::deque<IdleSocket> idle_sockets; - RequestQueue pending_requests; - RequestMap connecting_requests; - int active_socket_count; - }; - - typedef std::map<std::string, Group> GroupMap; - - // ConnectingSocket handles the host resolution necessary for socket creation - // and the Connect(). - class ConnectingSocket { - public: - enum State { - STATE_RESOLVE_HOST, - STATE_CONNECT - }; - - ConnectingSocket(const std::string& group_name, - const ClientSocketHandle* handle, - ClientSocketFactory* client_socket_factory, - ClientSocketPool* pool); - ~ConnectingSocket(); - - // Begins the host resolution and the TCP connect. Returns OK on success, - // in which case |callback| is not called. On pending IO, Connect returns - // ERR_IO_PENDING and runs |callback| on completion. - int Connect(const std::string& host, - int port, - CompletionCallback* callback); - - // If Connect() returns OK, ClientSocketPool may invoke this method to get - // the ConnectingSocket to release |socket_| to be set into the - // ClientSocketHandle immediately. - ClientSocket* ReleaseSocket(); - - // Called by the ClientSocketPool to cancel this ConnectingSocket. Only - // necessary if a ClientSocketHandle is reused. - void Cancel(); - - private: - void OnIOComplete(int result); - - const std::string group_name_; - const ClientSocketHandle* const handle_; - ClientSocketFactory* const client_socket_factory_; - CompletionCallbackImpl<ConnectingSocket> callback_; - scoped_ptr<ClientSocket> socket_; - scoped_refptr<ClientSocketPool> pool_; - HostResolver resolver_; - AddressList addresses_; - bool canceled_; - - // The time the Connect() method was called (if it got called). - base::Time connect_start_time_; - - DISALLOW_COPY_AND_ASSIGN(ConnectingSocket); - }; - - ~ClientSocketPool(); - - static void InsertRequestIntoQueue(const Request& r, - RequestQueue* pending_requests); - - // Closes all idle sockets if |force| is true. Else, only closes idle - // sockets that timed out or can't be reused. - void CleanupIdleSockets(bool force); - - // Called when the number of idle sockets changes. - void IncrementIdleCount(); - void DecrementIdleCount(); - - // Called via PostTask by ReleaseSocket. - void DoReleaseSocket(const std::string& group_name, ClientSocket* socket); - - // Called when timer_ fires. This method scans the idle sockets removing - // sockets that timed out or can't be reused. - void OnCleanupTimerFired() { - CleanupIdleSockets(false); - } - - ClientSocketFactory* const client_socket_factory_; - - GroupMap group_map_; - - std::map<const ClientSocketHandle*, ConnectingSocket*> connecting_socket_map_; - - // Timer used to periodically prune idle sockets that timed out or can't be - // reused. - base::RepeatingTimer<ClientSocketPool> timer_; - - // The total number of idle sockets in the system. - int idle_socket_count_; - - // The maximum number of sockets kept per group. - const int max_sockets_per_group_; - DISALLOW_COPY_AND_ASSIGN(ClientSocketPool); }; diff --git a/net/base/client_socket_pool.cc b/net/base/tcp_client_socket_pool.cc index c0f281b..a385e60 100644 --- a/net/base/client_socket_pool.cc +++ b/net/base/tcp_client_socket_pool.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "net/base/client_socket_pool.h" +#include "net/base/tcp_client_socket_pool.h" #include "base/compiler_specific.h" #include "base/field_trial.h" @@ -34,29 +34,29 @@ const int kIdleTimeout = 300; // 5 minutes. namespace net { -ClientSocketPool::ConnectingSocket::ConnectingSocket( +TCPClientSocketPool::ConnectingSocket::ConnectingSocket( const std::string& group_name, const ClientSocketHandle* handle, ClientSocketFactory* client_socket_factory, - ClientSocketPool* pool) + TCPClientSocketPool* pool) : group_name_(group_name), handle_(handle), client_socket_factory_(client_socket_factory), ALLOW_THIS_IN_INITIALIZER_LIST( callback_(this, - &ClientSocketPool::ConnectingSocket::OnIOComplete)), + &TCPClientSocketPool::ConnectingSocket::OnIOComplete)), pool_(pool), canceled_(false) { DCHECK(!ContainsKey(pool_->connecting_socket_map_, handle)); pool_->connecting_socket_map_[handle] = this; } -ClientSocketPool::ConnectingSocket::~ConnectingSocket() { +TCPClientSocketPool::ConnectingSocket::~ConnectingSocket() { if (!canceled_) pool_->connecting_socket_map_.erase(handle_); } -int ClientSocketPool::ConnectingSocket::Connect( +int TCPClientSocketPool::ConnectingSocket::Connect( const std::string& host, int port, CompletionCallback* callback) { @@ -75,11 +75,11 @@ int ClientSocketPool::ConnectingSocket::Connect( return rv; } -ClientSocket* ClientSocketPool::ConnectingSocket::ReleaseSocket() { +ClientSocket* TCPClientSocketPool::ConnectingSocket::ReleaseSocket() { return socket_.release(); } -void ClientSocketPool::ConnectingSocket::OnIOComplete(int result) { +void TCPClientSocketPool::ConnectingSocket::OnIOComplete(int result) { DCHECK_NE(result, ERR_IO_PENDING); if (canceled_) { @@ -154,21 +154,22 @@ void ClientSocketPool::ConnectingSocket::OnIOComplete(int result) { delete this; } -void ClientSocketPool::ConnectingSocket::Cancel() { +void TCPClientSocketPool::ConnectingSocket::Cancel() { DCHECK(!canceled_); DCHECK(ContainsKey(pool_->connecting_socket_map_, handle_)); pool_->connecting_socket_map_.erase(handle_); canceled_ = true; } -ClientSocketPool::ClientSocketPool(int max_sockets_per_group, - ClientSocketFactory* client_socket_factory) +TCPClientSocketPool::TCPClientSocketPool( + int max_sockets_per_group, + ClientSocketFactory* client_socket_factory) : client_socket_factory_(client_socket_factory), idle_socket_count_(0), max_sockets_per_group_(max_sockets_per_group) { } -ClientSocketPool::~ClientSocketPool() { +TCPClientSocketPool::~TCPClientSocketPool() { // Clean up any idle sockets. Assert that we have no remaining active // sockets or pending requests. They should have all been cleaned up prior // to the manager being destroyed. @@ -181,20 +182,20 @@ ClientSocketPool::~ClientSocketPool() { // prioritized over requests of equal priority. // // static -void ClientSocketPool::InsertRequestIntoQueue(const Request& r, - RequestQueue* pending_requests) { +void TCPClientSocketPool::InsertRequestIntoQueue( + const Request& r, RequestQueue* pending_requests) { RequestQueue::iterator it = pending_requests->begin(); while (it != pending_requests->end() && r.priority <= it->priority) ++it; pending_requests->insert(it, r); } -int ClientSocketPool::RequestSocket(const std::string& group_name, - const std::string& host, - int port, - int priority, - ClientSocketHandle* handle, - CompletionCallback* callback) { +int TCPClientSocketPool::RequestSocket(const std::string& group_name, + const std::string& host, + int port, + int priority, + ClientSocketHandle* handle, + CompletionCallback* callback) { DCHECK(!host.empty()); DCHECK_GE(priority, 0); Group& group = group_map_[group_name]; @@ -270,8 +271,8 @@ int ClientSocketPool::RequestSocket(const std::string& group_name, return rv; } -void ClientSocketPool::CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle) { +void TCPClientSocketPool::CancelRequest(const std::string& group_name, + const ClientSocketHandle* handle) { DCHECK(ContainsKey(group_map_, group_name)); Group& group = group_map_[group_name]; @@ -302,20 +303,20 @@ void ClientSocketPool::CancelRequest(const std::string& group_name, } } -void ClientSocketPool::ReleaseSocket(const std::string& group_name, - ClientSocket* socket) { +void TCPClientSocketPool::ReleaseSocket(const std::string& group_name, + ClientSocket* socket) { // Run this asynchronously to allow the caller to finish before we let // another to begin doing work. This also avoids nasty recursion issues. // NOTE: We cannot refer to the handle argument after this method returns. MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - this, &ClientSocketPool::DoReleaseSocket, group_name, socket)); + this, &TCPClientSocketPool::DoReleaseSocket, group_name, socket)); } -void ClientSocketPool::CloseIdleSockets() { +void TCPClientSocketPool::CloseIdleSockets() { CleanupIdleSockets(true); } -int ClientSocketPool::IdleSocketCountInGroup( +int TCPClientSocketPool::IdleSocketCountInGroup( const std::string& group_name) const { GroupMap::const_iterator i = group_map_.find(group_name); DCHECK(i != group_map_.end()); @@ -323,7 +324,7 @@ int ClientSocketPool::IdleSocketCountInGroup( return i->second.idle_sockets.size(); } -LoadState ClientSocketPool::GetLoadState( +LoadState TCPClientSocketPool::GetLoadState( const std::string& group_name, const ClientSocketHandle* handle) const { DCHECK(ContainsKey(group_map_, group_name)) << group_name; @@ -355,13 +356,13 @@ LoadState ClientSocketPool::GetLoadState( return LOAD_STATE_IDLE; } -bool ClientSocketPool::IdleSocket::ShouldCleanup(base::TimeTicks now) const { +bool TCPClientSocketPool::IdleSocket::ShouldCleanup(base::TimeTicks now) const { bool timed_out = (now - start_time) >= base::TimeDelta::FromSeconds(kIdleTimeout); return timed_out || !socket->IsConnectedAndIdle(); } -void ClientSocketPool::CleanupIdleSockets(bool force) { +void TCPClientSocketPool::CleanupIdleSockets(bool force) { if (idle_socket_count_ == 0) return; @@ -395,19 +396,19 @@ void ClientSocketPool::CleanupIdleSockets(bool force) { } } -void ClientSocketPool::IncrementIdleCount() { +void TCPClientSocketPool::IncrementIdleCount() { if (++idle_socket_count_ == 1) timer_.Start(TimeDelta::FromSeconds(kCleanupInterval), this, - &ClientSocketPool::OnCleanupTimerFired); + &TCPClientSocketPool::OnCleanupTimerFired); } -void ClientSocketPool::DecrementIdleCount() { +void TCPClientSocketPool::DecrementIdleCount() { if (--idle_socket_count_ == 0) timer_.Stop(); } -void ClientSocketPool::DoReleaseSocket(const std::string& group_name, - ClientSocket* socket) { +void TCPClientSocketPool::DoReleaseSocket(const std::string& group_name, + ClientSocket* socket) { GroupMap::iterator i = group_map_.find(group_name); DCHECK(i != group_map_.end()); diff --git a/net/base/tcp_client_socket_pool.h b/net/base/tcp_client_socket_pool.h new file mode 100644 index 0000000..bfd7a4b --- /dev/null +++ b/net/base/tcp_client_socket_pool.h @@ -0,0 +1,191 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ +#define NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ + +#include <deque> +#include <map> +#include <string> + +#include "base/scoped_ptr.h" +#include "base/timer.h" +#include "net/base/address_list.h" +#include "net/base/client_socket_pool.h" +#include "net/base/host_resolver.h" + +namespace net { + +class ClientSocketFactory; + +// A TCPClientSocketPool is used to restrict the number of TCP sockets open at +// a time. It also maintains a list of idle persistent sockets. +// +class TCPClientSocketPool : public ClientSocketPool { + public: + TCPClientSocketPool(int max_sockets_per_group, + ClientSocketFactory* client_socket_factory); + + // ClientSocketPool methods: + + virtual int RequestSocket(const std::string& group_name, + const std::string& host, + int port, + int priority, + ClientSocketHandle* handle, + CompletionCallback* callback); + + virtual void CancelRequest(const std::string& group_name, + const ClientSocketHandle* handle); + + virtual void ReleaseSocket(const std::string& group_name, + ClientSocket* socket); + + virtual void CloseIdleSockets(); + + virtual int idle_socket_count() const { + return idle_socket_count_; + } + + virtual int IdleSocketCountInGroup(const std::string& group_name) const; + + virtual LoadState GetLoadState(const std::string& group_name, + const ClientSocketHandle* handle) const; + + private: + // A Request is allocated per call to RequestSocket that results in + // ERR_IO_PENDING. + struct Request { + ClientSocketHandle* handle; + CompletionCallback* callback; + int priority; + std::string host; + int port; + LoadState load_state; + }; + + // Entry for a persistent socket which became idle at time |start_time|. + struct IdleSocket { + ClientSocket* socket; + base::TimeTicks start_time; + + // An idle socket should be removed if it can't be reused, or has been idle + // for too long. |now| is the current time value (TimeTicks::Now()). + // + // An idle socket can't be reused if it is disconnected or has received + // data unexpectedly (hence no longer idle). The unread data would be + // mistaken for the beginning of the next response if we were to reuse the + // socket for a new request. + bool ShouldCleanup(base::TimeTicks now) const; + }; + + typedef std::deque<Request> RequestQueue; + typedef std::map<const ClientSocketHandle*, Request> RequestMap; + + // A Group is allocated per group_name when there are idle sockets or pending + // requests. Otherwise, the Group object is removed from the map. + struct Group { + Group() : active_socket_count(0) {} + std::deque<IdleSocket> idle_sockets; + RequestQueue pending_requests; + RequestMap connecting_requests; + int active_socket_count; + }; + + typedef std::map<std::string, Group> GroupMap; + + // ConnectingSocket handles the host resolution necessary for socket creation + // and the Connect(). + class ConnectingSocket { + public: + enum State { + STATE_RESOLVE_HOST, + STATE_CONNECT + }; + + ConnectingSocket(const std::string& group_name, + const ClientSocketHandle* handle, + ClientSocketFactory* client_socket_factory, + TCPClientSocketPool* pool); + ~ConnectingSocket(); + + // Begins the host resolution and the TCP connect. Returns OK on success, + // in which case |callback| is not called. On pending IO, Connect returns + // ERR_IO_PENDING and runs |callback| on completion. + int Connect(const std::string& host, + int port, + CompletionCallback* callback); + + // If Connect() returns OK, TCPClientSocketPool may invoke this method to + // get the ConnectingSocket to release |socket_| to be set into the + // ClientSocketHandle immediately. + ClientSocket* ReleaseSocket(); + + // Called by the TCPClientSocketPool to cancel this ConnectingSocket. Only + // necessary if a ClientSocketHandle is reused. + void Cancel(); + + private: + void OnIOComplete(int result); + + const std::string group_name_; + const ClientSocketHandle* const handle_; + ClientSocketFactory* const client_socket_factory_; + CompletionCallbackImpl<ConnectingSocket> callback_; + scoped_ptr<ClientSocket> socket_; + scoped_refptr<TCPClientSocketPool> pool_; + HostResolver resolver_; + AddressList addresses_; + bool canceled_; + + // The time the Connect() method was called (if it got called). + base::Time connect_start_time_; + + DISALLOW_COPY_AND_ASSIGN(ConnectingSocket); + }; + + virtual ~TCPClientSocketPool(); + + static void InsertRequestIntoQueue(const Request& r, + RequestQueue* pending_requests); + + // Closes all idle sockets if |force| is true. Else, only closes idle + // sockets that timed out or can't be reused. + void CleanupIdleSockets(bool force); + + // Called when the number of idle sockets changes. + void IncrementIdleCount(); + void DecrementIdleCount(); + + // Called via PostTask by ReleaseSocket. + void DoReleaseSocket(const std::string& group_name, ClientSocket* socket); + + // Called when timer_ fires. This method scans the idle sockets removing + // sockets that timed out or can't be reused. + void OnCleanupTimerFired() { + CleanupIdleSockets(false); + } + + ClientSocketFactory* const client_socket_factory_; + + GroupMap group_map_; + + std::map<const ClientSocketHandle*, ConnectingSocket*> connecting_socket_map_; + + // Timer used to periodically prune idle sockets that timed out or can't be + // reused. + base::RepeatingTimer<TCPClientSocketPool> timer_; + + // The total number of idle sockets in the system. + int idle_socket_count_; + + // The maximum number of sockets kept per group. + const int max_sockets_per_group_; + + DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); +}; + +} // namespace net + +#endif // NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ diff --git a/net/base/client_socket_pool_unittest.cc b/net/base/tcp_client_socket_pool_unittest.cc index d7160dc..ce85871 100644 --- a/net/base/client_socket_pool_unittest.cc +++ b/net/base/tcp_client_socket_pool_unittest.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "net/base/tcp_client_socket_pool.h" + #include "base/message_loop.h" #include "net/base/client_socket.h" #include "net/base/client_socket_factory.h" #include "net/base/client_socket_handle.h" -#include "net/base/client_socket_pool.h" #include "net/base/host_resolver_unittest.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" @@ -194,11 +195,11 @@ class TestSocketRequest : public CallbackRunner< Tuple1<int> > { int TestSocketRequest::completion_count = 0; -class ClientSocketPoolTest : public testing::Test { +class TCPClientSocketPoolTest : public testing::Test { protected: - ClientSocketPoolTest() - : pool_(new ClientSocketPool(kMaxSocketsPerGroup, - &client_socket_factory_)) {} + TCPClientSocketPoolTest() + : pool_(new TCPClientSocketPool(kMaxSocketsPerGroup, + &client_socket_factory_)) {} virtual void SetUp() { TestSocketRequest::completion_count = 0; @@ -209,7 +210,7 @@ class ClientSocketPoolTest : public testing::Test { std::vector<TestSocketRequest*> request_order_; }; -TEST_F(ClientSocketPoolTest, Basic) { +TEST_F(TCPClientSocketPoolTest, Basic) { TestCompletionCallback callback; ClientSocketHandle handle(pool_.get()); int rv = handle.Init("a", "www.google.com", 80, 0, &callback); @@ -227,7 +228,7 @@ TEST_F(ClientSocketPoolTest, Basic) { MessageLoop::current()->RunAllPending(); } -TEST_F(ClientSocketPoolTest, InitHostResolutionFailure) { +TEST_F(TCPClientSocketPoolTest, InitHostResolutionFailure) { RuleBasedHostMapper* host_mapper = new RuleBasedHostMapper; host_mapper->AddSimulatedFailure("unresolvable.host.name"); ScopedHostMapper scoped_host_mapper(host_mapper); @@ -237,7 +238,7 @@ TEST_F(ClientSocketPoolTest, InitHostResolutionFailure) { EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req.WaitForResult()); } -TEST_F(ClientSocketPoolTest, InitConnectionFailure) { +TEST_F(TCPClientSocketPoolTest, InitConnectionFailure) { client_socket_factory_.set_client_socket_type( MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET); TestSocketRequest req(pool_.get(), &request_order_); @@ -246,7 +247,7 @@ TEST_F(ClientSocketPoolTest, InitConnectionFailure) { EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult()); } -TEST_F(ClientSocketPoolTest, PendingRequests) { +TEST_F(TCPClientSocketPoolTest, PendingRequests) { int rv; scoped_ptr<TestSocketRequest> reqs[kNumRequests]; @@ -302,7 +303,7 @@ TEST_F(ClientSocketPoolTest, PendingRequests) { "earlier into the queue."; } -TEST_F(ClientSocketPoolTest, PendingRequests_NoKeepAlive) { +TEST_F(TCPClientSocketPoolTest, PendingRequests_NoKeepAlive) { scoped_ptr<TestSocketRequest> reqs[kNumRequests]; for (size_t i = 0; i < arraysize(reqs); ++i) reqs[i].reset(new TestSocketRequest(pool_.get(), &request_order_)); @@ -344,7 +345,7 @@ TEST_F(ClientSocketPoolTest, PendingRequests_NoKeepAlive) { // This test will start up a RequestSocket() and then immediately Cancel() it. // The pending host resolution will eventually complete, and destroy the // ClientSocketPool which will crash if the group was not cleared properly. -TEST_F(ClientSocketPoolTest, CancelRequestClearGroup) { +TEST_F(TCPClientSocketPoolTest, CancelRequestClearGroup) { TestSocketRequest req(pool_.get(), &request_order_); EXPECT_EQ(ERR_IO_PENDING, req.handle.Init("a", "www.google.com", 80, 5, &req)); @@ -360,7 +361,7 @@ TEST_F(ClientSocketPoolTest, CancelRequestClearGroup) { MessageLoop::current()->RunAllPending(); } -TEST_F(ClientSocketPoolTest, TwoRequestsCancelOne) { +TEST_F(TCPClientSocketPoolTest, TwoRequestsCancelOne) { TestSocketRequest req(pool_.get(), &request_order_); TestSocketRequest req2(pool_.get(), &request_order_); @@ -382,7 +383,7 @@ TEST_F(ClientSocketPoolTest, TwoRequestsCancelOne) { MessageLoop::current()->RunAllPending(); } -TEST_F(ClientSocketPoolTest, DISABLED_ConnectCancelConnect) { +TEST_F(TCPClientSocketPoolTest, DISABLED_ConnectCancelConnect) { client_socket_factory_.set_client_socket_type( MockClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); TestSocketRequest req(pool_.get(), &request_order_); @@ -414,7 +415,7 @@ TEST_F(ClientSocketPoolTest, DISABLED_ConnectCancelConnect) { MessageLoop::current()->RunAllPending(); } -TEST_F(ClientSocketPoolTest, CancelRequest) { +TEST_F(TCPClientSocketPoolTest, CancelRequest) { scoped_ptr<TestSocketRequest> reqs[kNumRequests]; for (size_t i = 0; i < arraysize(reqs); ++i) diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index d96255a..cb023a0 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -6,8 +6,8 @@ #define NET_HTTP_HTTP_NETWORK_SESSION_H_ #include "base/ref_counted.h" -#include "net/base/client_socket_pool.h" #include "net/base/ssl_config_service.h" +#include "net/base/tcp_client_socket_pool.h" #include "net/http/http_auth_cache.h" namespace net { @@ -20,7 +20,7 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { public: HttpNetworkSession(ProxyService* proxy_service, ClientSocketFactory* client_socket_factory) - : connection_pool_(new ClientSocketPool( + : connection_pool_(new TCPClientSocketPool( max_sockets_per_group_, client_socket_factory)), proxy_service_(proxy_service) { DCHECK(proxy_service); diff --git a/net/net.gyp b/net/net.gyp index 3490d7c..37bc3a7 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -49,7 +49,6 @@ 'base/client_socket_factory.h', 'base/client_socket_handle.cc', 'base/client_socket_handle.h', - 'base/client_socket_pool.cc', 'base/client_socket_pool.h', 'base/completion_callback.h', 'base/connection_type_histograms.cc', @@ -127,6 +126,8 @@ 'base/tcp_client_socket.h', 'base/tcp_client_socket_libevent.cc', 'base/tcp_client_socket_libevent.h', + 'base/tcp_client_socket_pool.cc', + 'base/tcp_client_socket_pool.h', 'base/tcp_client_socket_win.cc', 'base/tcp_client_socket_win.h', 'base/telnet_server.cc', @@ -395,7 +396,6 @@ 'sources': [ 'base/base64_unittest.cc', 'base/bzip2_filter_unittest.cc', - 'base/client_socket_pool_unittest.cc', 'base/cookie_monster_unittest.cc', 'base/cookie_policy_unittest.cc', 'base/data_url_unittest.cc', @@ -417,6 +417,7 @@ 'base/sdch_filter_unittest.cc', 'base/ssl_client_socket_unittest.cc', 'base/ssl_config_service_unittest.cc', + 'base/tcp_client_socket_pool_unittest.cc', 'base/tcp_client_socket_unittest.cc', 'base/tcp_pinger_unittest.cc', 'base/telnet_server_unittest.cc', |