| 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_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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 NUM_TYPES, | 43 NUM_TYPES, |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 ClientSocketHandle(); | 46 ClientSocketHandle(); |
| 47 ~ClientSocketHandle(); | 47 ~ClientSocketHandle(); |
| 48 | 48 |
| 49 // Initializes a ClientSocketHandle object, which involves talking to the | 49 // Initializes a ClientSocketHandle object, which involves talking to the |
| 50 // ClientSocketPool to obtain a connected socket, possibly reusing one. This | 50 // ClientSocketPool to obtain a connected socket, possibly reusing one. This |
| 51 // method returns either OK or ERR_IO_PENDING. On ERR_IO_PENDING, |priority| | 51 // method returns either OK or ERR_IO_PENDING. On ERR_IO_PENDING, |priority| |
| 52 // is used to determine the placement in ClientSocketPool's wait list. | 52 // is used to determine the placement in ClientSocketPool's wait list. |
| 53 // If |respect_limits| is DISABLED, will bypass the wait list, but |priority| |
| 54 // must also be HIGHEST, if set. |
| 53 // | 55 // |
| 54 // If this method succeeds, then the socket member will be set to an existing | 56 // If this method succeeds, then the socket member will be set to an existing |
| 55 // connected socket if an existing connected socket was available to reuse, | 57 // connected socket if an existing connected socket was available to reuse, |
| 56 // otherwise it will be set to a new connected socket. Consumers can then | 58 // otherwise it will be set to a new connected socket. Consumers can then |
| 57 // call is_reused() to see if the socket was reused. If not reusing an | 59 // call is_reused() to see if the socket was reused. If not reusing an |
| 58 // existing socket, ClientSocketPool may need to establish a new | 60 // existing socket, ClientSocketPool may need to establish a new |
| 59 // connection using |socket_params|. | 61 // connection using |socket_params|. |
| 60 // | 62 // |
| 61 // This method returns ERR_IO_PENDING if it cannot complete synchronously, in | 63 // This method returns ERR_IO_PENDING if it cannot complete synchronously, in |
| 62 // which case the consumer will be notified of completion via |callback|. | 64 // which case the consumer will be notified of completion via |callback|. |
| 63 // | 65 // |
| 64 // If the pool was not able to reuse an existing socket, the new socket | 66 // If the pool was not able to reuse an existing socket, the new socket |
| 65 // may report a recoverable error. In this case, the return value will | 67 // may report a recoverable error. In this case, the return value will |
| 66 // indicate an error and the socket member will be set. If it is determined | 68 // indicate an error and the socket member will be set. If it is determined |
| 67 // that the error is not recoverable, the Disconnect method should be used | 69 // that the error is not recoverable, the Disconnect method should be used |
| 68 // on the socket, so that it does not get reused. | 70 // on the socket, so that it does not get reused. |
| 69 // | 71 // |
| 70 // A non-recoverable error may set additional state in the ClientSocketHandle | 72 // A non-recoverable error may set additional state in the ClientSocketHandle |
| 71 // to allow the caller to determine what went wrong. | 73 // to allow the caller to determine what went wrong. |
| 72 // | 74 // |
| 73 // Init may be called multiple times. | 75 // Init may be called multiple times. |
| 74 // | 76 // |
| 75 // Profiling information for the request is saved to |net_log| if non-NULL. | 77 // Profiling information for the request is saved to |net_log| if non-NULL. |
| 76 // | 78 // |
| 77 template <typename PoolType> | 79 template <typename PoolType> |
| 78 int Init(const std::string& group_name, | 80 int Init(const std::string& group_name, |
| 79 const scoped_refptr<typename PoolType::SocketParams>& socket_params, | 81 const scoped_refptr<typename PoolType::SocketParams>& socket_params, |
| 80 RequestPriority priority, | 82 RequestPriority priority, |
| 83 ClientSocketPool::RespectLimits respect_limits, |
| 81 const CompletionCallback& callback, | 84 const CompletionCallback& callback, |
| 82 PoolType* pool, | 85 PoolType* pool, |
| 83 const BoundNetLog& net_log); | 86 const BoundNetLog& net_log); |
| 84 | 87 |
| 85 // An initialized handle can be reset, which causes it to return to the | 88 // An initialized handle can be reset, which causes it to return to the |
| 86 // un-initialized state. This releases the underlying socket, which in the | 89 // un-initialized state. This releases the underlying socket, which in the |
| 87 // case of a socket that still has an established connection, indicates that | 90 // case of a socket that still has an established connection, indicates that |
| 88 // the socket may be kept alive for use by a subsequent ClientSocketHandle. | 91 // the socket may be kept alive for use by a subsequent ClientSocketHandle. |
| 89 // | 92 // |
| 90 // NOTE: To prevent the socket from being kept alive, be sure to call its | 93 // NOTE: To prevent the socket from being kept alive, be sure to call its |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 232 |
| 230 DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); | 233 DISALLOW_COPY_AND_ASSIGN(ClientSocketHandle); |
| 231 }; | 234 }; |
| 232 | 235 |
| 233 // Template function implementation: | 236 // Template function implementation: |
| 234 template <typename PoolType> | 237 template <typename PoolType> |
| 235 int ClientSocketHandle::Init( | 238 int ClientSocketHandle::Init( |
| 236 const std::string& group_name, | 239 const std::string& group_name, |
| 237 const scoped_refptr<typename PoolType::SocketParams>& socket_params, | 240 const scoped_refptr<typename PoolType::SocketParams>& socket_params, |
| 238 RequestPriority priority, | 241 RequestPriority priority, |
| 242 ClientSocketPool::RespectLimits respect_limits, |
| 239 const CompletionCallback& callback, | 243 const CompletionCallback& callback, |
| 240 PoolType* pool, | 244 PoolType* pool, |
| 241 const BoundNetLog& net_log) { | 245 const BoundNetLog& net_log) { |
| 242 requesting_source_ = net_log.source(); | 246 requesting_source_ = net_log.source(); |
| 243 | 247 |
| 244 CHECK(!group_name.empty()); | 248 CHECK(!group_name.empty()); |
| 245 ResetInternal(true); | 249 ResetInternal(true); |
| 246 ResetErrorState(); | 250 ResetErrorState(); |
| 247 pool_ = pool; | 251 pool_ = pool; |
| 248 group_name_ = group_name; | 252 group_name_ = group_name; |
| 249 init_time_ = base::TimeTicks::Now(); | 253 init_time_ = base::TimeTicks::Now(); |
| 250 int rv = pool_->RequestSocket( | 254 int rv = pool_->RequestSocket(group_name, &socket_params, priority, |
| 251 group_name, &socket_params, priority, this, callback_, net_log); | 255 respect_limits, this, callback_, net_log); |
| 252 if (rv == ERR_IO_PENDING) { | 256 if (rv == ERR_IO_PENDING) { |
| 253 user_callback_ = callback; | 257 user_callback_ = callback; |
| 254 } else { | 258 } else { |
| 255 HandleInitCompletion(rv); | 259 HandleInitCompletion(rv); |
| 256 } | 260 } |
| 257 return rv; | 261 return rv; |
| 258 } | 262 } |
| 259 | 263 |
| 260 } // namespace net | 264 } // namespace net |
| 261 | 265 |
| 262 #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ | 266 #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ |
| OLD | NEW |