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

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

Issue 169643006: Use sockets with unread data if they've never been used before. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweak SpdySession::IsReused (erf, got mixed in with a rebase) Created 6 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 | Annotate | Revision Log
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 "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/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 const Request& request, Group* group) { 442 const Request& request, Group* group) {
443 std::list<IdleSocket>* idle_sockets = group->mutable_idle_sockets(); 443 std::list<IdleSocket>* idle_sockets = group->mutable_idle_sockets();
444 std::list<IdleSocket>::iterator idle_socket_it = idle_sockets->end(); 444 std::list<IdleSocket>::iterator idle_socket_it = idle_sockets->end();
445 445
446 // Iterate through the idle sockets forwards (oldest to newest) 446 // Iterate through the idle sockets forwards (oldest to newest)
447 // * Delete any disconnected ones. 447 // * Delete any disconnected ones.
448 // * If we find a used idle socket, assign to |idle_socket|. At the end, 448 // * If we find a used idle socket, assign to |idle_socket|. At the end,
449 // the |idle_socket_it| will be set to the newest used idle socket. 449 // the |idle_socket_it| will be set to the newest used idle socket.
450 for (std::list<IdleSocket>::iterator it = idle_sockets->begin(); 450 for (std::list<IdleSocket>::iterator it = idle_sockets->begin();
451 it != idle_sockets->end();) { 451 it != idle_sockets->end();) {
452 if (!it->socket->IsConnectedAndIdle()) { 452 if (!it->IsReusable()) {
453 DecrementIdleCount(); 453 DecrementIdleCount();
454 delete it->socket; 454 delete it->socket;
455 it = idle_sockets->erase(it); 455 it = idle_sockets->erase(it);
456 continue; 456 continue;
457 } 457 }
458 458
459 if (it->socket->WasEverUsed()) { 459 if (it->socket->WasEverUsed()) {
460 // We found one we can reuse! 460 // We found one we can reuse!
461 idle_socket_it = it; 461 idle_socket_it = it;
462 } 462 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 max_sockets_per_group_)); 635 max_sockets_per_group_));
636 group_dict->SetBoolean("backup_job_timer_is_running", 636 group_dict->SetBoolean("backup_job_timer_is_running",
637 group->BackupJobTimerIsRunning()); 637 group->BackupJobTimerIsRunning());
638 638
639 all_groups_dict->SetWithoutPathExpansion(it->first, group_dict); 639 all_groups_dict->SetWithoutPathExpansion(it->first, group_dict);
640 } 640 }
641 dict->Set("groups", all_groups_dict); 641 dict->Set("groups", all_groups_dict);
642 return dict; 642 return dict;
643 } 643 }
644 644
645 bool ClientSocketPoolBaseHelper::IdleSocket::IsReusable() const {
646 if (socket->WasEverUsed())
647 return socket->IsConnectedAndIdle();
648 return socket->IsConnected();
649 }
650
645 bool ClientSocketPoolBaseHelper::IdleSocket::ShouldCleanup( 651 bool ClientSocketPoolBaseHelper::IdleSocket::ShouldCleanup(
646 base::TimeTicks now, 652 base::TimeTicks now,
647 base::TimeDelta timeout) const { 653 base::TimeDelta timeout) const {
648 bool timed_out = (now - start_time) >= timeout; 654 bool timed_out = (now - start_time) >= timeout;
649 if (timed_out) 655 if (timed_out)
650 return true; 656 return true;
651 if (socket->WasEverUsed()) 657 return !IsReusable();
652 return !socket->IsConnectedAndIdle();
653 return !socket->IsConnected();
654 } 658 }
655 659
656 void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) { 660 void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) {
657 if (idle_socket_count_ == 0) 661 if (idle_socket_count_ == 0)
658 return; 662 return;
659 663
660 // Current time value. Retrieving it once at the function start rather than 664 // Current time value. Retrieving it once at the function start rather than
661 // inside the inner loop, since it shouldn't change by any meaningful amount. 665 // inside the inner loop, since it shouldn't change by any meaningful amount.
662 base::TimeTicks now = base::TimeTicks::Now(); 666 base::TimeTicks now = base::TimeTicks::Now();
663 667
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 pending_requests_.Erase(pointer); 1316 pending_requests_.Erase(pointer);
1313 // If there are no more requests, kill the backup timer. 1317 // If there are no more requests, kill the backup timer.
1314 if (pending_requests_.empty()) 1318 if (pending_requests_.empty())
1315 backup_job_timer_.Stop(); 1319 backup_job_timer_.Stop();
1316 return request.Pass(); 1320 return request.Pass();
1317 } 1321 }
1318 1322
1319 } // namespace internal 1323 } // namespace internal
1320 1324
1321 } // namespace net 1325 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698