diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-14 07:07:49 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-14 07:07:49 +0000 |
commit | d80a432e2201c81d60508d8399129063baa63982 (patch) | |
tree | 00106740b6f9547148411a97fcc1328cc66b13c7 /net/socket/client_socket_handle.h | |
parent | b8c904a326b28ad76146ab2a7366b2bbc2edaab9 (diff) | |
download | chromium_src-d80a432e2201c81d60508d8399129063baa63982.zip chromium_src-d80a432e2201c81d60508d8399129063baa63982.tar.gz chromium_src-d80a432e2201c81d60508d8399129063baa63982.tar.bz2 |
Make ClientSocketPool/ClientSocketPoolBase/ClientSocketHandle more generic.
This is in preparation for creating an SSLClientSocketPool.
ClientSocketPoolBase is now templated. Most of the implementation has moved to ClientSocketPoolBaseHelper which is not templated.
In order to make this possible, ClientSocketPoolBaseHelper's internal data structures do not use the full concrete Request type, but rather use a pointer to Request.
ClientSocketPoolBase takes a SocketParams as a template argument, primarily to allow RequestSocket to take a templated parameter that contains all the information necessary to connect the socket (be it TCP or SSL or whatever).
ClientSocketPool::RequestSocket() and ClientSocketHandle::Init() have been templated as well to handle this case.
I've left adding run-time type safety checks as a TODO.
TEST=net_unittests
BUG=http://crbug.com/13289
Review URL: http://codereview.chromium.org/160621
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23427 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/client_socket_handle.h')
-rw-r--r-- | net/socket/client_socket_handle.h | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/net/socket/client_socket_handle.h b/net/socket/client_socket_handle.h index 0dbb1bc..67c6cb8 100644 --- a/net/socket/client_socket_handle.h +++ b/net/socket/client_socket_handle.h @@ -7,17 +7,17 @@ #include <string> +#include "base/logging.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "net/base/completion_callback.h" -#include "net/base/host_resolver.h" #include "net/base/load_states.h" +#include "net/base/net_errors.h" #include "net/socket/client_socket.h" +#include "net/socket/client_socket_pool.h" namespace net { -class ClientSocketPool; - // A container for a ClientSocket. // // The handle's |group_name| uniquely identifies the origin and type of the @@ -39,7 +39,7 @@ class ClientSocketHandle { // otherwise it will be set to a new connected socket. Consumers can then // call is_reused() to see if the socket was reused. If not reusing an // existing socket, ClientSocketPool may need to establish a new - // connection to the |resolve_info.host| |resolve_info.port| pair. + // connection using |socket_params|. // // This method returns ERR_IO_PENDING if it cannot complete synchronously, in // which case the consumer will be notified of completion via |callback|. @@ -47,8 +47,10 @@ class ClientSocketHandle { // Init may be called multiple times. // // Profiling information for the request is saved to |load_log| if non-NULL. + // + template <typename SocketParams> int Init(const std::string& group_name, - const HostResolver::RequestInfo& resolve_info, + const SocketParams& socket_params, int priority, CompletionCallback* callback, LoadLog* load_log); @@ -102,6 +104,26 @@ class ClientSocketHandle { DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); }; +// Template function implementation: +template <typename SocketParams> +int ClientSocketHandle::Init(const std::string& group_name, + const SocketParams& socket_params, + int priority, + CompletionCallback* callback, + LoadLog* load_log) { + CHECK(!group_name.empty()); + ResetInternal(true); + group_name_ = group_name; + int rv = pool_->RequestSocket( + group_name, &socket_params, priority, this, &callback_, load_log); + if (rv == ERR_IO_PENDING) { + user_callback_ = callback; + } else { + HandleInitCompletion(rv); + } + return rv; +} + } // namespace net #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ |