OLD | NEW |
1 // Copyright (c) 2010 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_CLIENT_SOCKET_HANDLE_H_ | 5 #ifndef NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ |
6 #define NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ | 6 #define NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.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 "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
15 #include "net/base/load_states.h" | 15 #include "net/base/load_states.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/base/net_log.h" |
17 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
18 #include "net/socket/client_socket.h" | 19 #include "net/socket/client_socket.h" |
19 #include "net/socket/client_socket_pool.h" | 20 #include "net/socket/client_socket_pool.h" |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 // A container for a ClientSocket. | 24 // A container for a ClientSocket. |
24 // | 25 // |
25 // The handle's |group_name| uniquely identifies the origin and type of the | 26 // The handle's |group_name| uniquely identifies the origin and type of the |
26 // connection. It is used by the ClientSocketPool to group similar connected | 27 // connection. It is used by the ClientSocketPool to group similar connected |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 scoped_refptr<ClientSocketPool> pool_; | 138 scoped_refptr<ClientSocketPool> pool_; |
138 scoped_ptr<ClientSocket> socket_; | 139 scoped_ptr<ClientSocket> socket_; |
139 std::string group_name_; | 140 std::string group_name_; |
140 bool is_reused_; | 141 bool is_reused_; |
141 CompletionCallbackImpl<ClientSocketHandle> callback_; | 142 CompletionCallbackImpl<ClientSocketHandle> callback_; |
142 CompletionCallback* user_callback_; | 143 CompletionCallback* user_callback_; |
143 base::TimeDelta idle_time_; | 144 base::TimeDelta idle_time_; |
144 base::TimeTicks init_time_; | 145 base::TimeTicks init_time_; |
145 base::TimeDelta setup_time_; | 146 base::TimeDelta setup_time_; |
146 | 147 |
| 148 NetLog::Source requesting_source_; |
| 149 |
147 DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); | 150 DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); |
148 }; | 151 }; |
149 | 152 |
150 // Template function implementation: | 153 // Template function implementation: |
151 template <typename SocketParams, typename PoolType> | 154 template <typename SocketParams, typename PoolType> |
152 int ClientSocketHandle::Init(const std::string& group_name, | 155 int ClientSocketHandle::Init(const std::string& group_name, |
153 const SocketParams& socket_params, | 156 const SocketParams& socket_params, |
154 RequestPriority priority, | 157 RequestPriority priority, |
155 CompletionCallback* callback, | 158 CompletionCallback* callback, |
156 const scoped_refptr<PoolType>& pool, | 159 const scoped_refptr<PoolType>& pool, |
157 const BoundNetLog& net_log) { | 160 const BoundNetLog& net_log) { |
| 161 requesting_source_ = net_log.source(); |
| 162 |
158 CHECK(!group_name.empty()); | 163 CHECK(!group_name.empty()); |
159 // Note that this will result in a link error if the SocketParams has not been | 164 // Note that this will result in a link error if the SocketParams has not been |
160 // registered for the PoolType via REGISTER_SOCKET_PARAMS_FOR_POOL (defined in | 165 // registered for the PoolType via REGISTER_SOCKET_PARAMS_FOR_POOL (defined in |
161 // client_socket_pool.h). | 166 // client_socket_pool.h). |
162 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); | 167 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); |
163 ResetInternal(true); | 168 ResetInternal(true); |
164 pool_ = pool; | 169 pool_ = pool; |
165 group_name_ = group_name; | 170 group_name_ = group_name; |
166 init_time_ = base::TimeTicks::Now(); | 171 init_time_ = base::TimeTicks::Now(); |
167 int rv = pool_->RequestSocket( | 172 int rv = pool_->RequestSocket( |
168 group_name, &socket_params, priority, this, &callback_, net_log); | 173 group_name, &socket_params, priority, this, &callback_, net_log); |
169 if (rv == ERR_IO_PENDING) { | 174 if (rv == ERR_IO_PENDING) { |
170 user_callback_ = callback; | 175 user_callback_ = callback; |
171 } else { | 176 } else { |
172 HandleInitCompletion(rv); | 177 HandleInitCompletion(rv); |
173 } | 178 } |
174 return rv; | 179 return rv; |
175 } | 180 } |
176 | 181 |
177 } // namespace net | 182 } // namespace net |
178 | 183 |
179 #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ | 184 #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ |
OLD | NEW |