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" | |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/time.h" | 15 #include "base/time.h" |
15 #include "base/template_util.h" | 16 #include "base/template_util.h" |
16 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
17 #include "net/base/host_resolver.h" | 18 #include "net/base/host_resolver.h" |
18 #include "net/base/load_states.h" | 19 #include "net/base/load_states.h" |
19 #include "net/base/net_export.h" | 20 #include "net/base/net_export.h" |
20 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class DictionaryValue; | 24 class DictionaryValue; |
24 } | 25 } |
25 | 26 |
26 namespace net { | 27 namespace net { |
27 | 28 |
28 class ClientSocketHandle; | 29 class ClientSocketHandle; |
29 class ClientSocketPoolHistograms; | 30 class ClientSocketPoolHistograms; |
30 class StreamSocket; | 31 class StreamSocket; |
31 | 32 |
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 void CrashIfFreed(); | |
45 | |
46 private: | |
eroman
2012/03/28 18:02:50
indentation
Ryan Hamilton
2012/03/28 18:15:44
Done.
| |
47 unsigned int magic_value_; | |
48 base::debug::StackTrace stack_trace_; | |
eroman
2012/03/28 18:02:50
Can you add corresponding TODOs to the code for la
Ryan Hamilton
2012/03/28 18:15:44
Done.
| |
49 }; | |
50 | |
32 // A ClientSocketPool is used to restrict the number of sockets open at a time. | 51 // A ClientSocketPool is used to restrict the number of sockets open at a time. |
33 // It also maintains a list of idle persistent sockets. | 52 // It also maintains a list of idle persistent sockets. |
34 // | 53 // |
35 class NET_EXPORT ClientSocketPool { | 54 class NET_EXPORT ClientSocketPool { |
36 public: | 55 public: |
37 // Requests a connected socket for a group_name. | 56 // Requests a connected socket for a group_name. |
38 // | 57 // |
39 // There are five possible results from calling this function: | 58 // There are five possible results from calling this function: |
40 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. | 59 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. |
41 // 2) RequestSocket returns OK with a newly connected socket. | 60 // 2) RequestSocket returns OK with a newly connected socket. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 virtual void ReleaseSocket(const std::string& group_name, | 122 virtual void ReleaseSocket(const std::string& group_name, |
104 StreamSocket* socket, | 123 StreamSocket* socket, |
105 int id) = 0; | 124 int id) = 0; |
106 | 125 |
107 // This flushes all state from the ClientSocketPool. This means that all | 126 // This flushes all state from the ClientSocketPool. This means that all |
108 // idle and connecting sockets are discarded. Active sockets being | 127 // idle and connecting sockets are discarded. Active sockets being |
109 // held by ClientSocketPool clients will be discarded when released back to | 128 // held by ClientSocketPool clients will be discarded when released back to |
110 // the pool. Does not flush any pools wrapped by |this|. | 129 // the pool. Does not flush any pools wrapped by |this|. |
111 virtual void Flush() = 0; | 130 virtual void Flush() = 0; |
112 | 131 |
132 // Returns true if a there is currently a request blocked on the | |
133 // per-pool (not per-host) max socket limit. | |
134 virtual bool IsStalled() const = 0; | |
135 | |
113 // Called to close any idle connections held by the connection manager. | 136 // Called to close any idle connections held by the connection manager. |
114 virtual void CloseIdleSockets() = 0; | 137 virtual void CloseIdleSockets() = 0; |
115 | 138 |
116 // The total number of idle sockets in the pool. | 139 // The total number of idle sockets in the pool. |
117 virtual int IdleSocketCount() const = 0; | 140 virtual int IdleSocketCount() const = 0; |
118 | 141 |
119 // The total number of idle sockets in a connection group. | 142 // The total number of idle sockets in a connection group. |
120 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; | 143 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; |
121 | 144 |
122 // Determine the LoadState of a connecting ClientSocketHandle. | 145 // Determine the LoadState of a connecting ClientSocketHandle. |
123 virtual LoadState GetLoadState(const std::string& group_name, | 146 virtual LoadState GetLoadState(const std::string& group_name, |
124 const ClientSocketHandle* handle) const = 0; | 147 const ClientSocketHandle* handle) const = 0; |
125 | 148 |
149 // Adds a LayeredPool on top of |this|. | |
150 virtual void AddLayeredPool(LayeredPool* layered_pool) = 0; | |
151 | |
152 // Removes a LayeredPool from |this|. | |
153 virtual void RemoveLayeredPool(LayeredPool* layered_pool) = 0; | |
154 | |
126 // Retrieves information on the current state of the pool as a | 155 // Retrieves information on the current state of the pool as a |
127 // DictionaryValue. Caller takes possession of the returned value. | 156 // DictionaryValue. Caller takes possession of the returned value. |
128 // If |include_nested_pools| is true, the states of any nested | 157 // If |include_nested_pools| is true, the states of any nested |
129 // ClientSocketPools will be included. | 158 // ClientSocketPools will be included. |
130 virtual base::DictionaryValue* GetInfoAsValue( | 159 virtual base::DictionaryValue* GetInfoAsValue( |
131 const std::string& name, | 160 const std::string& name, |
132 const std::string& type, | 161 const std::string& type, |
133 bool include_nested_pools) const = 0; | 162 bool include_nested_pools) const = 0; |
134 | 163 |
135 // Returns the maximum amount of time to wait before retrying a connect. | 164 // 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... | |
190 const scoped_refptr<SocketParams>& params, | 219 const scoped_refptr<SocketParams>& params, |
191 int num_sockets, | 220 int num_sockets, |
192 const BoundNetLog& net_log) { | 221 const BoundNetLog& net_log) { |
193 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); | 222 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); |
194 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); | 223 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); |
195 } | 224 } |
196 | 225 |
197 } // namespace net | 226 } // namespace net |
198 | 227 |
199 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 228 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |