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

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

Issue 2250001: Fixes an invalid read bug in ClientSocketPoolBaseHelper and cancels ConnectJobs on network changes. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Redo. Created 10 years, 7 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
« no previous file with comments | « no previous file | net/socket/client_socket_pool_base_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 connecting_socket_count_++; 325 connecting_socket_count_++;
326 group.jobs.insert(group.backup_job); 326 group.jobs.insert(group.backup_job);
327 ConnectJob* job = group.backup_job; 327 ConnectJob* job = group.backup_job;
328 group.backup_job = NULL; 328 group.backup_job = NULL;
329 if (rv != ERR_IO_PENDING) 329 if (rv != ERR_IO_PENDING)
330 OnConnectJobComplete(rv, job); 330 OnConnectJobComplete(rv, job);
331 } 331 }
332 332
333 void ClientSocketPoolBaseHelper::CancelRequest( 333 void ClientSocketPoolBaseHelper::CancelRequest(
334 const std::string& group_name, const ClientSocketHandle* handle) { 334 const std::string& group_name, const ClientSocketHandle* handle) {
335 // Running callbacks can cause the last outside reference to be released.
336 // Hold onto a reference.
337 scoped_refptr<ClientSocketPoolBaseHelper> ref_holder(this);
338
335 CHECK(ContainsKey(group_map_, group_name)); 339 CHECK(ContainsKey(group_map_, group_name));
336 340
337 Group& group = group_map_[group_name]; 341 Group& group = group_map_[group_name];
338 342
339 // Search pending_requests for matching handle. 343 // Search pending_requests for matching handle.
340 RequestQueue::iterator it = group.pending_requests.begin(); 344 RequestQueue::iterator it = group.pending_requests.begin();
341 for (; it != group.pending_requests.end(); ++it) { 345 for (; it != group.pending_requests.end(); ++it) {
342 if ((*it)->handle() == handle) { 346 if ((*it)->handle() == handle) {
343 const Request* req = RemoveRequestFromQueue(it, &group.pending_requests); 347 const Request* req = RemoveRequestFromQueue(it, &group.pending_requests);
344 req->net_log().AddEvent(NetLog::TYPE_CANCELLED, NULL); 348 req->net_log().AddEvent(NetLog::TYPE_CANCELLED, NULL);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 &ClientSocketPoolBaseHelper::OnCleanupTimerFired); 467 &ClientSocketPoolBaseHelper::OnCleanupTimerFired);
464 } 468 }
465 469
466 void ClientSocketPoolBaseHelper::DecrementIdleCount() { 470 void ClientSocketPoolBaseHelper::DecrementIdleCount() {
467 if (--idle_socket_count_ == 0) 471 if (--idle_socket_count_ == 0)
468 timer_.Stop(); 472 timer_.Stop();
469 } 473 }
470 474
471 void ClientSocketPoolBaseHelper::DoReleaseSocket(const std::string& group_name, 475 void ClientSocketPoolBaseHelper::DoReleaseSocket(const std::string& group_name,
472 ClientSocket* socket) { 476 ClientSocket* socket) {
477 // Running callbacks can cause the last outside reference to be released.
478 // Hold onto a reference.
479 scoped_refptr<ClientSocketPoolBaseHelper> ref_holder(this);
480
473 GroupMap::iterator i = group_map_.find(group_name); 481 GroupMap::iterator i = group_map_.find(group_name);
474 CHECK(i != group_map_.end()); 482 CHECK(i != group_map_.end());
475 483
476 Group& group = i->second; 484 Group& group = i->second;
477 485
478 group.num_releasing_sockets--; 486 group.num_releasing_sockets--;
479 DCHECK_GE(group.num_releasing_sockets, 0); 487 DCHECK_GE(group.num_releasing_sockets, 0);
480 488
481 CHECK_GT(handed_out_socket_count_, 0); 489 CHECK_GT(handed_out_socket_count_, 0);
482 handed_out_socket_count_--; 490 handed_out_socket_count_--;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 } 564 }
557 if (top_group) { 565 if (top_group) {
558 *group = top_group; 566 *group = top_group;
559 *group_name = *top_group_name; 567 *group_name = *top_group_name;
560 } 568 }
561 return stalled_group_count; 569 return stalled_group_count;
562 } 570 }
563 571
564 void ClientSocketPoolBaseHelper::OnConnectJobComplete( 572 void ClientSocketPoolBaseHelper::OnConnectJobComplete(
565 int result, ConnectJob* job) { 573 int result, ConnectJob* job) {
574 // Running callbacks can cause the last outside reference to be released.
575 // Hold onto a reference.
576 scoped_refptr<ClientSocketPoolBaseHelper> ref_holder(this);
577
566 DCHECK_NE(ERR_IO_PENDING, result); 578 DCHECK_NE(ERR_IO_PENDING, result);
567 const std::string group_name = job->group_name(); 579 const std::string group_name = job->group_name();
568 GroupMap::iterator group_it = group_map_.find(group_name); 580 GroupMap::iterator group_it = group_map_.find(group_name);
569 CHECK(group_it != group_map_.end()); 581 CHECK(group_it != group_map_.end());
570 Group& group = group_it->second; 582 Group& group = group_it->second;
571 583
572 // We've had a connect on the socket; discard any pending backup job 584 // We've had a connect on the socket; discard any pending backup job
573 // for this group and kill the pending task. 585 // for this group and kill the pending task.
574 group.CleanupBackupJob(); 586 group.CleanupBackupJob();
575 587
(...skipping 28 matching lines...) Expand all
604 NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, 616 NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID,
605 new NetLogIntegerParameter("source_id", job_log.source().id)); 617 new NetLogIntegerParameter("source_id", job_log.source().id));
606 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); 618 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL);
607 r->callback()->Run(result); 619 r->callback()->Run(result);
608 } 620 }
609 MaybeOnAvailableSocketSlot(group_name); 621 MaybeOnAvailableSocketSlot(group_name);
610 } 622 }
611 } 623 }
612 624
613 void ClientSocketPoolBaseHelper::OnIPAddressChanged() { 625 void ClientSocketPoolBaseHelper::OnIPAddressChanged() {
626 CancelAllConnectJobs();
614 CloseIdleSockets(); 627 CloseIdleSockets();
615 } 628 }
616 629
617 void ClientSocketPoolBaseHelper::RemoveConnectJob(const ConnectJob *job, 630 void ClientSocketPoolBaseHelper::RemoveConnectJob(const ConnectJob *job,
618 Group* group) { 631 Group* group) {
619 CHECK_GT(connecting_socket_count_, 0); 632 CHECK_GT(connecting_socket_count_, 0);
620 connecting_socket_count_--; 633 connecting_socket_count_--;
621 634
622 DCHECK(job); 635 DCHECK(job);
623 delete job; 636 delete job;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 DCHECK_LE(total, max_sockets_); 755 DCHECK_LE(total, max_sockets_);
743 if (total < max_sockets_) 756 if (total < max_sockets_)
744 return false; 757 return false;
745 LOG(WARNING) << "ReachedMaxSocketsLimit: " << total << "/" << max_sockets_; 758 LOG(WARNING) << "ReachedMaxSocketsLimit: " << total << "/" << max_sockets_;
746 return true; 759 return true;
747 } 760 }
748 761
749 } // namespace internal 762 } // namespace internal
750 763
751 } // namespace net 764 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/socket/client_socket_pool_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698