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 #include "net/socket/client_socket_pool_base.h" | 5 #include "net/socket/client_socket_pool_base.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stats_counters.h" | 10 #include "base/stats_counters.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 : handle_(handle), callback_(callback), priority_(priority), | 103 : handle_(handle), callback_(callback), priority_(priority), |
104 net_log_(net_log) {} | 104 net_log_(net_log) {} |
105 | 105 |
106 ClientSocketPoolBaseHelper::Request::~Request() {} | 106 ClientSocketPoolBaseHelper::Request::~Request() {} |
107 | 107 |
108 ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( | 108 ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( |
109 int max_sockets, | 109 int max_sockets, |
110 int max_sockets_per_group, | 110 int max_sockets_per_group, |
111 base::TimeDelta unused_idle_socket_timeout, | 111 base::TimeDelta unused_idle_socket_timeout, |
112 base::TimeDelta used_idle_socket_timeout, | 112 base::TimeDelta used_idle_socket_timeout, |
113 ConnectJobFactory* connect_job_factory, | 113 ConnectJobFactory* connect_job_factory) |
114 NetworkChangeNotifier* network_change_notifier) | |
115 : idle_socket_count_(0), | 114 : idle_socket_count_(0), |
116 connecting_socket_count_(0), | 115 connecting_socket_count_(0), |
117 handed_out_socket_count_(0), | 116 handed_out_socket_count_(0), |
118 max_sockets_(max_sockets), | 117 max_sockets_(max_sockets), |
119 max_sockets_per_group_(max_sockets_per_group), | 118 max_sockets_per_group_(max_sockets_per_group), |
120 unused_idle_socket_timeout_(unused_idle_socket_timeout), | 119 unused_idle_socket_timeout_(unused_idle_socket_timeout), |
121 used_idle_socket_timeout_(used_idle_socket_timeout), | 120 used_idle_socket_timeout_(used_idle_socket_timeout), |
122 may_have_stalled_group_(false), | 121 may_have_stalled_group_(false), |
123 connect_job_factory_(connect_job_factory), | 122 connect_job_factory_(connect_job_factory), |
124 network_change_notifier_(network_change_notifier), | |
125 backup_jobs_enabled_(false), | 123 backup_jobs_enabled_(false), |
126 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 124 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
127 DCHECK_LE(0, max_sockets_per_group); | 125 DCHECK_LE(0, max_sockets_per_group); |
128 DCHECK_LE(max_sockets_per_group, max_sockets); | 126 DCHECK_LE(max_sockets_per_group, max_sockets); |
129 | |
130 if (network_change_notifier_) | |
131 network_change_notifier_->AddObserver(this); | |
132 } | 127 } |
133 | 128 |
134 ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { | 129 ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { |
135 CancelAllConnectJobs(); | 130 CancelAllConnectJobs(); |
136 | 131 |
137 // Clean up any idle sockets. Assert that we have no remaining active | 132 // Clean up any idle sockets. Assert that we have no remaining active |
138 // sockets or pending requests. They should have all been cleaned up prior | 133 // sockets or pending requests. They should have all been cleaned up prior |
139 // to the manager being destroyed. | 134 // to the manager being destroyed. |
140 CloseIdleSockets(); | 135 CloseIdleSockets(); |
141 CHECK(group_map_.empty()); | 136 CHECK(group_map_.empty()); |
142 DCHECK_EQ(0, connecting_socket_count_); | 137 DCHECK_EQ(0, connecting_socket_count_); |
143 | |
144 if (network_change_notifier_) | |
145 network_change_notifier_->RemoveObserver(this); | |
146 } | 138 } |
147 | 139 |
148 // InsertRequestIntoQueue inserts the request into the queue based on | 140 // InsertRequestIntoQueue inserts the request into the queue based on |
149 // priority. Highest priorities are closest to the front. Older requests are | 141 // priority. Highest priorities are closest to the front. Older requests are |
150 // prioritized over requests of equal priority. | 142 // prioritized over requests of equal priority. |
151 // | 143 // |
152 // static | 144 // static |
153 void ClientSocketPoolBaseHelper::InsertRequestIntoQueue( | 145 void ClientSocketPoolBaseHelper::InsertRequestIntoQueue( |
154 const Request* r, RequestQueue* pending_requests) { | 146 const Request* r, RequestQueue* pending_requests) { |
155 RequestQueue::iterator it = pending_requests->begin(); | 147 RequestQueue::iterator it = pending_requests->begin(); |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 group.pending_requests.begin(), &group.pending_requests)); | 572 group.pending_requests.begin(), &group.pending_requests)); |
581 r->net_log().AddEventWithInteger(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, | 573 r->net_log().AddEventWithInteger(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, |
582 job_log.source().id); | 574 job_log.source().id); |
583 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL); | 575 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL); |
584 r->callback()->Run(result); | 576 r->callback()->Run(result); |
585 } | 577 } |
586 MaybeOnAvailableSocketSlot(group_name); | 578 MaybeOnAvailableSocketSlot(group_name); |
587 } | 579 } |
588 } | 580 } |
589 | 581 |
590 void ClientSocketPoolBaseHelper::OnIPAddressChanged() { | |
591 CloseIdleSockets(); | |
592 } | |
593 | |
594 void ClientSocketPoolBaseHelper::RemoveConnectJob(const ConnectJob *job, | 582 void ClientSocketPoolBaseHelper::RemoveConnectJob(const ConnectJob *job, |
595 Group* group) { | 583 Group* group) { |
596 CHECK_GT(connecting_socket_count_, 0); | 584 CHECK_GT(connecting_socket_count_, 0); |
597 connecting_socket_count_--; | 585 connecting_socket_count_--; |
598 | 586 |
599 DCHECK(job); | 587 DCHECK(job); |
600 delete job; | 588 delete job; |
601 | 589 |
602 if (group) { | 590 if (group) { |
603 DCHECK(ContainsKey(group->jobs, job)); | 591 DCHECK(ContainsKey(group->jobs, job)); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 bool ClientSocketPoolBaseHelper::ReachedMaxSocketsLimit() const { | 702 bool ClientSocketPoolBaseHelper::ReachedMaxSocketsLimit() const { |
715 // Each connecting socket will eventually connect and be handed out. | 703 // Each connecting socket will eventually connect and be handed out. |
716 int total = handed_out_socket_count_ + connecting_socket_count_; | 704 int total = handed_out_socket_count_ + connecting_socket_count_; |
717 DCHECK_LE(total, max_sockets_); | 705 DCHECK_LE(total, max_sockets_); |
718 return total == max_sockets_; | 706 return total == max_sockets_; |
719 } | 707 } |
720 | 708 |
721 } // namespace internal | 709 } // namespace internal |
722 | 710 |
723 } // namespace net | 711 } // namespace net |
OLD | NEW |