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

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

Issue 384873002: This CL changes the lifespan of SSLConnectJobMessengers so that they are created only when needed, (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@useloop
Patch Set: Rebase, fixed issue where messenger field wasn't set to NULL after deletion Created 6 years, 4 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
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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 }; 196 };
197 197
198 class ConnectJobFactory { 198 class ConnectJobFactory {
199 public: 199 public:
200 ConnectJobFactory() {} 200 ConnectJobFactory() {}
201 virtual ~ConnectJobFactory() {} 201 virtual ~ConnectJobFactory() {}
202 202
203 virtual scoped_ptr<ConnectJob> NewConnectJob( 203 virtual scoped_ptr<ConnectJob> NewConnectJob(
204 const std::string& group_name, 204 const std::string& group_name,
205 const Request& request, 205 const Request& request,
206 ConnectJob::Delegate* delegate) const = 0; 206 ConnectJob::Delegate* delegate) = 0;
wtc 2014/08/12 14:51:00 Why can't this method be const? I guess it's becau
mshelley 2014/08/12 21:47:00 Done.
207 207
208 virtual base::TimeDelta ConnectionTimeout() const = 0; 208 virtual base::TimeDelta ConnectionTimeout() const = 0;
209 209
210 private: 210 private:
211 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); 211 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory);
212 }; 212 };
213 213
214 ClientSocketPoolBaseHelper( 214 ClientSocketPoolBaseHelper(
215 HigherLayeredPool* pool, 215 HigherLayeredPool* pool,
216 int max_sockets, 216 int max_sockets,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 int NumConnectJobsInGroup(const std::string& group_name) const { 284 int NumConnectJobsInGroup(const std::string& group_name) const {
285 return group_map_.find(group_name)->second->jobs().size(); 285 return group_map_.find(group_name)->second->jobs().size();
286 } 286 }
287 287
288 int NumActiveSocketsInGroup(const std::string& group_name) const { 288 int NumActiveSocketsInGroup(const std::string& group_name) const {
289 return group_map_.find(group_name)->second->active_socket_count(); 289 return group_map_.find(group_name)->second->active_socket_count();
290 } 290 }
291 291
292 bool HasGroup(const std::string& group_name) const; 292 bool HasGroup(const std::string& group_name) const;
293 293
294 void RemoveMessengersFromGroup(const std::string& group_name,
295 const std::string& cache_key) const;
Ryan Sleevi 2014/08/12 00:27:42 This feels like a layering violation. ClientSocket
mshelley 2014/08/12 21:47:00 Done.
296
294 // Called to enable/disable cleaning up idle sockets. When enabled, 297 // Called to enable/disable cleaning up idle sockets. When enabled,
295 // idle sockets that have been around for longer than a period defined 298 // idle sockets that have been around for longer than a period defined
296 // by kCleanupInterval are cleaned up using a timer. Otherwise they are 299 // by kCleanupInterval are cleaned up using a timer. Otherwise they are
297 // closed next time client makes a request. This may reduce network 300 // closed next time client makes a request. This may reduce network
298 // activity and power consumption. 301 // activity and power consumption.
299 static bool cleanup_timer_enabled(); 302 static bool cleanup_timer_enabled();
300 static bool set_cleanup_timer_enabled(bool enabled); 303 static bool set_cleanup_timer_enabled(bool enabled);
301 304
302 // Closes all idle sockets if |force| is true. Else, only closes idle 305 // Closes all idle sockets if |force| is true. Else, only closes idle
303 // sockets that timed out or can't be reused. Made public for testing. 306 // sockets that timed out or can't be reused. Made public for testing.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 410
408 // If there's a ConnectJob that's never been assigned to Request, 411 // If there's a ConnectJob that's never been assigned to Request,
409 // decrements |unassigned_job_count_| and returns true. 412 // decrements |unassigned_job_count_| and returns true.
410 // Otherwise, returns false. 413 // Otherwise, returns false.
411 bool TryToUseUnassignedConnectJob(); 414 bool TryToUseUnassignedConnectJob();
412 415
413 void AddJob(scoped_ptr<ConnectJob> job, bool is_preconnect); 416 void AddJob(scoped_ptr<ConnectJob> job, bool is_preconnect);
414 // Remove |job| from this group, which must already own |job|. 417 // Remove |job| from this group, which must already own |job|.
415 void RemoveJob(ConnectJob* job); 418 void RemoveJob(ConnectJob* job);
416 void RemoveAllJobs(); 419 void RemoveAllJobs();
420 void RemoveMessengers(const std::string& cache_key);
417 421
418 bool has_pending_requests() const { 422 bool has_pending_requests() const {
419 return !pending_requests_.empty(); 423 return !pending_requests_.empty();
420 } 424 }
421 425
422 size_t pending_request_count() const { 426 size_t pending_request_count() const {
423 return pending_requests_.size(); 427 return pending_requests_.size();
424 } 428 }
425 429
426 // Gets (but does not remove) the next pending request. Returns 430 // Gets (but does not remove) the next pending request. Returns
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 }; 683 };
680 684
681 class ConnectJobFactory { 685 class ConnectJobFactory {
682 public: 686 public:
683 ConnectJobFactory() {} 687 ConnectJobFactory() {}
684 virtual ~ConnectJobFactory() {} 688 virtual ~ConnectJobFactory() {}
685 689
686 virtual scoped_ptr<ConnectJob> NewConnectJob( 690 virtual scoped_ptr<ConnectJob> NewConnectJob(
687 const std::string& group_name, 691 const std::string& group_name,
688 const Request& request, 692 const Request& request,
689 ConnectJob::Delegate* delegate) const = 0; 693 ConnectJob::Delegate* delegate) = 0;
690 694
691 virtual base::TimeDelta ConnectionTimeout() const = 0; 695 virtual base::TimeDelta ConnectionTimeout() const = 0;
692 696
693 private: 697 private:
694 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); 698 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory);
695 }; 699 };
696 700
697 // |max_sockets| is the maximum number of sockets to be maintained by this 701 // |max_sockets| is the maximum number of sockets to be maintained by this
698 // ClientSocketPool. |max_sockets_per_group| specifies the maximum number of 702 // ClientSocketPool. |max_sockets_per_group| specifies the maximum number of
699 // sockets a "group" can have. |unused_idle_socket_timeout| specifies how 703 // sockets a "group" can have. |unused_idle_socket_timeout| specifies how
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 } 809 }
806 810
807 int NumActiveSocketsInGroup(const std::string& group_name) const { 811 int NumActiveSocketsInGroup(const std::string& group_name) const {
808 return helper_.NumActiveSocketsInGroup(group_name); 812 return helper_.NumActiveSocketsInGroup(group_name);
809 } 813 }
810 814
811 bool HasGroup(const std::string& group_name) const { 815 bool HasGroup(const std::string& group_name) const {
812 return helper_.HasGroup(group_name); 816 return helper_.HasGroup(group_name);
813 } 817 }
814 818
819 void RemoveMessengersFromGroup(const std::string& group_name,
820 const std::string& cache_key) const {
821 return helper_.RemoveMessengersFromGroup(group_name, cache_key);
822 }
823
815 void CleanupIdleSockets(bool force) { 824 void CleanupIdleSockets(bool force) {
816 return helper_.CleanupIdleSockets(force); 825 return helper_.CleanupIdleSockets(force);
817 } 826 }
818 827
819 base::DictionaryValue* GetInfoAsValue(const std::string& name, 828 base::DictionaryValue* GetInfoAsValue(const std::string& name,
820 const std::string& type) const { 829 const std::string& type) const {
821 return helper_.GetInfoAsValue(name, type); 830 return helper_.GetInfoAsValue(name, type);
822 } 831 }
823 832
824 base::TimeDelta ConnectionTimeout() const { 833 base::TimeDelta ConnectionTimeout() const {
(...skipping 24 matching lines...) Expand all
849 typedef typename ClientSocketPoolBase<SocketParams>::ConnectJobFactory 858 typedef typename ClientSocketPoolBase<SocketParams>::ConnectJobFactory
850 ConnectJobFactory; 859 ConnectJobFactory;
851 860
852 explicit ConnectJobFactoryAdaptor(ConnectJobFactory* connect_job_factory) 861 explicit ConnectJobFactoryAdaptor(ConnectJobFactory* connect_job_factory)
853 : connect_job_factory_(connect_job_factory) {} 862 : connect_job_factory_(connect_job_factory) {}
854 virtual ~ConnectJobFactoryAdaptor() {} 863 virtual ~ConnectJobFactoryAdaptor() {}
855 864
856 virtual scoped_ptr<ConnectJob> NewConnectJob( 865 virtual scoped_ptr<ConnectJob> NewConnectJob(
857 const std::string& group_name, 866 const std::string& group_name,
858 const internal::ClientSocketPoolBaseHelper::Request& request, 867 const internal::ClientSocketPoolBaseHelper::Request& request,
859 ConnectJob::Delegate* delegate) const OVERRIDE { 868 ConnectJob::Delegate* delegate) OVERRIDE {
860 const Request& casted_request = static_cast<const Request&>(request); 869 const Request& casted_request = static_cast<const Request&>(request);
861 return connect_job_factory_->NewConnectJob( 870 return connect_job_factory_->NewConnectJob(
862 group_name, casted_request, delegate); 871 group_name, casted_request, delegate);
863 } 872 }
864 873
865 virtual base::TimeDelta ConnectionTimeout() const { 874 virtual base::TimeDelta ConnectionTimeout() const {
866 return connect_job_factory_->ConnectionTimeout(); 875 return connect_job_factory_->ConnectionTimeout();
867 } 876 }
868 877
869 const scoped_ptr<ConnectJobFactory> connect_job_factory_; 878 const scoped_ptr<ConnectJobFactory> connect_job_factory_;
870 }; 879 };
871 880
872 // Histograms for the pool 881 // Histograms for the pool
873 ClientSocketPoolHistograms* const histograms_; 882 ClientSocketPoolHistograms* const histograms_;
874 internal::ClientSocketPoolBaseHelper helper_; 883 internal::ClientSocketPoolBaseHelper helper_;
875 884
876 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); 885 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase);
877 }; 886 };
878 887
879 } // namespace net 888 } // namespace net
880 889
881 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ 890 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698