| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "net/base/tcp_client_socket_pool.h" | 5 #include "net/base/tcp_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/field_trial.h" | 8 #include "base/field_trial.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 const ClientSocketHandle* handle, | 39 const ClientSocketHandle* handle, |
| 40 ClientSocketFactory* client_socket_factory, | 40 ClientSocketFactory* client_socket_factory, |
| 41 TCPClientSocketPool* pool) | 41 TCPClientSocketPool* pool) |
| 42 : group_name_(group_name), | 42 : group_name_(group_name), |
| 43 handle_(handle), | 43 handle_(handle), |
| 44 client_socket_factory_(client_socket_factory), | 44 client_socket_factory_(client_socket_factory), |
| 45 ALLOW_THIS_IN_INITIALIZER_LIST( | 45 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 46 callback_(this, | 46 callback_(this, |
| 47 &TCPClientSocketPool::ConnectingSocket::OnIOComplete)), | 47 &TCPClientSocketPool::ConnectingSocket::OnIOComplete)), |
| 48 pool_(pool), | 48 pool_(pool), |
| 49 resolver_(pool->GetHostResolver()), |
| 49 canceled_(false) { | 50 canceled_(false) { |
| 50 DCHECK(!ContainsKey(pool_->connecting_socket_map_, handle)); | 51 DCHECK(!ContainsKey(pool_->connecting_socket_map_, handle)); |
| 51 pool_->connecting_socket_map_[handle] = this; | 52 pool_->connecting_socket_map_[handle] = this; |
| 52 } | 53 } |
| 53 | 54 |
| 54 TCPClientSocketPool::ConnectingSocket::~ConnectingSocket() { | 55 TCPClientSocketPool::ConnectingSocket::~ConnectingSocket() { |
| 55 if (!canceled_) | 56 if (!canceled_) |
| 56 pool_->connecting_socket_map_.erase(handle_); | 57 pool_->connecting_socket_map_.erase(handle_); |
| 57 } | 58 } |
| 58 | 59 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 152 |
| 152 void TCPClientSocketPool::ConnectingSocket::Cancel() { | 153 void TCPClientSocketPool::ConnectingSocket::Cancel() { |
| 153 DCHECK(!canceled_); | 154 DCHECK(!canceled_); |
| 154 DCHECK(ContainsKey(pool_->connecting_socket_map_, handle_)); | 155 DCHECK(ContainsKey(pool_->connecting_socket_map_, handle_)); |
| 155 pool_->connecting_socket_map_.erase(handle_); | 156 pool_->connecting_socket_map_.erase(handle_); |
| 156 canceled_ = true; | 157 canceled_ = true; |
| 157 } | 158 } |
| 158 | 159 |
| 159 TCPClientSocketPool::TCPClientSocketPool( | 160 TCPClientSocketPool::TCPClientSocketPool( |
| 160 int max_sockets_per_group, | 161 int max_sockets_per_group, |
| 162 HostResolver* host_resolver, |
| 161 ClientSocketFactory* client_socket_factory) | 163 ClientSocketFactory* client_socket_factory) |
| 162 : client_socket_factory_(client_socket_factory), | 164 : client_socket_factory_(client_socket_factory), |
| 163 idle_socket_count_(0), | 165 idle_socket_count_(0), |
| 164 max_sockets_per_group_(max_sockets_per_group) { | 166 max_sockets_per_group_(max_sockets_per_group), |
| 167 host_resolver_(host_resolver) { |
| 165 } | 168 } |
| 166 | 169 |
| 167 TCPClientSocketPool::~TCPClientSocketPool() { | 170 TCPClientSocketPool::~TCPClientSocketPool() { |
| 168 // Clean up any idle sockets. Assert that we have no remaining active | 171 // Clean up any idle sockets. Assert that we have no remaining active |
| 169 // sockets or pending requests. They should have all been cleaned up prior | 172 // sockets or pending requests. They should have all been cleaned up prior |
| 170 // to the manager being destroyed. | 173 // to the manager being destroyed. |
| 171 CloseIdleSockets(); | 174 CloseIdleSockets(); |
| 172 DCHECK(group_map_.empty()); | 175 DCHECK(group_map_.empty()); |
| 173 } | 176 } |
| 174 | 177 |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 | 425 |
| 423 // Delete group if no longer needed. | 426 // Delete group if no longer needed. |
| 424 if (group.active_socket_count == 0 && group.idle_sockets.empty()) { | 427 if (group.active_socket_count == 0 && group.idle_sockets.empty()) { |
| 425 DCHECK(group.pending_requests.empty()); | 428 DCHECK(group.pending_requests.empty()); |
| 426 DCHECK(group.connecting_requests.empty()); | 429 DCHECK(group.connecting_requests.empty()); |
| 427 group_map_.erase(i); | 430 group_map_.erase(i); |
| 428 } | 431 } |
| 429 } | 432 } |
| 430 | 433 |
| 431 } // namespace net | 434 } // namespace net |
| OLD | NEW |