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

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

Issue 1091793002: Report the connect status of the oldest connection in the socket pool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve comment Created 5 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
« no previous file with comments | « no previous file | net/socket/client_socket_pool_base.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 // A ClientSocketPoolBase is used to restrict the number of sockets open at 5 // A ClientSocketPoolBase is used to restrict the number of sockets open at
6 // a time. It also maintains a list of idle persistent sockets for reuse. 6 // a time. It also maintains a list of idle persistent sockets for reuse.
7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle 7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle
8 // the core logic of (1) restricting the number of active (connected or 8 // the core logic of (1) restricting the number of active (connected or
9 // connecting) sockets per "group" (generally speaking, the hostname), (2) 9 // connecting) sockets per "group" (generally speaking, the hostname), (2)
10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) 10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // result) this method will be called, allowing the pool to add 105 // result) this method will be called, allowing the pool to add
106 // additional error state to the ClientSocketHandle (post late-binding). 106 // additional error state to the ClientSocketHandle (post late-binding).
107 virtual void GetAdditionalErrorState(ClientSocketHandle* handle) {} 107 virtual void GetAdditionalErrorState(ClientSocketHandle* handle) {}
108 108
109 const LoadTimingInfo::ConnectTiming& connect_timing() const { 109 const LoadTimingInfo::ConnectTiming& connect_timing() const {
110 return connect_timing_; 110 return connect_timing_;
111 } 111 }
112 112
113 const BoundNetLog& net_log() const { return net_log_; } 113 const BoundNetLog& net_log() const { return net_log_; }
114 114
115 // Used to order ConnectJob in a set with ascending connect time.
116 struct CompareJobConnectStartTime {
117 bool operator()(const ConnectJob* lhs, const ConnectJob* rhs) const {
118 return lhs->connect_timing().connect_start <
119 rhs->connect_timing().connect_start;
120 }
mmenke 2015/04/17 15:32:39 Also, should probably have two tests for this (In
mmenke 2015/04/17 15:32:40 If two ConnectJob are created at the same time, do
haavardm 2015/04/18 07:24:16 Agree. Using something else than a set here is pro
haavardm 2015/04/18 07:24:16 Yes, I discovered yesterday that that's exactly wh
mmenke 2015/04/18 13:49:57 That's probably because connect_start times can ch
haavardm 2015/04/20 13:03:48 Not sure I get this test. As I understand it, sock
haavardm 2015/04/20 13:03:48 I removed the compare function since list is now u
mmenke 2015/04/20 14:49:16 I was thinking SSL sockets, where more is needed a
121 };
122
115 protected: 123 protected:
116 RequestPriority priority() const { return priority_; } 124 RequestPriority priority() const { return priority_; }
117 void SetSocket(scoped_ptr<StreamSocket> socket); 125 void SetSocket(scoped_ptr<StreamSocket> socket);
118 StreamSocket* socket() { return socket_.get(); } 126 StreamSocket* socket() { return socket_.get(); }
119 void NotifyDelegateOfCompletion(int rv); 127 void NotifyDelegateOfCompletion(int rv);
120 void ResetTimer(base::TimeDelta remainingTime); 128 void ResetTimer(base::TimeDelta remainingTime);
121 129
122 // Connection establishment timing information. 130 // Connection establishment timing information.
123 LoadTimingInfo::ConnectTiming connect_timing_; 131 LoadTimingInfo::ConnectTiming connect_timing_;
124 132
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 451
444 // Finds the pending request for |handle| and removes it. Returns 452 // Finds the pending request for |handle| and removes it. Returns
445 // the removed pending request, or NULL if there was none. 453 // the removed pending request, or NULL if there was none.
446 scoped_ptr<const Request> FindAndRemovePendingRequest( 454 scoped_ptr<const Request> FindAndRemovePendingRequest(
447 ClientSocketHandle* handle); 455 ClientSocketHandle* handle);
448 456
449 void IncrementActiveSocketCount() { active_socket_count_++; } 457 void IncrementActiveSocketCount() { active_socket_count_++; }
450 void DecrementActiveSocketCount() { active_socket_count_--; } 458 void DecrementActiveSocketCount() { active_socket_count_--; }
451 459
452 int unassigned_job_count() const { return unassigned_job_count_; } 460 int unassigned_job_count() const { return unassigned_job_count_; }
453 const std::set<ConnectJob*>& jobs() const { return jobs_; } 461 const std::set<ConnectJob*, ConnectJob::CompareJobConnectStartTime>& jobs()
462 const {
463 return jobs_;
464 }
454 const std::list<IdleSocket>& idle_sockets() const { return idle_sockets_; } 465 const std::list<IdleSocket>& idle_sockets() const { return idle_sockets_; }
455 int active_socket_count() const { return active_socket_count_; } 466 int active_socket_count() const { return active_socket_count_; }
456 std::list<IdleSocket>* mutable_idle_sockets() { return &idle_sockets_; } 467 std::list<IdleSocket>* mutable_idle_sockets() { return &idle_sockets_; }
457 468
458 private: 469 private:
459 // Returns the iterator's pending request after removing it from 470 // Returns the iterator's pending request after removing it from
460 // the queue. 471 // the queue.
461 scoped_ptr<const Request> RemovePendingRequest( 472 scoped_ptr<const Request> RemovePendingRequest(
462 const RequestQueue::Pointer& pointer); 473 const RequestQueue::Pointer& pointer);
463 474
464 // Called when the backup socket timer fires. 475 // Called when the backup socket timer fires.
465 void OnBackupJobTimerFired( 476 void OnBackupJobTimerFired(
466 std::string group_name, 477 std::string group_name,
467 ClientSocketPoolBaseHelper* pool); 478 ClientSocketPoolBaseHelper* pool);
468 479
469 // Checks that |unassigned_job_count_| does not execeed the number of 480 // Checks that |unassigned_job_count_| does not execeed the number of
470 // ConnectJobs. 481 // ConnectJobs.
471 void SanityCheck(); 482 void SanityCheck();
472 483
473 // Total number of ConnectJobs that have never been assigned to a Request. 484 // Total number of ConnectJobs that have never been assigned to a Request.
474 // Since jobs use late binding to requests, which ConnectJobs have or have 485 // Since jobs use late binding to requests, which ConnectJobs have or have
475 // not been assigned to a request are not tracked. This is incremented on 486 // not been assigned to a request are not tracked. This is incremented on
476 // preconnect and decremented when a preconnect is assigned, or when there 487 // preconnect and decremented when a preconnect is assigned, or when there
477 // are fewer than |unassigned_job_count_| ConnectJobs. Not incremented 488 // are fewer than |unassigned_job_count_| ConnectJobs. Not incremented
478 // when a request is cancelled. 489 // when a request is cancelled.
479 size_t unassigned_job_count_; 490 size_t unassigned_job_count_;
480 491
481 std::list<IdleSocket> idle_sockets_; 492 std::list<IdleSocket> idle_sockets_;
482 std::set<ConnectJob*> jobs_; 493 std::set<ConnectJob*, ConnectJob::CompareJobConnectStartTime> jobs_;
483 RequestQueue pending_requests_; 494 RequestQueue pending_requests_;
484 int active_socket_count_; // number of active sockets used by clients 495 int active_socket_count_; // number of active sockets used by clients
485 // A timer for when to start the backup job. 496 // A timer for when to start the backup job.
486 base::OneShotTimer<Group> backup_job_timer_; 497 base::OneShotTimer<Group> backup_job_timer_;
487 }; 498 };
488 499
489 typedef std::map<std::string, Group*> GroupMap; 500 typedef std::map<std::string, Group*> GroupMap;
490 501
491 typedef std::set<ConnectJob*> ConnectJobSet; 502 typedef std::set<ConnectJob*> ConnectJobSet;
492 503
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 }; 876 };
866 877
867 internal::ClientSocketPoolBaseHelper helper_; 878 internal::ClientSocketPoolBaseHelper helper_;
868 879
869 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); 880 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase);
870 }; 881 };
871 882
872 } // namespace net 883 } // namespace net
873 884
874 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ 885 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_
OLDNEW
« no previous file with comments | « no previous file | net/socket/client_socket_pool_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698