Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: net/socket/client_socket_pool_base.cc

Issue 2802015: Massively simplify the NetworkChangeNotifier infrastructure:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 : handle_(handle), callback_(callback), priority_(priority), 121 : handle_(handle), callback_(callback), priority_(priority),
122 net_log_(net_log) {} 122 net_log_(net_log) {}
123 123
124 ClientSocketPoolBaseHelper::Request::~Request() {} 124 ClientSocketPoolBaseHelper::Request::~Request() {}
125 125
126 ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( 126 ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper(
127 int max_sockets, 127 int max_sockets,
128 int max_sockets_per_group, 128 int max_sockets_per_group,
129 base::TimeDelta unused_idle_socket_timeout, 129 base::TimeDelta unused_idle_socket_timeout,
130 base::TimeDelta used_idle_socket_timeout, 130 base::TimeDelta used_idle_socket_timeout,
131 ConnectJobFactory* connect_job_factory, 131 ConnectJobFactory* connect_job_factory)
132 NetworkChangeNotifier* network_change_notifier)
133 : idle_socket_count_(0), 132 : idle_socket_count_(0),
134 connecting_socket_count_(0), 133 connecting_socket_count_(0),
135 handed_out_socket_count_(0), 134 handed_out_socket_count_(0),
136 num_releasing_sockets_(0), 135 num_releasing_sockets_(0),
137 max_sockets_(max_sockets), 136 max_sockets_(max_sockets),
138 max_sockets_per_group_(max_sockets_per_group), 137 max_sockets_per_group_(max_sockets_per_group),
139 unused_idle_socket_timeout_(unused_idle_socket_timeout), 138 unused_idle_socket_timeout_(unused_idle_socket_timeout),
140 used_idle_socket_timeout_(used_idle_socket_timeout), 139 used_idle_socket_timeout_(used_idle_socket_timeout),
141 may_have_stalled_group_(false), 140 may_have_stalled_group_(false),
142 connect_job_factory_(connect_job_factory), 141 connect_job_factory_(connect_job_factory),
143 network_change_notifier_(network_change_notifier),
144 backup_jobs_enabled_(false), 142 backup_jobs_enabled_(false),
145 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 143 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
146 pool_generation_number_(0) { 144 pool_generation_number_(0) {
147 DCHECK_LE(0, max_sockets_per_group); 145 DCHECK_LE(0, max_sockets_per_group);
148 DCHECK_LE(max_sockets_per_group, max_sockets); 146 DCHECK_LE(max_sockets_per_group, max_sockets);
149 147
150 if (network_change_notifier_) 148 NetworkChangeNotifier::AddObserver(this);
151 network_change_notifier_->AddObserver(this);
152 } 149 }
153 150
154 ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { 151 ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() {
155 CancelAllConnectJobs(); 152 CancelAllConnectJobs();
156 153
157 // Clean up any idle sockets. Assert that we have no remaining active 154 // Clean up any idle sockets. Assert that we have no remaining active
158 // sockets or pending requests. They should have all been cleaned up prior 155 // sockets or pending requests. They should have all been cleaned up prior
159 // to the manager being destroyed. 156 // to the manager being destroyed.
160 CloseIdleSockets(); 157 CloseIdleSockets();
161 CHECK(group_map_.empty()); 158 CHECK(group_map_.empty());
162 DCHECK_EQ(0, connecting_socket_count_); 159 DCHECK_EQ(0, connecting_socket_count_);
163 160
164 if (network_change_notifier_) 161 NetworkChangeNotifier::RemoveObserver(this);
165 network_change_notifier_->RemoveObserver(this);
166 } 162 }
167 163
168 // InsertRequestIntoQueue inserts the request into the queue based on 164 // InsertRequestIntoQueue inserts the request into the queue based on
169 // priority. Highest priorities are closest to the front. Older requests are 165 // priority. Highest priorities are closest to the front. Older requests are
170 // prioritized over requests of equal priority. 166 // prioritized over requests of equal priority.
171 // 167 //
172 // static 168 // static
173 void ClientSocketPoolBaseHelper::InsertRequestIntoQueue( 169 void ClientSocketPoolBaseHelper::InsertRequestIntoQueue(
174 const Request* r, RequestQueue* pending_requests) { 170 const Request* r, RequestQueue* pending_requests) {
175 RequestQueue::iterator it = pending_requests->begin(); 171 RequestQueue::iterator it = pending_requests->begin();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name, 372 void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name,
377 ClientSocket* socket, 373 ClientSocket* socket,
378 int id) { 374 int id) {
379 Group& group = group_map_[group_name]; 375 Group& group = group_map_[group_name];
380 group.num_releasing_sockets++; 376 group.num_releasing_sockets++;
381 num_releasing_sockets_++; 377 num_releasing_sockets_++;
382 DCHECK_LE(group.num_releasing_sockets, group.active_socket_count); 378 DCHECK_LE(group.num_releasing_sockets, group.active_socket_count);
383 // Run this asynchronously to allow the caller to finish before we let 379 // Run this asynchronously to allow the caller to finish before we let
384 // another to begin doing work. This also avoids nasty recursion issues. 380 // another to begin doing work. This also avoids nasty recursion issues.
385 // NOTE: We cannot refer to the handle argument after this method returns. 381 // NOTE: We cannot refer to the handle argument after this method returns.
386 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 382 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
387 this, &ClientSocketPoolBaseHelper::DoReleaseSocket, group_name, socket, id )); 383 &ClientSocketPoolBaseHelper::DoReleaseSocket, group_name, socket, id));
388 } 384 }
389 385
390 void ClientSocketPoolBaseHelper::CloseIdleSockets() { 386 void ClientSocketPoolBaseHelper::CloseIdleSockets() {
391 CleanupIdleSockets(true); 387 CleanupIdleSockets(true);
392 } 388 }
393 389
394 int ClientSocketPoolBaseHelper::IdleSocketCountInGroup( 390 int ClientSocketPoolBaseHelper::IdleSocketCountInGroup(
395 const std::string& group_name) const { 391 const std::string& group_name) const {
396 GroupMap::const_iterator i = group_map_.find(group_name); 392 GroupMap::const_iterator i = group_map_.find(group_name);
397 CHECK(i != group_map_.end()); 393 CHECK(i != group_map_.end());
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 group.pending_requests.begin(), &group.pending_requests)); 629 group.pending_requests.begin(), &group.pending_requests));
634 LogBoundConnectJobToRequest(job_log.source(), r.get()); 630 LogBoundConnectJobToRequest(job_log.source(), r.get());
635 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, 631 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL,
636 new NetLogIntegerParameter("net_error", result)); 632 new NetLogIntegerParameter("net_error", result));
637 r->callback()->Run(result); 633 r->callback()->Run(result);
638 } 634 }
639 MaybeOnAvailableSocketSlot(group_name); 635 MaybeOnAvailableSocketSlot(group_name);
640 } 636 }
641 } 637 }
642 638
639 void ClientSocketPoolBaseHelper::OnIPAddressChanged() {
640 Flush();
641 }
642
643 void ClientSocketPoolBaseHelper::Flush() { 643 void ClientSocketPoolBaseHelper::Flush() {
644 pool_generation_number_++; 644 pool_generation_number_++;
645 CancelAllConnectJobs(); 645 CancelAllConnectJobs();
646 CloseIdleSockets(); 646 CloseIdleSockets();
647 } 647 }
648 648
649 void ClientSocketPoolBaseHelper::RemoveConnectJob(const ConnectJob *job, 649 void ClientSocketPoolBaseHelper::RemoveConnectJob(const ConnectJob *job,
650 Group* group) { 650 Group* group) {
651 CHECK_GT(connecting_socket_count_, 0); 651 CHECK_GT(connecting_socket_count_, 0);
652 connecting_socket_count_--; 652 connecting_socket_count_--;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 return; 801 return;
802 } 802 }
803 } 803 }
804 804
805 LOG(DFATAL) << "No idle socket found to close!."; 805 LOG(DFATAL) << "No idle socket found to close!.";
806 } 806 }
807 807
808 } // namespace internal 808 } // namespace internal
809 809
810 } // namespace net 810 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698