OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
6 #define NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 6 #define NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/debug/stack_trace.h" | |
14 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
15 #include "base/time.h" | 14 #include "base/time.h" |
16 #include "base/template_util.h" | 15 #include "base/template_util.h" |
17 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
18 #include "net/base/host_resolver.h" | 17 #include "net/base/host_resolver.h" |
19 #include "net/base/load_states.h" | 18 #include "net/base/load_states.h" |
20 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
21 #include "net/base/request_priority.h" | 20 #include "net/base/request_priority.h" |
22 | 21 |
23 namespace base { | 22 namespace base { |
24 class DictionaryValue; | 23 class DictionaryValue; |
25 } | 24 } |
26 | 25 |
27 namespace net { | 26 namespace net { |
28 | 27 |
29 class ClientSocketHandle; | 28 class ClientSocketHandle; |
30 class ClientSocketPoolHistograms; | 29 class ClientSocketPoolHistograms; |
31 class StreamSocket; | 30 class StreamSocket; |
32 | 31 |
33 // ClientSocketPools are layered. This defines an interface for lower level | |
34 // socket pools to communicate with higher layer pools. | |
35 class NET_EXPORT LayeredPool { | |
36 public: | |
37 LayeredPool(); | |
38 virtual ~LayeredPool(); | |
39 | |
40 // Instructs the LayeredPool to close an idle connection. Return true if one | |
41 // was closed. | |
42 virtual bool CloseOneIdleConnection() = 0; | |
43 | |
44 // TODO(rch): remove this once we track down the use-after-free | |
45 void CrashIfFreed(); | |
46 | |
47 private: | |
48 // TODO(rch): Remove this once we track down the use-after-free | |
49 enum MagicValue { | |
50 ALIVE = 0xCA11AB1E, | |
51 DEAD = 0xDEADBEEF | |
52 }; | |
53 | |
54 // TODO(rch): Remove this once we track down the use-after-free | |
55 MagicValue magic_value_; | |
56 base::debug::StackTrace stack_trace_; | |
57 }; | |
58 | |
59 // A ClientSocketPool is used to restrict the number of sockets open at a time. | 32 // A ClientSocketPool is used to restrict the number of sockets open at a time. |
60 // It also maintains a list of idle persistent sockets. | 33 // It also maintains a list of idle persistent sockets. |
61 // | 34 // |
62 class NET_EXPORT ClientSocketPool { | 35 class NET_EXPORT ClientSocketPool { |
63 public: | 36 public: |
64 // Requests a connected socket for a group_name. | 37 // Requests a connected socket for a group_name. |
65 // | 38 // |
66 // There are five possible results from calling this function: | 39 // There are five possible results from calling this function: |
67 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. | 40 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. |
68 // 2) RequestSocket returns OK with a newly connected socket. | 41 // 2) RequestSocket returns OK with a newly connected socket. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 virtual void ReleaseSocket(const std::string& group_name, | 103 virtual void ReleaseSocket(const std::string& group_name, |
131 StreamSocket* socket, | 104 StreamSocket* socket, |
132 int id) = 0; | 105 int id) = 0; |
133 | 106 |
134 // This flushes all state from the ClientSocketPool. This means that all | 107 // This flushes all state from the ClientSocketPool. This means that all |
135 // idle and connecting sockets are discarded. Active sockets being | 108 // idle and connecting sockets are discarded. Active sockets being |
136 // held by ClientSocketPool clients will be discarded when released back to | 109 // held by ClientSocketPool clients will be discarded when released back to |
137 // the pool. Does not flush any pools wrapped by |this|. | 110 // the pool. Does not flush any pools wrapped by |this|. |
138 virtual void Flush() = 0; | 111 virtual void Flush() = 0; |
139 | 112 |
140 // Returns true if a there is currently a request blocked on the | |
141 // per-pool (not per-host) max socket limit. | |
142 virtual bool IsStalled() const = 0; | |
143 | |
144 // Called to close any idle connections held by the connection manager. | 113 // Called to close any idle connections held by the connection manager. |
145 virtual void CloseIdleSockets() = 0; | 114 virtual void CloseIdleSockets() = 0; |
146 | 115 |
147 // The total number of idle sockets in the pool. | 116 // The total number of idle sockets in the pool. |
148 virtual int IdleSocketCount() const = 0; | 117 virtual int IdleSocketCount() const = 0; |
149 | 118 |
150 // The total number of idle sockets in a connection group. | 119 // The total number of idle sockets in a connection group. |
151 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; | 120 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; |
152 | 121 |
153 // Determine the LoadState of a connecting ClientSocketHandle. | 122 // Determine the LoadState of a connecting ClientSocketHandle. |
154 virtual LoadState GetLoadState(const std::string& group_name, | 123 virtual LoadState GetLoadState(const std::string& group_name, |
155 const ClientSocketHandle* handle) const = 0; | 124 const ClientSocketHandle* handle) const = 0; |
156 | 125 |
157 // Adds a LayeredPool on top of |this|. | |
158 virtual void AddLayeredPool(LayeredPool* layered_pool) = 0; | |
159 | |
160 // Removes a LayeredPool from |this|. | |
161 virtual void RemoveLayeredPool(LayeredPool* layered_pool) = 0; | |
162 | |
163 // Retrieves information on the current state of the pool as a | 126 // Retrieves information on the current state of the pool as a |
164 // DictionaryValue. Caller takes possession of the returned value. | 127 // DictionaryValue. Caller takes possession of the returned value. |
165 // If |include_nested_pools| is true, the states of any nested | 128 // If |include_nested_pools| is true, the states of any nested |
166 // ClientSocketPools will be included. | 129 // ClientSocketPools will be included. |
167 virtual base::DictionaryValue* GetInfoAsValue( | 130 virtual base::DictionaryValue* GetInfoAsValue( |
168 const std::string& name, | 131 const std::string& name, |
169 const std::string& type, | 132 const std::string& type, |
170 bool include_nested_pools) const = 0; | 133 bool include_nested_pools) const = 0; |
171 | 134 |
172 // Returns the maximum amount of time to wait before retrying a connect. | 135 // Returns the maximum amount of time to wait before retrying a connect. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 const scoped_refptr<SocketParams>& params, | 190 const scoped_refptr<SocketParams>& params, |
228 int num_sockets, | 191 int num_sockets, |
229 const BoundNetLog& net_log) { | 192 const BoundNetLog& net_log) { |
230 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); | 193 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); |
231 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); | 194 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); |
232 } | 195 } |
233 | 196 |
234 } // namespace net | 197 } // namespace net |
235 | 198 |
236 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 199 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |