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

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

Issue 2678353003: Close idle H2 sockets when SpdySession is initialized. (Closed)
Patch Set: Address comments to hook directly to ClientSocketHandle Created 3 years, 9 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 | « net/socket/client_socket_pool_base.h ('k') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 613
614 bool ClientSocketPoolBaseHelper::HasGroup(const std::string& group_name) const { 614 bool ClientSocketPoolBaseHelper::HasGroup(const std::string& group_name) const {
615 return base::ContainsKey(group_map_, group_name); 615 return base::ContainsKey(group_map_, group_name);
616 } 616 }
617 617
618 void ClientSocketPoolBaseHelper::CloseIdleSockets() { 618 void ClientSocketPoolBaseHelper::CloseIdleSockets() {
619 CleanupIdleSockets(true); 619 CleanupIdleSockets(true);
620 DCHECK_EQ(0, idle_socket_count_); 620 DCHECK_EQ(0, idle_socket_count_);
621 } 621 }
622 622
623 void ClientSocketPoolBaseHelper::CloseIdleSocketsInGroup(
624 const std::string& group_name) {
625 if (idle_socket_count_ == 0)
626 return;
627 GroupMap::iterator it = group_map_.find(group_name);
628 if (it == group_map_.end())
629 return;
630 CleanupIdleSocketsInGroup(true, it->second, base::TimeTicks::Now());
631 if (it->second->IsEmpty())
632 RemoveGroup(it);
633 }
634
623 int ClientSocketPoolBaseHelper::IdleSocketCountInGroup( 635 int ClientSocketPoolBaseHelper::IdleSocketCountInGroup(
624 const std::string& group_name) const { 636 const std::string& group_name) const {
625 GroupMap::const_iterator i = group_map_.find(group_name); 637 GroupMap::const_iterator i = group_map_.find(group_name);
626 CHECK(i != group_map_.end()); 638 CHECK(i != group_map_.end());
627 639
628 return i->second->idle_sockets().size(); 640 return i->second->idle_sockets().size();
629 } 641 }
630 642
631 LoadState ClientSocketPoolBaseHelper::GetLoadState( 643 LoadState ClientSocketPoolBaseHelper::GetLoadState(
632 const std::string& group_name, 644 const std::string& group_name,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 if (idle_socket_count_ == 0) 778 if (idle_socket_count_ == 0)
767 return; 779 return;
768 780
769 // Current time value. Retrieving it once at the function start rather than 781 // Current time value. Retrieving it once at the function start rather than
770 // inside the inner loop, since it shouldn't change by any meaningful amount. 782 // inside the inner loop, since it shouldn't change by any meaningful amount.
771 base::TimeTicks now = base::TimeTicks::Now(); 783 base::TimeTicks now = base::TimeTicks::Now();
772 784
773 GroupMap::iterator i = group_map_.begin(); 785 GroupMap::iterator i = group_map_.begin();
774 while (i != group_map_.end()) { 786 while (i != group_map_.end()) {
775 Group* group = i->second; 787 Group* group = i->second;
776 788 CleanupIdleSocketsInGroup(force, group, now);
777 auto idle_socket_it = group->mutable_idle_sockets()->begin();
778 while (idle_socket_it != group->idle_sockets().end()) {
779 base::TimeDelta timeout = idle_socket_it->socket->WasEverUsed()
780 ? used_idle_socket_timeout_
781 : unused_idle_socket_timeout_;
782 bool timed_out = (now - idle_socket_it->start_time) >= timeout;
783 bool should_clean_up = force || timed_out || !idle_socket_it->IsUsable();
784 if (should_clean_up) {
785 if (force) {
786 RecordIdleSocketFate(IDLE_SOCKET_FATE_CLEAN_UP_FORCED);
787 } else if (timed_out) {
788 RecordIdleSocketFate(
789 idle_socket_it->socket->WasEverUsed()
790 ? IDLE_SOCKET_FATE_CLEAN_UP_TIMED_OUT_REUSED
791 : IDLE_SOCKET_FATE_CLEAN_UP_TIMED_OUT_UNUSED);
792 } else {
793 DCHECK(!idle_socket_it->IsUsable());
794 RecordIdleSocketFate(IDLE_SOCKET_FATE_CLEAN_UP_UNUSABLE);
795 }
796 delete idle_socket_it->socket;
797 idle_socket_it = group->mutable_idle_sockets()->erase(idle_socket_it);
798 DecrementIdleCount();
799 } else {
800 ++idle_socket_it;
801 }
802 }
803
804 // Delete group if no longer needed. 789 // Delete group if no longer needed.
805 if (group->IsEmpty()) { 790 if (group->IsEmpty()) {
806 RemoveGroup(i++); 791 RemoveGroup(i++);
807 } else { 792 } else {
808 ++i; 793 ++i;
809 } 794 }
810 } 795 }
811 } 796 }
812 797
798 void ClientSocketPoolBaseHelper::CleanupIdleSocketsInGroup(
799 bool force,
800 Group* group,
801 const base::TimeTicks& now) {
802 auto idle_socket_it = group->mutable_idle_sockets()->begin();
803 while (idle_socket_it != group->idle_sockets().end()) {
804 base::TimeDelta timeout = idle_socket_it->socket->WasEverUsed()
805 ? used_idle_socket_timeout_
806 : unused_idle_socket_timeout_;
807 bool timed_out = (now - idle_socket_it->start_time) >= timeout;
808 bool should_clean_up = force || timed_out || !idle_socket_it->IsUsable();
809 if (should_clean_up) {
810 if (force) {
811 RecordIdleSocketFate(IDLE_SOCKET_FATE_CLEAN_UP_FORCED);
812 } else if (timed_out) {
813 RecordIdleSocketFate(idle_socket_it->socket->WasEverUsed()
814 ? IDLE_SOCKET_FATE_CLEAN_UP_TIMED_OUT_REUSED
815 : IDLE_SOCKET_FATE_CLEAN_UP_TIMED_OUT_UNUSED);
816 } else {
817 DCHECK(!idle_socket_it->IsUsable());
818 RecordIdleSocketFate(IDLE_SOCKET_FATE_CLEAN_UP_UNUSABLE);
819 }
820 delete idle_socket_it->socket;
821 idle_socket_it = group->mutable_idle_sockets()->erase(idle_socket_it);
822 DecrementIdleCount();
823 } else {
824 ++idle_socket_it;
825 }
826 }
827 }
828
813 ClientSocketPoolBaseHelper::Group* ClientSocketPoolBaseHelper::GetOrCreateGroup( 829 ClientSocketPoolBaseHelper::Group* ClientSocketPoolBaseHelper::GetOrCreateGroup(
814 const std::string& group_name) { 830 const std::string& group_name) {
815 GroupMap::iterator it = group_map_.find(group_name); 831 GroupMap::iterator it = group_map_.find(group_name);
816 if (it != group_map_.end()) 832 if (it != group_map_.end())
817 return it->second; 833 return it->second;
818 Group* group = new Group; 834 Group* group = new Group;
819 group_map_[group_name] = group; 835 group_map_[group_name] = group;
820 return group; 836 return group;
821 } 837 }
822 838
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 // If there are no more requests, kill the backup timer. 1484 // If there are no more requests, kill the backup timer.
1469 if (pending_requests_.empty()) 1485 if (pending_requests_.empty())
1470 backup_job_timer_.Stop(); 1486 backup_job_timer_.Stop();
1471 request->CrashIfInvalid(); 1487 request->CrashIfInvalid();
1472 return request; 1488 return request;
1473 } 1489 }
1474 1490
1475 } // namespace internal 1491 } // namespace internal
1476 1492
1477 } // namespace net 1493 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base.h ('k') | net/socket/client_socket_pool_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698