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

Unified 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, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/client_socket_pool_base.cc
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index 15accce274fd58506fae8f5c17d6a300e7b371f1..8e89a9affd35eca4f2e27d6fbeaf212c88e52894 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -620,6 +620,18 @@ void ClientSocketPoolBaseHelper::CloseIdleSockets() {
DCHECK_EQ(0, idle_socket_count_);
}
+void ClientSocketPoolBaseHelper::CloseIdleSocketsInGroup(
+ const std::string& group_name) {
+ if (idle_socket_count_ == 0)
+ return;
+ GroupMap::iterator it = group_map_.find(group_name);
+ if (it == group_map_.end())
+ return;
+ CleanupIdleSocketsInGroup(true, it->second, base::TimeTicks::Now());
+ if (it->second->IsEmpty())
+ RemoveGroup(it);
+}
+
int ClientSocketPoolBaseHelper::IdleSocketCountInGroup(
const std::string& group_name) const {
GroupMap::const_iterator i = group_map_.find(group_name);
@@ -773,34 +785,7 @@ void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) {
GroupMap::iterator i = group_map_.begin();
while (i != group_map_.end()) {
Group* group = i->second;
-
- auto idle_socket_it = group->mutable_idle_sockets()->begin();
- while (idle_socket_it != group->idle_sockets().end()) {
- base::TimeDelta timeout = idle_socket_it->socket->WasEverUsed()
- ? used_idle_socket_timeout_
- : unused_idle_socket_timeout_;
- bool timed_out = (now - idle_socket_it->start_time) >= timeout;
- bool should_clean_up = force || timed_out || !idle_socket_it->IsUsable();
- if (should_clean_up) {
- if (force) {
- RecordIdleSocketFate(IDLE_SOCKET_FATE_CLEAN_UP_FORCED);
- } else if (timed_out) {
- RecordIdleSocketFate(
- idle_socket_it->socket->WasEverUsed()
- ? IDLE_SOCKET_FATE_CLEAN_UP_TIMED_OUT_REUSED
- : IDLE_SOCKET_FATE_CLEAN_UP_TIMED_OUT_UNUSED);
- } else {
- DCHECK(!idle_socket_it->IsUsable());
- RecordIdleSocketFate(IDLE_SOCKET_FATE_CLEAN_UP_UNUSABLE);
- }
- delete idle_socket_it->socket;
- idle_socket_it = group->mutable_idle_sockets()->erase(idle_socket_it);
- DecrementIdleCount();
- } else {
- ++idle_socket_it;
- }
- }
-
+ CleanupIdleSocketsInGroup(force, group, now);
// Delete group if no longer needed.
if (group->IsEmpty()) {
RemoveGroup(i++);
@@ -810,6 +795,37 @@ void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) {
}
}
+void ClientSocketPoolBaseHelper::CleanupIdleSocketsInGroup(
+ bool force,
+ Group* group,
+ const base::TimeTicks& now) {
+ auto idle_socket_it = group->mutable_idle_sockets()->begin();
+ while (idle_socket_it != group->idle_sockets().end()) {
+ base::TimeDelta timeout = idle_socket_it->socket->WasEverUsed()
+ ? used_idle_socket_timeout_
+ : unused_idle_socket_timeout_;
+ bool timed_out = (now - idle_socket_it->start_time) >= timeout;
+ bool should_clean_up = force || timed_out || !idle_socket_it->IsUsable();
+ if (should_clean_up) {
+ if (force) {
+ RecordIdleSocketFate(IDLE_SOCKET_FATE_CLEAN_UP_FORCED);
+ } else if (timed_out) {
+ RecordIdleSocketFate(idle_socket_it->socket->WasEverUsed()
+ ? IDLE_SOCKET_FATE_CLEAN_UP_TIMED_OUT_REUSED
+ : IDLE_SOCKET_FATE_CLEAN_UP_TIMED_OUT_UNUSED);
+ } else {
+ DCHECK(!idle_socket_it->IsUsable());
+ RecordIdleSocketFate(IDLE_SOCKET_FATE_CLEAN_UP_UNUSABLE);
+ }
+ delete idle_socket_it->socket;
+ idle_socket_it = group->mutable_idle_sockets()->erase(idle_socket_it);
+ DecrementIdleCount();
+ } else {
+ ++idle_socket_it;
+ }
+ }
+}
+
ClientSocketPoolBaseHelper::Group* ClientSocketPoolBaseHelper::GetOrCreateGroup(
const std::string& group_name) {
GroupMap::iterator it = group_map_.find(group_name);
« 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