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 // A ClientSocketPoolBase is used to restrict the number of sockets open at | 5 // A ClientSocketPoolBase is used to restrict the number of sockets open at |
6 // a time. It also maintains a list of idle persistent sockets for reuse. | 6 // a time. It also maintains a list of idle persistent sockets for reuse. |
7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle | 7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle |
8 // the core logic of (1) restricting the number of active (connected or | 8 // the core logic of (1) restricting the number of active (connected or |
9 // connecting) sockets per "group" (generally speaking, the hostname), (2) | 9 // connecting) sockets per "group" (generally speaking, the hostname), (2) |
10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) | 10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 ClientSocketPoolBaseHelper( | 170 ClientSocketPoolBaseHelper( |
171 int max_sockets, | 171 int max_sockets, |
172 int max_sockets_per_group, | 172 int max_sockets_per_group, |
173 base::TimeDelta unused_idle_socket_timeout, | 173 base::TimeDelta unused_idle_socket_timeout, |
174 base::TimeDelta used_idle_socket_timeout, | 174 base::TimeDelta used_idle_socket_timeout, |
175 ConnectJobFactory* connect_job_factory, | 175 ConnectJobFactory* connect_job_factory, |
176 NetworkChangeNotifier* network_change_notifier); | 176 NetworkChangeNotifier* network_change_notifier); |
177 | 177 |
178 // See ClientSocketPool::RequestSocket for documentation on this function. | 178 // See ClientSocketPool::RequestSocket for documentation on this function. |
179 // Note that |request| must be heap allocated. If ERR_IO_PENDING is returned, | 179 // ClientSocketPoolBaseHelper takes ownership of |request|, which must be |
180 // then ClientSocketPoolBaseHelper takes ownership of |request|. | 180 // heap allocated. |
181 int RequestSocket(const std::string& group_name, const Request* request); | 181 int RequestSocket(const std::string& group_name, const Request* request); |
182 | 182 |
183 // See ClientSocketPool::CancelRequest for documentation on this function. | 183 // See ClientSocketPool::CancelRequest for documentation on this function. |
184 void CancelRequest(const std::string& group_name, | 184 void CancelRequest(const std::string& group_name, |
185 const ClientSocketHandle* handle); | 185 const ClientSocketHandle* handle); |
186 | 186 |
187 // See ClientSocketPool::ReleaseSocket for documentation on this function. | 187 // See ClientSocketPool::ReleaseSocket for documentation on this function. |
188 void ReleaseSocket(const std::string& group_name, | 188 void ReleaseSocket(const std::string& group_name, |
189 ClientSocket* socket); | 189 ClientSocket* socket); |
190 | 190 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 | 519 |
520 // RequestSocket bundles up the parameters into a Request and then forwards to | 520 // RequestSocket bundles up the parameters into a Request and then forwards to |
521 // ClientSocketPoolBaseHelper::RequestSocket(). Note that the memory | 521 // ClientSocketPoolBaseHelper::RequestSocket(). Note that the memory |
522 // ownership is transferred in the asynchronous (ERR_IO_PENDING) case. | 522 // ownership is transferred in the asynchronous (ERR_IO_PENDING) case. |
523 int RequestSocket(const std::string& group_name, | 523 int RequestSocket(const std::string& group_name, |
524 const SocketParams& params, | 524 const SocketParams& params, |
525 RequestPriority priority, | 525 RequestPriority priority, |
526 ClientSocketHandle* handle, | 526 ClientSocketHandle* handle, |
527 CompletionCallback* callback, | 527 CompletionCallback* callback, |
528 const BoundNetLog& net_log) { | 528 const BoundNetLog& net_log) { |
529 scoped_ptr<Request> request( | 529 Request* request = new Request(handle, callback, priority, params, net_log); |
530 new Request(handle, callback, priority, params, net_log)); | 530 return helper_->RequestSocket(group_name, request); |
531 int rv = helper_->RequestSocket(group_name, request.get()); | |
532 if (rv == ERR_IO_PENDING) | |
533 request.release(); | |
534 return rv; | |
535 } | 531 } |
536 | 532 |
537 void CancelRequest(const std::string& group_name, | 533 void CancelRequest(const std::string& group_name, |
538 const ClientSocketHandle* handle) { | 534 const ClientSocketHandle* handle) { |
539 return helper_->CancelRequest(group_name, handle); | 535 return helper_->CancelRequest(group_name, handle); |
540 } | 536 } |
541 | 537 |
542 void ReleaseSocket(const std::string& group_name, ClientSocket* socket) { | 538 void ReleaseSocket(const std::string& group_name, ClientSocket* socket) { |
543 return helper_->ReleaseSocket(group_name, socket); | 539 return helper_->ReleaseSocket(group_name, socket); |
544 } | 540 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 // the posting of the task and the execution, then we'll hit the DCHECK that | 620 // the posting of the task and the execution, then we'll hit the DCHECK that |
625 // |ClientSocketPoolBaseHelper::group_map_| is empty. | 621 // |ClientSocketPoolBaseHelper::group_map_| is empty. |
626 scoped_refptr<internal::ClientSocketPoolBaseHelper> helper_; | 622 scoped_refptr<internal::ClientSocketPoolBaseHelper> helper_; |
627 | 623 |
628 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 624 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
629 }; | 625 }; |
630 | 626 |
631 } // namespace net | 627 } // namespace net |
632 | 628 |
633 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 629 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
OLD | NEW |