OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 class ClientSocketPoolBase { | 484 class ClientSocketPoolBase { |
485 public: | 485 public: |
486 class Request : public internal::ClientSocketPoolBaseHelper::Request { | 486 class Request : public internal::ClientSocketPoolBaseHelper::Request { |
487 public: | 487 public: |
488 Request(ClientSocketHandle* handle, | 488 Request(ClientSocketHandle* handle, |
489 CompletionCallback* callback, | 489 CompletionCallback* callback, |
490 RequestPriority priority, | 490 RequestPriority priority, |
491 const scoped_refptr<SocketParams>& params, | 491 const scoped_refptr<SocketParams>& params, |
492 const BoundNetLog& net_log) | 492 const BoundNetLog& net_log) |
493 : internal::ClientSocketPoolBaseHelper::Request( | 493 : internal::ClientSocketPoolBaseHelper::Request( |
494 handle, callback, priority, net_log), | 494 handle, callback, priority, net_log), |
495 params_(params) {} | 495 params_(params) {} |
496 | 496 |
497 const scoped_refptr<SocketParams>& params() const { return params_; } | 497 const scoped_refptr<SocketParams>& params() const { return params_; } |
498 | 498 |
499 private: | 499 private: |
500 scoped_refptr<SocketParams> params_; | 500 scoped_refptr<SocketParams> params_; |
501 }; | 501 }; |
502 | 502 |
503 class ConnectJobFactory { | 503 class ConnectJobFactory { |
504 public: | 504 public: |
(...skipping 19 matching lines...) Expand all Loading... |
524 // idle socket open before closing it. | 524 // idle socket open before closing it. |
525 ClientSocketPoolBase( | 525 ClientSocketPoolBase( |
526 int max_sockets, | 526 int max_sockets, |
527 int max_sockets_per_group, | 527 int max_sockets_per_group, |
528 const scoped_refptr<ClientSocketPoolHistograms>& histograms, | 528 const scoped_refptr<ClientSocketPoolHistograms>& histograms, |
529 base::TimeDelta unused_idle_socket_timeout, | 529 base::TimeDelta unused_idle_socket_timeout, |
530 base::TimeDelta used_idle_socket_timeout, | 530 base::TimeDelta used_idle_socket_timeout, |
531 ConnectJobFactory* connect_job_factory) | 531 ConnectJobFactory* connect_job_factory) |
532 : histograms_(histograms), | 532 : histograms_(histograms), |
533 helper_(new internal::ClientSocketPoolBaseHelper( | 533 helper_(new internal::ClientSocketPoolBaseHelper( |
534 max_sockets, max_sockets_per_group, | 534 max_sockets, max_sockets_per_group, |
535 unused_idle_socket_timeout, used_idle_socket_timeout, | 535 unused_idle_socket_timeout, used_idle_socket_timeout, |
536 new ConnectJobFactoryAdaptor(connect_job_factory))) {} | 536 new ConnectJobFactoryAdaptor(connect_job_factory))) {} |
537 | 537 |
538 virtual ~ClientSocketPoolBase() {} | 538 virtual ~ClientSocketPoolBase() {} |
539 | 539 |
540 // These member functions simply forward to ClientSocketPoolBaseHelper. | 540 // These member functions simply forward to ClientSocketPoolBaseHelper. |
541 | 541 |
542 // RequestSocket bundles up the parameters into a Request and then forwards to | 542 // RequestSocket bundles up the parameters into a Request and then forwards to |
543 // ClientSocketPoolBaseHelper::RequestSocket(). Note that the memory | 543 // ClientSocketPoolBaseHelper::RequestSocket(). Note that the memory |
544 // ownership is transferred in the asynchronous (ERR_IO_PENDING) case. | 544 // ownership is transferred in the asynchronous (ERR_IO_PENDING) case. |
545 int RequestSocket(const std::string& group_name, | 545 int RequestSocket(const std::string& group_name, |
546 const scoped_refptr<SocketParams>& params, | 546 const scoped_refptr<SocketParams>& params, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 // internal::ClientSocketPoolBaseHelper::ConnectJobFactory and | 604 // internal::ClientSocketPoolBaseHelper::ConnectJobFactory and |
605 // ClientSocketPoolBase::ConnectJobFactory types, allowing clients to use the | 605 // ClientSocketPoolBase::ConnectJobFactory types, allowing clients to use the |
606 // typesafe ClientSocketPoolBase::ConnectJobFactory, rather than having to | 606 // typesafe ClientSocketPoolBase::ConnectJobFactory, rather than having to |
607 // static_cast themselves. | 607 // static_cast themselves. |
608 class ConnectJobFactoryAdaptor | 608 class ConnectJobFactoryAdaptor |
609 : public internal::ClientSocketPoolBaseHelper::ConnectJobFactory { | 609 : public internal::ClientSocketPoolBaseHelper::ConnectJobFactory { |
610 public: | 610 public: |
611 typedef typename ClientSocketPoolBase<SocketParams>::ConnectJobFactory | 611 typedef typename ClientSocketPoolBase<SocketParams>::ConnectJobFactory |
612 ConnectJobFactory; | 612 ConnectJobFactory; |
613 | 613 |
614 explicit ConnectJobFactoryAdaptor( | 614 explicit ConnectJobFactoryAdaptor(ConnectJobFactory* connect_job_factory) |
615 ConnectJobFactory* connect_job_factory) | |
616 : connect_job_factory_(connect_job_factory) {} | 615 : connect_job_factory_(connect_job_factory) {} |
617 virtual ~ConnectJobFactoryAdaptor() {} | 616 virtual ~ConnectJobFactoryAdaptor() {} |
618 | 617 |
619 virtual ConnectJob* NewConnectJob( | 618 virtual ConnectJob* NewConnectJob( |
620 const std::string& group_name, | 619 const std::string& group_name, |
621 const internal::ClientSocketPoolBaseHelper::Request& request, | 620 const internal::ClientSocketPoolBaseHelper::Request& request, |
622 ConnectJob::Delegate* delegate) const { | 621 ConnectJob::Delegate* delegate) const { |
623 const Request* casted_request = static_cast<const Request*>(&request); | 622 const Request* casted_request = static_cast<const Request*>(&request); |
624 return connect_job_factory_->NewConnectJob( | 623 return connect_job_factory_->NewConnectJob( |
625 group_name, *casted_request, delegate); | 624 group_name, *casted_request, delegate); |
(...skipping 14 matching lines...) Expand all Loading... |
640 // ClientSocketPoolBase<T> reference to drop to zero. While we're deep | 639 // ClientSocketPoolBase<T> reference to drop to zero. While we're deep |
641 // in cleanup code, we'll often hold a reference to |self|. | 640 // in cleanup code, we'll often hold a reference to |self|. |
642 scoped_refptr<internal::ClientSocketPoolBaseHelper> helper_; | 641 scoped_refptr<internal::ClientSocketPoolBaseHelper> helper_; |
643 | 642 |
644 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 643 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
645 }; | 644 }; |
646 | 645 |
647 } // namespace net | 646 } // namespace net |
648 | 647 |
649 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 648 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
OLD | NEW |