| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_SOCKET_TCP_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_SOCKET_TCP_CLIENT_SOCKET_POOL_H_ |
| 6 #define NET_SOCKET_TCP_CLIENT_SOCKET_POOL_H_ | 6 #define NET_SOCKET_TCP_CLIENT_SOCKET_POOL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "base/timer.h" | 14 #include "base/timer.h" |
| 15 #include "net/base/host_resolver.h" | 15 #include "net/base/host_resolver.h" |
| 16 #include "net/socket/client_socket_pool_base.h" | 16 #include "net/socket/client_socket_pool_base.h" |
| 17 #include "net/socket/client_socket_pool.h" | 17 #include "net/socket/client_socket_pool.h" |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 class ClientSocketFactory; | 21 class ClientSocketFactory; |
| 22 | 22 |
| 23 class TCPSocketParams { |
| 24 public: |
| 25 TCPSocketParams(const std::string& host, int port, RequestPriority priority, |
| 26 const GURL& referrer, bool disable_resolver_cache) |
| 27 : destination_(host, port) { |
| 28 // The referrer is used by the DNS prefetch system to correlate resolutions |
| 29 // with the page that triggered them. It doesn't impact the actual addresses |
| 30 // that we resolve to. |
| 31 destination_.set_referrer(referrer); |
| 32 destination_.set_priority(priority); |
| 33 if (disable_resolver_cache) |
| 34 destination_.set_allow_cached_response(false); |
| 35 } |
| 36 |
| 37 HostResolver::RequestInfo destination() const { return destination_; } |
| 38 |
| 39 private: |
| 40 HostResolver::RequestInfo destination_; |
| 41 }; |
| 42 |
| 23 // TCPConnectJob handles the host resolution necessary for socket creation | 43 // TCPConnectJob handles the host resolution necessary for socket creation |
| 24 // and the tcp connect. | 44 // and the tcp connect. |
| 25 class TCPConnectJob : public ConnectJob { | 45 class TCPConnectJob : public ConnectJob { |
| 26 public: | 46 public: |
| 27 TCPConnectJob(const std::string& group_name, | 47 TCPConnectJob(const std::string& group_name, |
| 28 const HostResolver::RequestInfo& resolve_info, | 48 const TCPSocketParams& params, |
| 29 base::TimeDelta timeout_duration, | 49 base::TimeDelta timeout_duration, |
| 30 ClientSocketFactory* client_socket_factory, | 50 ClientSocketFactory* client_socket_factory, |
| 31 HostResolver* host_resolver, | 51 HostResolver* host_resolver, |
| 32 Delegate* delegate, | 52 Delegate* delegate, |
| 33 LoadLog* load_log); | 53 LoadLog* load_log); |
| 34 virtual ~TCPConnectJob(); | 54 virtual ~TCPConnectJob(); |
| 35 | 55 |
| 36 // ConnectJob methods. | 56 // ConnectJob methods. |
| 37 virtual LoadState GetLoadState() const; | 57 virtual LoadState GetLoadState() const; |
| 38 | 58 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 53 void OnIOComplete(int result); | 73 void OnIOComplete(int result); |
| 54 | 74 |
| 55 // Runs the state transition loop. | 75 // Runs the state transition loop. |
| 56 int DoLoop(int result); | 76 int DoLoop(int result); |
| 57 | 77 |
| 58 int DoResolveHost(); | 78 int DoResolveHost(); |
| 59 int DoResolveHostComplete(int result); | 79 int DoResolveHostComplete(int result); |
| 60 int DoTCPConnect(); | 80 int DoTCPConnect(); |
| 61 int DoTCPConnectComplete(int result); | 81 int DoTCPConnectComplete(int result); |
| 62 | 82 |
| 63 const HostResolver::RequestInfo resolve_info_; | 83 const TCPSocketParams params_; |
| 64 ClientSocketFactory* const client_socket_factory_; | 84 ClientSocketFactory* const client_socket_factory_; |
| 65 CompletionCallbackImpl<TCPConnectJob> callback_; | 85 CompletionCallbackImpl<TCPConnectJob> callback_; |
| 66 SingleRequestHostResolver resolver_; | 86 SingleRequestHostResolver resolver_; |
| 67 AddressList addresses_; | 87 AddressList addresses_; |
| 68 State next_state_; | 88 State next_state_; |
| 69 | 89 |
| 70 // The time Connect() was called. | 90 // The time Connect() was called. |
| 71 base::TimeTicks start_time_; | 91 base::TimeTicks start_time_; |
| 72 | 92 |
| 73 // The time the connect was started (after DNS finished). | 93 // The time the connect was started (after DNS finished). |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 128 |
| 109 virtual int IdleSocketCountInGroup(const std::string& group_name) const; | 129 virtual int IdleSocketCountInGroup(const std::string& group_name) const; |
| 110 | 130 |
| 111 virtual LoadState GetLoadState(const std::string& group_name, | 131 virtual LoadState GetLoadState(const std::string& group_name, |
| 112 const ClientSocketHandle* handle) const; | 132 const ClientSocketHandle* handle) const; |
| 113 | 133 |
| 114 protected: | 134 protected: |
| 115 virtual ~TCPClientSocketPool(); | 135 virtual ~TCPClientSocketPool(); |
| 116 | 136 |
| 117 private: | 137 private: |
| 118 typedef ClientSocketPoolBase<HostResolver::RequestInfo> PoolBase; | 138 typedef ClientSocketPoolBase<TCPSocketParams> PoolBase; |
| 119 | 139 |
| 120 class TCPConnectJobFactory | 140 class TCPConnectJobFactory |
| 121 : public PoolBase::ConnectJobFactory { | 141 : public PoolBase::ConnectJobFactory { |
| 122 public: | 142 public: |
| 123 TCPConnectJobFactory(ClientSocketFactory* client_socket_factory, | 143 TCPConnectJobFactory(ClientSocketFactory* client_socket_factory, |
| 124 HostResolver* host_resolver) | 144 HostResolver* host_resolver) |
| 125 : client_socket_factory_(client_socket_factory), | 145 : client_socket_factory_(client_socket_factory), |
| 126 host_resolver_(host_resolver) {} | 146 host_resolver_(host_resolver) {} |
| 127 | 147 |
| 128 virtual ~TCPConnectJobFactory() {} | 148 virtual ~TCPConnectJobFactory() {} |
| (...skipping 11 matching lines...) Expand all Loading... |
| 140 const scoped_refptr<HostResolver> host_resolver_; | 160 const scoped_refptr<HostResolver> host_resolver_; |
| 141 | 161 |
| 142 DISALLOW_COPY_AND_ASSIGN(TCPConnectJobFactory); | 162 DISALLOW_COPY_AND_ASSIGN(TCPConnectJobFactory); |
| 143 }; | 163 }; |
| 144 | 164 |
| 145 PoolBase base_; | 165 PoolBase base_; |
| 146 | 166 |
| 147 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); | 167 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); |
| 148 }; | 168 }; |
| 149 | 169 |
| 150 REGISTER_SOCKET_PARAMS_FOR_POOL(TCPClientSocketPool, HostResolver::RequestInfo) | 170 REGISTER_SOCKET_PARAMS_FOR_POOL(TCPClientSocketPool, TCPSocketParams) |
| 151 | 171 |
| 152 } // namespace net | 172 } // namespace net |
| 153 | 173 |
| 154 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_POOL_H_ | 174 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_POOL_H_ |
| OLD | NEW |