diff options
author | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-25 20:13:46 +0000 |
---|---|---|
committer | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-25 20:13:46 +0000 |
commit | 2df19bbe98514cda5a61d0805b62beacd85a85d0 (patch) | |
tree | 9624087bcdcf85b4e873ea383f63f3a58ff249ce /net/socket/socket_test_util.cc | |
parent | f5bbc935e2dbf097974ebe48d3ae7e6ef1220d38 (diff) | |
download | chromium_src-2df19bbe98514cda5a61d0805b62beacd85a85d0.zip chromium_src-2df19bbe98514cda5a61d0805b62beacd85a85d0.tar.gz chromium_src-2df19bbe98514cda5a61d0805b62beacd85a85d0.tar.bz2 |
Attempting to re-land CL 3110006 which turned out to have
a memory leak.
Add support for speaking SSL to an HTTP Proxy, to
HttpProxyClientSocketPool (and friends)
More information about an HTTPS Proxy can be found here:
http://dev.chromium.org/spdy/spdy-proxy
This implementation supports both http:// and https:// requests,
as well as support for both Proxy and Server auth.
BUG=29625
TEST=none
Review URL: http://codereview.chromium.org/3112034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57371 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/socket_test_util.cc')
-rw-r--r-- | net/socket/socket_test_util.cc | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc index 74f5f4f..07d4206 100644 --- a/net/socket/socket_test_util.cc +++ b/net/socket/socket_test_util.cc @@ -1178,4 +1178,102 @@ const char kSOCKS5OkResponse[] = { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); +MockSSLClientSocketPool::MockSSLClientSocketPool( + int max_sockets, + int max_sockets_per_group, + const scoped_refptr<ClientSocketPoolHistograms>& histograms, + ClientSocketFactory* socket_factory) + : SSLClientSocketPool(max_sockets, max_sockets_per_group, histograms, + NULL, socket_factory, + new MockTCPClientSocketPool(max_sockets, + max_sockets_per_group, + histograms, + socket_factory), + NULL, NULL, NULL), + client_socket_factory_(socket_factory), + release_count_(0), + cancel_count_(0) { +} + +int MockSSLClientSocketPool::RequestSocket(const std::string& group_name, + const void* socket_params, + RequestPriority priority, + ClientSocketHandle* handle, + CompletionCallback* callback, + const BoundNetLog& net_log) { + ClientSocket* socket = client_socket_factory_->CreateTCPClientSocket( + AddressList(), net_log.net_log(), net::NetLog::Source()); + MockConnectJob* job = new MockConnectJob(socket, handle, callback); + job_list_.push_back(job); + handle->set_pool_id(1); + return job->Connect(); +} + +void MockSSLClientSocketPool::CancelRequest(const std::string& group_name, + ClientSocketHandle* handle) { + std::vector<MockConnectJob*>::iterator i; + for (i = job_list_.begin(); i != job_list_.end(); ++i) { + if ((*i)->CancelHandle(handle)) { + cancel_count_++; + break; + } + } +} + +void MockSSLClientSocketPool::ReleaseSocket(const std::string& group_name, + ClientSocket* socket, int id) { + EXPECT_EQ(1, id); + release_count_++; + delete socket; +} + +MockSSLClientSocketPool::~MockSSLClientSocketPool() {} + +MockSSLClientSocketPool::MockConnectJob::MockConnectJob( + ClientSocket* socket, + ClientSocketHandle* handle, + CompletionCallback* callback) + : socket_(socket), + handle_(handle), + user_callback_(callback), + ALLOW_THIS_IN_INITIALIZER_LIST( + connect_callback_(this, &MockConnectJob::OnConnect)) { +} + +int MockSSLClientSocketPool::MockConnectJob::Connect() { + int rv = socket_->Connect(&connect_callback_); + if (rv == OK) { + user_callback_ = NULL; + OnConnect(OK); + } + return rv; +} + +bool MockSSLClientSocketPool::MockConnectJob::CancelHandle( + const ClientSocketHandle* handle) { + if (handle != handle_) + return false; + socket_.reset(); + handle_ = NULL; + user_callback_ = NULL; + return true; +} + +void MockSSLClientSocketPool::MockConnectJob::OnConnect(int rv) { + if (!socket_.get()) + return; + if (rv == OK) { + handle_->set_socket(socket_.release()); + } else { + socket_.reset(); + } + + handle_ = NULL; + + if (user_callback_) { + CompletionCallback* callback = user_callback_; + user_callback_ = NULL; + callback->Run(rv); + } +} } // namespace net |