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

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: mmenke comments Created 6 years, 8 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
« 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 "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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 const Request& request, Group* group) { 441 const Request& request, Group* group) {
442 std::list<IdleSocket>* idle_sockets = group->mutable_idle_sockets(); 442 std::list<IdleSocket>* idle_sockets = group->mutable_idle_sockets();
443 std::list<IdleSocket>::iterator idle_socket_it = idle_sockets->end(); 443 std::list<IdleSocket>::iterator idle_socket_it = idle_sockets->end();
444 444
445 // Iterate through the idle sockets forwards (oldest to newest) 445 // Iterate through the idle sockets forwards (oldest to newest)
446 // * Delete any disconnected ones. 446 // * Delete any disconnected ones.
447 // * If we find a used idle socket, assign to |idle_socket|. At the end, 447 // * If we find a used idle socket, assign to |idle_socket|. At the end,
448 // the |idle_socket_it| will be set to the newest used idle socket. 448 // the |idle_socket_it| will be set to the newest used idle socket.
449 for (std::list<IdleSocket>::iterator it = idle_sockets->begin(); 449 for (std::list<IdleSocket>::iterator it = idle_sockets->begin();
450 it != idle_sockets->end();) { 450 it != idle_sockets->end();) {
451 if (!it->socket->IsConnectedAndIdle()) { 451 if (!it->IsUsable()) {
452 DecrementIdleCount(); 452 DecrementIdleCount();
453 delete it->socket; 453 delete it->socket;
454 it = idle_sockets->erase(it); 454 it = idle_sockets->erase(it);
455 continue; 455 continue;
456 } 456 }
457 457
458 if (it->socket->WasEverUsed()) { 458 if (it->socket->WasEverUsed()) {
459 // We found one we can reuse! 459 // We found one we can reuse!
460 idle_socket_it = it; 460 idle_socket_it = it;
461 } 461 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 max_sockets_per_group_)); 641 max_sockets_per_group_));
642 group_dict->SetBoolean("backup_job_timer_is_running", 642 group_dict->SetBoolean("backup_job_timer_is_running",
643 group->BackupJobTimerIsRunning()); 643 group->BackupJobTimerIsRunning());
644 644
645 all_groups_dict->SetWithoutPathExpansion(it->first, group_dict); 645 all_groups_dict->SetWithoutPathExpansion(it->first, group_dict);
646 } 646 }
647 dict->Set("groups", all_groups_dict); 647 dict->Set("groups", all_groups_dict);
648 return dict; 648 return dict;
649 } 649 }
650 650
651 bool ClientSocketPoolBaseHelper::IdleSocket::IsUsable() const {
652 if (socket->WasEverUsed())
653 return socket->IsConnectedAndIdle();
654 return socket->IsConnected();
655 }
656
651 bool ClientSocketPoolBaseHelper::IdleSocket::ShouldCleanup( 657 bool ClientSocketPoolBaseHelper::IdleSocket::ShouldCleanup(
652 base::TimeTicks now, 658 base::TimeTicks now,
653 base::TimeDelta timeout) const { 659 base::TimeDelta timeout) const {
654 bool timed_out = (now - start_time) >= timeout; 660 bool timed_out = (now - start_time) >= timeout;
655 if (timed_out) 661 if (timed_out)
656 return true; 662 return true;
657 if (socket->WasEverUsed()) 663 return !IsUsable();
658 return !socket->IsConnectedAndIdle();
659 return !socket->IsConnected();
660 } 664 }
661 665
662 void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) { 666 void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) {
663 if (idle_socket_count_ == 0) 667 if (idle_socket_count_ == 0)
664 return; 668 return;
665 669
666 // Current time value. Retrieving it once at the function start rather than 670 // Current time value. Retrieving it once at the function start rather than
667 // inside the inner loop, since it shouldn't change by any meaningful amount. 671 // inside the inner loop, since it shouldn't change by any meaningful amount.
668 base::TimeTicks now = base::TimeTicks::Now(); 672 base::TimeTicks now = base::TimeTicks::Now();
669 673
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 pending_requests_.Erase(pointer); 1322 pending_requests_.Erase(pointer);
1319 // If there are no more requests, kill the backup timer. 1323 // If there are no more requests, kill the backup timer.
1320 if (pending_requests_.empty()) 1324 if (pending_requests_.empty())
1321 backup_job_timer_.Stop(); 1325 backup_job_timer_.Stop();
1322 return request.Pass(); 1326 return request.Pass();
1323 } 1327 }
1324 1328
1325 } // namespace internal 1329 } // namespace internal
1326 1330
1327 } // namespace net 1331 } // 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