summaryrefslogtreecommitdiffstats
path: root/net/socket/socks_client_socket_pool.h
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 17:17:26 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 17:17:26 +0000
commita796bcec176ca3875a55346800b3a60a83e2dd89 (patch)
tree2533c17673ff50f4f101e803c2dff3bf8f5cbf7b /net/socket/socks_client_socket_pool.h
parent35818452760c23c570b7947e00a3b38e733ce58e (diff)
downloadchromium_src-a796bcec176ca3875a55346800b3a60a83e2dd89.zip
chromium_src-a796bcec176ca3875a55346800b3a60a83e2dd89.tar.gz
chromium_src-a796bcec176ca3875a55346800b3a60a83e2dd89.tar.bz2
Implement SOCKSClientSocketPool
This is the first layered pool, so there are several infrastructure changes in this change as well. Add a ConnectionTimeout method to pools so that layered pools can timeout each phase. Add a name method to pools to support per pool UMA histograms. Change SOCKS sockets to take a ClientSocketHandle instead of a ClientSocket BUG=30357 (blocks an SSL Pool) TEST=existing unit tests Review URL: http://codereview.chromium.org/668097 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42231 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/socks_client_socket_pool.h')
-rw-r--r--net/socket/socks_client_socket_pool.h185
1 files changed, 185 insertions, 0 deletions
diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h
new file mode 100644
index 0000000..2c30600
--- /dev/null
+++ b/net/socket/socks_client_socket_pool.h
@@ -0,0 +1,185 @@
+// Copyright (c) 2010 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_SOCKET_SOCKS_CLIENT_SOCKET_POOL_H_
+#define NET_SOCKET_SOCKS_CLIENT_SOCKET_POOL_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/scoped_ptr.h"
+#include "base/time.h"
+#include "net/base/host_resolver.h"
+#include "net/proxy/proxy_server.h"
+#include "net/socket/client_socket_pool_base.h"
+#include "net/socket/client_socket_pool.h"
+#include "net/socket/tcp_client_socket_pool.h"
+
+namespace net {
+
+class ClientSocketFactory;
+class ConnectJobFactory;
+
+class SOCKSSocketParams {
+ public:
+ SOCKSSocketParams(const TCPSocketParams& proxy_server, bool socks_v5,
+ const std::string& destination_host, int destination_port,
+ RequestPriority priority, const GURL& referrer)
+ : tcp_params_(proxy_server),
+ destination_(destination_host, destination_port),
+ socks_v5_(socks_v5) {
+ // The referrer is used by the DNS prefetch system to correlate resolutions
+ // with the page that triggered them. It doesn't impact the actual addresses
+ // that we resolve to.
+ destination_.set_referrer(referrer);
+ destination_.set_priority(priority);
+ }
+
+ const TCPSocketParams& tcp_params() const { return tcp_params_; }
+ const HostResolver::RequestInfo& destination() const { return destination_; }
+ bool is_socks_v5() const { return socks_v5_; };
+
+ private:
+ // The tcp connection must point toward the proxy server.
+ const TCPSocketParams tcp_params_;
+ // This is the HTTP destination.
+ HostResolver::RequestInfo destination_;
+ const bool socks_v5_;
+};
+
+// SOCKSConnectJob handles the handshake to a socks server after setting up
+// an underlying transport socket.
+class SOCKSConnectJob : public ConnectJob {
+ public:
+ SOCKSConnectJob(const std::string& group_name,
+ const SOCKSSocketParams& params,
+ const base::TimeDelta& timeout_duration,
+ const scoped_refptr<TCPClientSocketPool>& tcp_pool,
+ const scoped_refptr<HostResolver> &host_resolver,
+ Delegate* delegate,
+ const BoundNetLog& net_log);
+ virtual ~SOCKSConnectJob();
+
+ // ConnectJob methods.
+ virtual LoadState GetLoadState() const;
+
+ private:
+ enum State {
+ kStateTCPConnect,
+ kStateTCPConnectComplete,
+ kStateSOCKSConnect,
+ kStateSOCKSConnectComplete,
+ kStateNone,
+ };
+
+ // Begins the tcp connection and the SOCKS handshake. Returns OK on success
+ // and ERR_IO_PENDING if it cannot immediately service the request.
+ // Otherwise, it returns a net error code.
+ virtual int ConnectInternal();
+
+ void OnIOComplete(int result);
+
+ // Runs the state transition loop.
+ int DoLoop(int result);
+
+ int DoTCPConnect();
+ int DoTCPConnectComplete(int result);
+ int DoSOCKSConnect();
+ int DoSOCKSConnectComplete(int result);
+
+ SOCKSSocketParams socks_params_;
+ const scoped_refptr<TCPClientSocketPool> tcp_pool_;
+ const scoped_refptr<HostResolver> resolver_;
+
+ State next_state_;
+ CompletionCallbackImpl<SOCKSConnectJob> callback_;
+ scoped_ptr<ClientSocketHandle> tcp_socket_handle_;
+ scoped_ptr<ClientSocket> socket_;
+
+ DISALLOW_COPY_AND_ASSIGN(SOCKSConnectJob);
+};
+
+class SOCKSClientSocketPool : public ClientSocketPool {
+ public:
+ SOCKSClientSocketPool(
+ int max_sockets,
+ int max_sockets_per_group,
+ const std::string& name,
+ const scoped_refptr<HostResolver>& host_resolver,
+ const scoped_refptr<TCPClientSocketPool>& tcp_pool,
+ NetworkChangeNotifier* network_change_notifier);
+
+ // ClientSocketPool methods:
+ virtual int RequestSocket(const std::string& group_name,
+ const void* connect_params,
+ RequestPriority priority,
+ ClientSocketHandle* handle,
+ CompletionCallback* callback,
+ const BoundNetLog& net_log);
+
+ 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 IdleSocketCount() const {
+ return base_.idle_socket_count();
+ }
+
+ virtual int IdleSocketCountInGroup(const std::string& group_name) const;
+
+ virtual LoadState GetLoadState(const std::string& group_name,
+ const ClientSocketHandle* handle) const;
+
+ virtual base::TimeDelta ConnectionTimeout() const {
+ return base_.ConnectionTimeout();
+ }
+
+ virtual const std::string& name() const { return base_.name(); };
+
+ protected:
+ virtual ~SOCKSClientSocketPool();
+
+ private:
+ typedef ClientSocketPoolBase<SOCKSSocketParams> PoolBase;
+
+ class SOCKSConnectJobFactory : public PoolBase::ConnectJobFactory {
+ public:
+ SOCKSConnectJobFactory(const scoped_refptr<TCPClientSocketPool>& tcp_pool,
+ HostResolver* host_resolver)
+ : tcp_pool_(tcp_pool),
+ host_resolver_(host_resolver) {}
+
+ virtual ~SOCKSConnectJobFactory() {}
+
+ // ClientSocketPoolBase::ConnectJobFactory methods.
+ virtual ConnectJob* NewConnectJob(
+ const std::string& group_name,
+ const PoolBase::Request& request,
+ ConnectJob::Delegate* delegate,
+ const BoundNetLog& net_log) const;
+
+ virtual base::TimeDelta ConnectionTimeout() const;
+
+ private:
+ const scoped_refptr<TCPClientSocketPool> tcp_pool_;
+ const scoped_refptr<HostResolver> host_resolver_;
+
+ DISALLOW_COPY_AND_ASSIGN(SOCKSConnectJobFactory);
+ };
+
+ PoolBase base_;
+
+ DISALLOW_COPY_AND_ASSIGN(SOCKSClientSocketPool);
+};
+
+REGISTER_SOCKET_PARAMS_FOR_POOL(SOCKSClientSocketPool, SOCKSSocketParams)
+
+} // namespace net
+
+#endif // NET_SOCKET_SOCKS_CLIENT_SOCKET_POOL_H_