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