| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // called. Returns false and makes no changes to |load_timing_info| when | 119 // called. Returns false and makes no changes to |load_timing_info| when |
| 120 // |socket_| is NULL. | 120 // |socket_| is NULL. |
| 121 bool GetLoadTimingInfo(bool is_reused, | 121 bool GetLoadTimingInfo(bool is_reused, |
| 122 LoadTimingInfo* load_timing_info) const; | 122 LoadTimingInfo* load_timing_info) const; |
| 123 | 123 |
| 124 // Used by ClientSocketPool to initialize the ClientSocketHandle. | 124 // Used by ClientSocketPool to initialize the ClientSocketHandle. |
| 125 // | 125 // |
| 126 // SetSocket() may also be used if this handle is used as simply for | 126 // SetSocket() may also be used if this handle is used as simply for |
| 127 // socket storage (e.g., http://crbug.com/37810). | 127 // socket storage (e.g., http://crbug.com/37810). |
| 128 void SetSocket(scoped_ptr<StreamSocket> s); | 128 void SetSocket(scoped_ptr<StreamSocket> s); |
| 129 void set_is_reused(bool is_reused) { is_reused_ = is_reused; } | 129 void set_reuse_type(SocketReuseType reuse_type) { reuse_type_ = reuse_type; } |
| 130 void set_idle_time(base::TimeDelta idle_time) { idle_time_ = idle_time; } | 130 void set_idle_time(base::TimeDelta idle_time) { idle_time_ = idle_time; } |
| 131 void set_pool_id(int id) { pool_id_ = id; } | 131 void set_pool_id(int id) { pool_id_ = id; } |
| 132 void set_is_ssl_error(bool is_ssl_error) { is_ssl_error_ = is_ssl_error; } | 132 void set_is_ssl_error(bool is_ssl_error) { is_ssl_error_ = is_ssl_error; } |
| 133 void set_ssl_error_response_info(const HttpResponseInfo& ssl_error_state) { | 133 void set_ssl_error_response_info(const HttpResponseInfo& ssl_error_state) { |
| 134 ssl_error_response_info_ = ssl_error_state; | 134 ssl_error_response_info_ = ssl_error_state; |
| 135 } | 135 } |
| 136 void set_pending_http_proxy_connection(ClientSocketHandle* connection) { | 136 void set_pending_http_proxy_connection(ClientSocketHandle* connection) { |
| 137 pending_http_proxy_connection_.reset(connection); | 137 pending_http_proxy_connection_.reset(connection); |
| 138 } | 138 } |
| 139 | 139 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 154 | 154 |
| 155 StreamSocket* socket() { return socket_.get(); } | 155 StreamSocket* socket() { return socket_.get(); } |
| 156 | 156 |
| 157 // SetSocket() must be called with a new socket before this handle | 157 // SetSocket() must be called with a new socket before this handle |
| 158 // is destroyed if is_initialized() is true. | 158 // is destroyed if is_initialized() is true. |
| 159 scoped_ptr<StreamSocket> PassSocket(); | 159 scoped_ptr<StreamSocket> PassSocket(); |
| 160 | 160 |
| 161 // These may only be used if is_initialized() is true. | 161 // These may only be used if is_initialized() is true. |
| 162 const std::string& group_name() const { return group_name_; } | 162 const std::string& group_name() const { return group_name_; } |
| 163 int id() const { return pool_id_; } | 163 int id() const { return pool_id_; } |
| 164 bool is_reused() const { return is_reused_; } | 164 bool is_reused() const { return reuse_type_ == REUSED_IDLE; } |
| 165 base::TimeDelta idle_time() const { return idle_time_; } | 165 base::TimeDelta idle_time() const { return idle_time_; } |
| 166 SocketReuseType reuse_type() const { | 166 SocketReuseType reuse_type() const { return reuse_type_; } |
| 167 if (is_reused()) { | |
| 168 return REUSED_IDLE; | |
| 169 } else if (idle_time() == base::TimeDelta()) { | |
| 170 return UNUSED; | |
| 171 } else { | |
| 172 return UNUSED_IDLE; | |
| 173 } | |
| 174 } | |
| 175 const LoadTimingInfo::ConnectTiming& connect_timing() const { | 167 const LoadTimingInfo::ConnectTiming& connect_timing() const { |
| 176 return connect_timing_; | 168 return connect_timing_; |
| 177 } | 169 } |
| 178 void set_connect_timing(const LoadTimingInfo::ConnectTiming& connect_timing) { | 170 void set_connect_timing(const LoadTimingInfo::ConnectTiming& connect_timing) { |
| 179 connect_timing_ = connect_timing; | 171 connect_timing_ = connect_timing; |
| 180 } | 172 } |
| 181 | 173 |
| 182 private: | 174 private: |
| 183 // Called on asynchronous completion of an Init() request. | 175 // Called on asynchronous completion of an Init() request. |
| 184 void OnIOComplete(int result); | 176 void OnIOComplete(int result); |
| 185 | 177 |
| 186 // Called on completion (both asynchronous & synchronous) of an Init() | 178 // Called on completion (both asynchronous & synchronous) of an Init() |
| 187 // request. | 179 // request. |
| 188 void HandleInitCompletion(int result); | 180 void HandleInitCompletion(int result); |
| 189 | 181 |
| 190 // Resets the state of the ClientSocketHandle. |cancel| indicates whether or | 182 // Resets the state of the ClientSocketHandle. |cancel| indicates whether or |
| 191 // not to try to cancel the request with the ClientSocketPool. Does not | 183 // not to try to cancel the request with the ClientSocketPool. Does not |
| 192 // reset the supplemental error state. | 184 // reset the supplemental error state. |
| 193 void ResetInternal(bool cancel); | 185 void ResetInternal(bool cancel); |
| 194 | 186 |
| 195 // Resets the supplemental error state. | 187 // Resets the supplemental error state. |
| 196 void ResetErrorState(); | 188 void ResetErrorState(); |
| 197 | 189 |
| 198 bool is_initialized_; | 190 bool is_initialized_; |
| 199 ClientSocketPool* pool_; | 191 ClientSocketPool* pool_; |
| 200 HigherLayeredPool* higher_pool_; | 192 HigherLayeredPool* higher_pool_; |
| 201 scoped_ptr<StreamSocket> socket_; | 193 scoped_ptr<StreamSocket> socket_; |
| 202 std::string group_name_; | 194 std::string group_name_; |
| 203 bool is_reused_; | 195 SocketReuseType reuse_type_; |
| 204 CompletionCallback callback_; | 196 CompletionCallback callback_; |
| 205 CompletionCallback user_callback_; | 197 CompletionCallback user_callback_; |
| 206 base::TimeDelta idle_time_; | 198 base::TimeDelta idle_time_; |
| 207 int pool_id_; // See ClientSocketPool::ReleaseSocket() for an explanation. | 199 int pool_id_; // See ClientSocketPool::ReleaseSocket() for an explanation. |
| 208 bool is_ssl_error_; | 200 bool is_ssl_error_; |
| 209 HttpResponseInfo ssl_error_response_info_; | 201 HttpResponseInfo ssl_error_response_info_; |
| 210 scoped_ptr<ClientSocketHandle> pending_http_proxy_connection_; | 202 scoped_ptr<ClientSocketHandle> pending_http_proxy_connection_; |
| 211 base::TimeTicks init_time_; | 203 base::TimeTicks init_time_; |
| 212 base::TimeDelta setup_time_; | 204 base::TimeDelta setup_time_; |
| 213 | 205 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 242 user_callback_ = callback; | 234 user_callback_ = callback; |
| 243 } else { | 235 } else { |
| 244 HandleInitCompletion(rv); | 236 HandleInitCompletion(rv); |
| 245 } | 237 } |
| 246 return rv; | 238 return rv; |
| 247 } | 239 } |
| 248 | 240 |
| 249 } // namespace net | 241 } // namespace net |
| 250 | 242 |
| 251 #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ | 243 #endif // NET_SOCKET_CLIENT_SOCKET_HANDLE_H_ |
| OLD | NEW |