OLD | NEW |
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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 443 |
444 // Finds the pending request for |handle| and removes it. Returns | 444 // Finds the pending request for |handle| and removes it. Returns |
445 // the removed pending request, or NULL if there was none. | 445 // the removed pending request, or NULL if there was none. |
446 scoped_ptr<const Request> FindAndRemovePendingRequest( | 446 scoped_ptr<const Request> FindAndRemovePendingRequest( |
447 ClientSocketHandle* handle); | 447 ClientSocketHandle* handle); |
448 | 448 |
449 void IncrementActiveSocketCount() { active_socket_count_++; } | 449 void IncrementActiveSocketCount() { active_socket_count_++; } |
450 void DecrementActiveSocketCount() { active_socket_count_--; } | 450 void DecrementActiveSocketCount() { active_socket_count_--; } |
451 | 451 |
452 int unassigned_job_count() const { return unassigned_job_count_; } | 452 int unassigned_job_count() const { return unassigned_job_count_; } |
453 const std::set<ConnectJob*>& jobs() const { return jobs_; } | 453 const std::list<ConnectJob*>& jobs() const { return jobs_; } |
454 const std::list<IdleSocket>& idle_sockets() const { return idle_sockets_; } | 454 const std::list<IdleSocket>& idle_sockets() const { return idle_sockets_; } |
455 int active_socket_count() const { return active_socket_count_; } | 455 int active_socket_count() const { return active_socket_count_; } |
456 std::list<IdleSocket>* mutable_idle_sockets() { return &idle_sockets_; } | 456 std::list<IdleSocket>* mutable_idle_sockets() { return &idle_sockets_; } |
457 | 457 |
458 private: | 458 private: |
459 // Returns the iterator's pending request after removing it from | 459 // Returns the iterator's pending request after removing it from |
460 // the queue. | 460 // the queue. |
461 scoped_ptr<const Request> RemovePendingRequest( | 461 scoped_ptr<const Request> RemovePendingRequest( |
462 const RequestQueue::Pointer& pointer); | 462 const RequestQueue::Pointer& pointer); |
463 | 463 |
464 // Called when the backup socket timer fires. | 464 // Called when the backup socket timer fires. |
465 void OnBackupJobTimerFired( | 465 void OnBackupJobTimerFired( |
466 std::string group_name, | 466 std::string group_name, |
467 ClientSocketPoolBaseHelper* pool); | 467 ClientSocketPoolBaseHelper* pool); |
468 | 468 |
469 // Checks that |unassigned_job_count_| does not execeed the number of | 469 // Checks that |unassigned_job_count_| does not execeed the number of |
470 // ConnectJobs. | 470 // ConnectJobs. |
471 void SanityCheck(); | 471 void SanityCheck(); |
472 | 472 |
473 // Total number of ConnectJobs that have never been assigned to a Request. | 473 // 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 | 474 // 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 | 475 // 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 | 476 // preconnect and decremented when a preconnect is assigned, or when there |
477 // are fewer than |unassigned_job_count_| ConnectJobs. Not incremented | 477 // are fewer than |unassigned_job_count_| ConnectJobs. Not incremented |
478 // when a request is cancelled. | 478 // when a request is cancelled. |
479 size_t unassigned_job_count_; | 479 size_t unassigned_job_count_; |
480 | 480 |
481 std::list<IdleSocket> idle_sockets_; | 481 std::list<IdleSocket> idle_sockets_; |
482 std::set<ConnectJob*> jobs_; | 482 std::list<ConnectJob*> jobs_; |
483 RequestQueue pending_requests_; | 483 RequestQueue pending_requests_; |
484 int active_socket_count_; // number of active sockets used by clients | 484 int active_socket_count_; // number of active sockets used by clients |
485 // A timer for when to start the backup job. | 485 // A timer for when to start the backup job. |
486 base::OneShotTimer<Group> backup_job_timer_; | 486 base::OneShotTimer<Group> backup_job_timer_; |
487 }; | 487 }; |
488 | 488 |
489 typedef std::map<std::string, Group*> GroupMap; | 489 typedef std::map<std::string, Group*> GroupMap; |
490 | 490 |
491 typedef std::set<ConnectJob*> ConnectJobSet; | 491 typedef std::set<ConnectJob*> ConnectJobSet; |
492 | 492 |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 }; | 865 }; |
866 | 866 |
867 internal::ClientSocketPoolBaseHelper helper_; | 867 internal::ClientSocketPoolBaseHelper helper_; |
868 | 868 |
869 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 869 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
870 }; | 870 }; |
871 | 871 |
872 } // namespace net | 872 } // namespace net |
873 | 873 |
874 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 874 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
OLD | NEW |