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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 class NET_EXPORT_PRIVATE ConnectJob { 60 class NET_EXPORT_PRIVATE ConnectJob {
61 public: 61 public:
62 class NET_EXPORT_PRIVATE Delegate { 62 class NET_EXPORT_PRIVATE Delegate {
63 public: 63 public:
64 Delegate() {} 64 Delegate() {}
65 virtual ~Delegate() {} 65 virtual ~Delegate() {}
66 66
67 // Alerts the delegate that the connection completed. |job| must 67 // Alerts the delegate that the connection completed. |job| must
68 // be destroyed by the delegate. A scoped_ptr<> isn't used because 68 // be destroyed by the delegate. A scoped_ptr<> isn't used because
69 // the caller of this function doesn't own |job|. 69 // the caller of this function doesn't own |job|.
70 virtual void OnConnectJobComplete(int result, 70 virtual void OnConnectJobComplete(int result, ConnectJob* job) = 0;
71 ConnectJob* job) = 0;
72 71
73 private: 72 private:
74 DISALLOW_COPY_AND_ASSIGN(Delegate); 73 DISALLOW_COPY_AND_ASSIGN(Delegate);
75 }; 74 };
76 75
77 // A |timeout_duration| of 0 corresponds to no timeout. 76 // A |timeout_duration| of 0 corresponds to no timeout.
78 ConnectJob(const std::string& group_name, 77 ConnectJob(const std::string& group_name,
79 base::TimeDelta timeout_duration, 78 base::TimeDelta timeout_duration,
80 RequestPriority priority, 79 RequestPriority priority,
81 Delegate* delegate, 80 Delegate* delegate,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // ClientSocketPoolBaseHelper. This class is not for external use, please use 153 // ClientSocketPoolBaseHelper. This class is not for external use, please use
155 // ClientSocketPoolBase instead. 154 // ClientSocketPoolBase instead.
156 class NET_EXPORT_PRIVATE ClientSocketPoolBaseHelper 155 class NET_EXPORT_PRIVATE ClientSocketPoolBaseHelper
157 : public ConnectJob::Delegate, 156 : public ConnectJob::Delegate,
158 public NetworkChangeNotifier::IPAddressObserver { 157 public NetworkChangeNotifier::IPAddressObserver {
159 public: 158 public:
160 typedef uint32 Flags; 159 typedef uint32 Flags;
161 160
162 // Used to specify specific behavior for the ClientSocketPool. 161 // Used to specify specific behavior for the ClientSocketPool.
163 enum Flag { 162 enum Flag {
164 NORMAL = 0, // Normal behavior. 163 NORMAL = 0, // Normal behavior.
165 NO_IDLE_SOCKETS = 0x1, // Do not return an idle socket. Create a new one. 164 NO_IDLE_SOCKETS = 0x1, // Do not return an idle socket. Create a new one.
166 }; 165 };
167 166
168 class NET_EXPORT_PRIVATE Request { 167 class NET_EXPORT_PRIVATE Request {
169 public: 168 public:
170 Request(ClientSocketHandle* handle, 169 Request(ClientSocketHandle* handle,
171 const CompletionCallback& callback, 170 const CompletionCallback& callback,
172 RequestPriority priority, 171 RequestPriority priority,
173 bool ignore_limits, 172 bool ignore_limits,
174 Flags flags, 173 Flags flags,
(...skipping 29 matching lines...) Expand all
204 const std::string& group_name, 203 const std::string& group_name,
205 const Request& request, 204 const Request& request,
206 ConnectJob::Delegate* delegate) const = 0; 205 ConnectJob::Delegate* delegate) const = 0;
207 206
208 virtual base::TimeDelta ConnectionTimeout() const = 0; 207 virtual base::TimeDelta ConnectionTimeout() const = 0;
209 208
210 private: 209 private:
211 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); 210 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory);
212 }; 211 };
213 212
214 ClientSocketPoolBaseHelper( 213 ClientSocketPoolBaseHelper(HigherLayeredPool* pool,
215 HigherLayeredPool* pool, 214 int max_sockets,
216 int max_sockets, 215 int max_sockets_per_group,
217 int max_sockets_per_group, 216 base::TimeDelta unused_idle_socket_timeout,
218 base::TimeDelta unused_idle_socket_timeout, 217 base::TimeDelta used_idle_socket_timeout,
219 base::TimeDelta used_idle_socket_timeout, 218 ConnectJobFactory* connect_job_factory);
220 ConnectJobFactory* connect_job_factory);
221 219
222 virtual ~ClientSocketPoolBaseHelper(); 220 virtual ~ClientSocketPoolBaseHelper();
223 221
224 // Adds a lower layered pool to |this|, and adds |this| as a higher layered 222 // Adds a lower layered pool to |this|, and adds |this| as a higher layered
225 // pool on top of |lower_pool|. 223 // pool on top of |lower_pool|.
226 void AddLowerLayeredPool(LowerLayeredPool* lower_pool); 224 void AddLowerLayeredPool(LowerLayeredPool* lower_pool);
227 225
228 // See LowerLayeredPool::IsStalled for documentation on this function. 226 // See LowerLayeredPool::IsStalled for documentation on this function.
229 bool IsStalled() const; 227 bool IsStalled() const;
230 228
231 // See LowerLayeredPool for documentation on these functions. It is expected 229 // See LowerLayeredPool for documentation on these functions. It is expected
232 // in the destructor that no higher layer pools remain. 230 // in the destructor that no higher layer pools remain.
233 void AddHigherLayeredPool(HigherLayeredPool* higher_pool); 231 void AddHigherLayeredPool(HigherLayeredPool* higher_pool);
234 void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool); 232 void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool);
235 233
236 // See ClientSocketPool::RequestSocket for documentation on this function. 234 // See ClientSocketPool::RequestSocket for documentation on this function.
237 int RequestSocket(const std::string& group_name, 235 int RequestSocket(const std::string& group_name,
238 scoped_ptr<const Request> request); 236 scoped_ptr<const Request> request);
239 237
240 // See ClientSocketPool::RequestSocket for documentation on this function. 238 // See ClientSocketPool::RequestSocket for documentation on this function.
241 void RequestSockets(const std::string& group_name, 239 void RequestSockets(const std::string& group_name,
242 const Request& request, 240 const Request& request,
243 int num_sockets); 241 int num_sockets);
244 242
245 // See ClientSocketPool::CancelRequest for documentation on this function. 243 // See ClientSocketPool::CancelRequest for documentation on this function.
246 void CancelRequest(const std::string& group_name, 244 void CancelRequest(const std::string& group_name, ClientSocketHandle* handle);
247 ClientSocketHandle* handle);
248 245
249 // See ClientSocketPool::ReleaseSocket for documentation on this function. 246 // See ClientSocketPool::ReleaseSocket for documentation on this function.
250 void ReleaseSocket(const std::string& group_name, 247 void ReleaseSocket(const std::string& group_name,
251 scoped_ptr<StreamSocket> socket, 248 scoped_ptr<StreamSocket> socket,
252 int id); 249 int id);
253 250
254 // See ClientSocketPool::FlushWithError for documentation on this function. 251 // See ClientSocketPool::FlushWithError for documentation on this function.
255 void FlushWithError(int error); 252 void FlushWithError(int error);
256 253
257 // See ClientSocketPool::CloseIdleSockets for documentation on this function. 254 // See ClientSocketPool::CloseIdleSockets for documentation on this function.
258 void CloseIdleSockets(); 255 void CloseIdleSockets();
259 256
260 // See ClientSocketPool::IdleSocketCount() for documentation on this function. 257 // See ClientSocketPool::IdleSocketCount() for documentation on this function.
261 int idle_socket_count() const { 258 int idle_socket_count() const { return idle_socket_count_; }
262 return idle_socket_count_;
263 }
264 259
265 // See ClientSocketPool::IdleSocketCountInGroup() for documentation on this 260 // See ClientSocketPool::IdleSocketCountInGroup() for documentation on this
266 // function. 261 // function.
267 int IdleSocketCountInGroup(const std::string& group_name) const; 262 int IdleSocketCountInGroup(const std::string& group_name) const;
268 263
269 // See ClientSocketPool::GetLoadState() for documentation on this function. 264 // See ClientSocketPool::GetLoadState() for documentation on this function.
270 LoadState GetLoadState(const std::string& group_name, 265 LoadState GetLoadState(const std::string& group_name,
271 const ClientSocketHandle* handle) const; 266 const ClientSocketHandle* handle) const;
272 267
273 base::TimeDelta ConnectRetryInterval() const { 268 base::TimeDelta ConnectRetryInterval() const {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // A Group is allocated per group_name when there are idle sockets or pending 359 // A Group is allocated per group_name when there are idle sockets or pending
365 // requests. Otherwise, the Group object is removed from the map. 360 // requests. Otherwise, the Group object is removed from the map.
366 // |active_socket_count| tracks the number of sockets held by clients. 361 // |active_socket_count| tracks the number of sockets held by clients.
367 class Group { 362 class Group {
368 public: 363 public:
369 Group(); 364 Group();
370 ~Group(); 365 ~Group();
371 366
372 bool IsEmpty() const { 367 bool IsEmpty() const {
373 return active_socket_count_ == 0 && idle_sockets_.empty() && 368 return active_socket_count_ == 0 && idle_sockets_.empty() &&
374 jobs_.empty() && pending_requests_.empty(); 369 jobs_.empty() && pending_requests_.empty();
375 } 370 }
376 371
377 bool HasAvailableSocketSlot(int max_sockets_per_group) const { 372 bool HasAvailableSocketSlot(int max_sockets_per_group) const {
378 return NumActiveSocketSlots() < max_sockets_per_group; 373 return NumActiveSocketSlots() < max_sockets_per_group;
379 } 374 }
380 375
381 int NumActiveSocketSlots() const { 376 int NumActiveSocketSlots() const {
382 return active_socket_count_ + static_cast<int>(jobs_.size()) + 377 return active_socket_count_ + static_cast<int>(jobs_.size()) +
383 static_cast<int>(idle_sockets_.size()); 378 static_cast<int>(idle_sockets_.size());
384 } 379 }
385 380
386 bool IsStalledOnPoolMaxSockets(int max_sockets_per_group) const { 381 bool IsStalledOnPoolMaxSockets(int max_sockets_per_group) const {
387 return HasAvailableSocketSlot(max_sockets_per_group) && 382 return HasAvailableSocketSlot(max_sockets_per_group) &&
388 pending_requests_.size() > jobs_.size(); 383 pending_requests_.size() > jobs_.size();
389 } 384 }
390 385
391 // Returns the priority of the top of the pending request queue 386 // Returns the priority of the top of the pending request queue
392 // (which may be less than the maximum priority over the entire 387 // (which may be less than the maximum priority over the entire
393 // queue, due to how we prioritize requests with |ignore_limits| 388 // queue, due to how we prioritize requests with |ignore_limits|
394 // set over others). 389 // set over others).
395 RequestPriority TopPendingPriority() const { 390 RequestPriority TopPendingPriority() const {
396 // NOTE: FirstMax().value()->priority() is not the same as 391 // NOTE: FirstMax().value()->priority() is not the same as
397 // FirstMax().priority()! 392 // FirstMax().priority()!
398 return pending_requests_.FirstMax().value()->priority(); 393 return pending_requests_.FirstMax().value()->priority();
399 } 394 }
400 395
401 // Set a timer to create a backup job if it takes too long to 396 // Set a timer to create a backup job if it takes too long to
402 // create one and if a timer isn't already running. 397 // create one and if a timer isn't already running.
403 void StartBackupJobTimer(const std::string& group_name, 398 void StartBackupJobTimer(const std::string& group_name,
404 ClientSocketPoolBaseHelper* pool); 399 ClientSocketPoolBaseHelper* pool);
405 400
406 bool BackupJobTimerIsRunning() const; 401 bool BackupJobTimerIsRunning() const;
407 402
408 // If there's a ConnectJob that's never been assigned to Request, 403 // If there's a ConnectJob that's never been assigned to Request,
409 // decrements |unassigned_job_count_| and returns true. 404 // decrements |unassigned_job_count_| and returns true.
410 // Otherwise, returns false. 405 // Otherwise, returns false.
411 bool TryToUseUnassignedConnectJob(); 406 bool TryToUseUnassignedConnectJob();
412 407
413 void AddJob(scoped_ptr<ConnectJob> job, bool is_preconnect); 408 void AddJob(scoped_ptr<ConnectJob> job, bool is_preconnect);
414 // Remove |job| from this group, which must already own |job|. 409 // Remove |job| from this group, which must already own |job|.
415 void RemoveJob(ConnectJob* job); 410 void RemoveJob(ConnectJob* job);
416 void RemoveAllJobs(); 411 void RemoveAllJobs();
417 412
418 bool has_pending_requests() const { 413 bool has_pending_requests() const { return !pending_requests_.empty(); }
419 return !pending_requests_.empty();
420 }
421 414
422 size_t pending_request_count() const { 415 size_t pending_request_count() const { return pending_requests_.size(); }
423 return pending_requests_.size();
424 }
425 416
426 // Gets (but does not remove) the next pending request. Returns 417 // Gets (but does not remove) the next pending request. Returns
427 // NULL if there are no pending requests. 418 // NULL if there are no pending requests.
428 const Request* GetNextPendingRequest() const; 419 const Request* GetNextPendingRequest() const;
429 420
430 // Returns true if there is a connect job for |handle|. 421 // Returns true if there is a connect job for |handle|.
431 bool HasConnectJobForHandle(const ClientSocketHandle* handle) const; 422 bool HasConnectJobForHandle(const ClientSocketHandle* handle) const;
432 423
433 // Inserts the request into the queue based on priority 424 // Inserts the request into the queue based on priority
434 // order. Older requests are prioritized over requests of equal 425 // order. Older requests are prioritized over requests of equal
(...skipping 18 matching lines...) Expand all
453 int active_socket_count() const { return active_socket_count_; } 444 int active_socket_count() const { return active_socket_count_; }
454 std::list<IdleSocket>* mutable_idle_sockets() { return &idle_sockets_; } 445 std::list<IdleSocket>* mutable_idle_sockets() { return &idle_sockets_; }
455 446
456 private: 447 private:
457 // Returns the iterator's pending request after removing it from 448 // Returns the iterator's pending request after removing it from
458 // the queue. 449 // the queue.
459 scoped_ptr<const Request> RemovePendingRequest( 450 scoped_ptr<const Request> RemovePendingRequest(
460 const RequestQueue::Pointer& pointer); 451 const RequestQueue::Pointer& pointer);
461 452
462 // Called when the backup socket timer fires. 453 // Called when the backup socket timer fires.
463 void OnBackupJobTimerFired( 454 void OnBackupJobTimerFired(std::string group_name,
464 std::string group_name, 455 ClientSocketPoolBaseHelper* pool);
465 ClientSocketPoolBaseHelper* pool);
466 456
467 // Checks that |unassigned_job_count_| does not execeed the number of 457 // Checks that |unassigned_job_count_| does not execeed the number of
468 // ConnectJobs. 458 // ConnectJobs.
469 void SanityCheck(); 459 void SanityCheck();
470 460
471 // Total number of ConnectJobs that have never been assigned to a Request. 461 // Total number of ConnectJobs that have never been assigned to a Request.
472 // Since jobs use late binding to requests, which ConnectJobs have or have 462 // Since jobs use late binding to requests, which ConnectJobs have or have
473 // not been assigned to a request are not tracked. This is incremented on 463 // not been assigned to a request are not tracked. This is incremented on
474 // preconnect and decremented when a preconnect is assigned, or when there 464 // preconnect and decremented when a preconnect is assigned, or when there
475 // are fewer than |unassigned_job_count_| ConnectJobs. Not incremented 465 // are fewer than |unassigned_job_count_| ConnectJobs. Not incremented
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 void StartIdleSocketTimer(); 502 void StartIdleSocketTimer();
513 503
514 // Scans the group map for groups which have an available socket slot and 504 // Scans the group map for groups which have an available socket slot and
515 // at least one pending request. Returns true if any groups are stalled, and 505 // at least one pending request. Returns true if any groups are stalled, and
516 // if so (and if both |group| and |group_name| are not NULL), fills |group| 506 // if so (and if both |group| and |group_name| are not NULL), fills |group|
517 // and |group_name| with data of the stalled group having highest priority. 507 // and |group_name| with data of the stalled group having highest priority.
518 bool FindTopStalledGroup(Group** group, std::string* group_name) const; 508 bool FindTopStalledGroup(Group** group, std::string* group_name) const;
519 509
520 // Called when timer_ fires. This method scans the idle sockets removing 510 // Called when timer_ fires. This method scans the idle sockets removing
521 // sockets that timed out or can't be reused. 511 // sockets that timed out or can't be reused.
522 void OnCleanupTimerFired() { 512 void OnCleanupTimerFired() { CleanupIdleSockets(false); }
523 CleanupIdleSockets(false);
524 }
525 513
526 // Removes |job| from |group|, which must already own |job|. 514 // Removes |job| from |group|, which must already own |job|.
527 void RemoveConnectJob(ConnectJob* job, Group* group); 515 void RemoveConnectJob(ConnectJob* job, Group* group);
528 516
529 // Tries to see if we can handle any more requests for |group|. 517 // Tries to see if we can handle any more requests for |group|.
530 void OnAvailableSocketSlot(const std::string& group_name, Group* group); 518 void OnAvailableSocketSlot(const std::string& group_name, Group* group);
531 519
532 // Process a pending socket request for a group. 520 // Process a pending socket request for a group.
533 void ProcessPendingRequest(const std::string& group_name, Group* group); 521 void ProcessPendingRequest(const std::string& group_name, Group* group);
534 522
(...skipping 24 matching lines...) Expand all
559 // it does not handle logging into NetLog of the queueing status of 547 // it does not handle logging into NetLog of the queueing status of
560 // |request|. 548 // |request|.
561 int RequestSocketInternal(const std::string& group_name, 549 int RequestSocketInternal(const std::string& group_name,
562 const Request& request); 550 const Request& request);
563 551
564 // Assigns an idle socket for the group to the request. 552 // Assigns an idle socket for the group to the request.
565 // Returns |true| if an idle socket is available, false otherwise. 553 // Returns |true| if an idle socket is available, false otherwise.
566 bool AssignIdleSocketToRequest(const Request& request, Group* group); 554 bool AssignIdleSocketToRequest(const Request& request, Group* group);
567 555
568 static void LogBoundConnectJobToRequest( 556 static void LogBoundConnectJobToRequest(
569 const NetLog::Source& connect_job_source, const Request& request); 557 const NetLog::Source& connect_job_source,
558 const Request& request);
570 559
571 // Same as CloseOneIdleSocket() except it won't close an idle socket in 560 // Same as CloseOneIdleSocket() except it won't close an idle socket in
572 // |group|. If |group| is NULL, it is ignored. Returns true if it closed a 561 // |group|. If |group| is NULL, it is ignored. Returns true if it closed a
573 // socket. 562 // socket.
574 bool CloseOneIdleSocketExceptInGroup(const Group* group); 563 bool CloseOneIdleSocketExceptInGroup(const Group* group);
575 564
576 // Checks if there are stalled socket groups that should be notified 565 // Checks if there are stalled socket groups that should be notified
577 // for possible wakeup. 566 // for possible wakeup.
578 void CheckForStalledSocketGroups(); 567 void CheckForStalledSocketGroups();
579 568
580 // Posts a task to call InvokeUserCallback() on the next iteration through the 569 // Posts a task to call InvokeUserCallback() on the next iteration through the
581 // current message loop. Inserts |callback| into |pending_callback_map_|, 570 // current message loop. Inserts |callback| into |pending_callback_map_|,
582 // keyed by |handle|. 571 // keyed by |handle|.
583 void InvokeUserCallbackLater( 572 void InvokeUserCallbackLater(ClientSocketHandle* handle,
584 ClientSocketHandle* handle, const CompletionCallback& callback, int rv); 573 const CompletionCallback& callback,
574 int rv);
585 575
586 // Invokes the user callback for |handle|. By the time this task has run, 576 // Invokes the user callback for |handle|. By the time this task has run,
587 // it's possible that the request has been cancelled, so |handle| may not 577 // it's possible that the request has been cancelled, so |handle| may not
588 // exist in |pending_callback_map_|. We look up the callback and result code 578 // exist in |pending_callback_map_|. We look up the callback and result code
589 // in |pending_callback_map_|. 579 // in |pending_callback_map_|.
590 void InvokeUserCallback(ClientSocketHandle* handle); 580 void InvokeUserCallback(ClientSocketHandle* handle);
591 581
592 // Tries to close idle sockets in a higher level socket pool as long as this 582 // Tries to close idle sockets in a higher level socket pool as long as this
593 // this pool is stalled. 583 // this pool is stalled.
594 void TryToCloseSocketsInLayeredPools(); 584 void TryToCloseSocketsInLayeredPools();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 public: 651 public:
662 class Request : public internal::ClientSocketPoolBaseHelper::Request { 652 class Request : public internal::ClientSocketPoolBaseHelper::Request {
663 public: 653 public:
664 Request(ClientSocketHandle* handle, 654 Request(ClientSocketHandle* handle,
665 const CompletionCallback& callback, 655 const CompletionCallback& callback,
666 RequestPriority priority, 656 RequestPriority priority,
667 internal::ClientSocketPoolBaseHelper::Flags flags, 657 internal::ClientSocketPoolBaseHelper::Flags flags,
668 bool ignore_limits, 658 bool ignore_limits,
669 const scoped_refptr<SocketParams>& params, 659 const scoped_refptr<SocketParams>& params,
670 const BoundNetLog& net_log) 660 const BoundNetLog& net_log)
671 : internal::ClientSocketPoolBaseHelper::Request( 661 : internal::ClientSocketPoolBaseHelper::Request(handle,
672 handle, callback, priority, ignore_limits, flags, net_log), 662 callback,
663 priority,
664 ignore_limits,
665 flags,
666 net_log),
673 params_(params) {} 667 params_(params) {}
674 668
675 const scoped_refptr<SocketParams>& params() const { return params_; } 669 const scoped_refptr<SocketParams>& params() const { return params_; }
676 670
677 private: 671 private:
678 const scoped_refptr<SocketParams> params_; 672 const scoped_refptr<SocketParams> params_;
679 }; 673 };
680 674
681 class ConnectJobFactory { 675 class ConnectJobFactory {
682 public: 676 public:
(...skipping 10 matching lines...) Expand all
693 private: 687 private:
694 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); 688 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory);
695 }; 689 };
696 690
697 // |max_sockets| is the maximum number of sockets to be maintained by this 691 // |max_sockets| is the maximum number of sockets to be maintained by this
698 // ClientSocketPool. |max_sockets_per_group| specifies the maximum number of 692 // ClientSocketPool. |max_sockets_per_group| specifies the maximum number of
699 // sockets a "group" can have. |unused_idle_socket_timeout| specifies how 693 // sockets a "group" can have. |unused_idle_socket_timeout| specifies how
700 // long to leave an unused idle socket open before closing it. 694 // long to leave an unused idle socket open before closing it.
701 // |used_idle_socket_timeout| specifies how long to leave a previously used 695 // |used_idle_socket_timeout| specifies how long to leave a previously used
702 // idle socket open before closing it. 696 // idle socket open before closing it.
703 ClientSocketPoolBase( 697 ClientSocketPoolBase(HigherLayeredPool* self,
704 HigherLayeredPool* self, 698 int max_sockets,
705 int max_sockets, 699 int max_sockets_per_group,
706 int max_sockets_per_group, 700 ClientSocketPoolHistograms* histograms,
707 ClientSocketPoolHistograms* histograms, 701 base::TimeDelta unused_idle_socket_timeout,
708 base::TimeDelta unused_idle_socket_timeout, 702 base::TimeDelta used_idle_socket_timeout,
709 base::TimeDelta used_idle_socket_timeout, 703 ConnectJobFactory* connect_job_factory)
710 ConnectJobFactory* connect_job_factory)
711 : histograms_(histograms), 704 : histograms_(histograms),
712 helper_(self, max_sockets, max_sockets_per_group, 705 helper_(self,
713 unused_idle_socket_timeout, used_idle_socket_timeout, 706 max_sockets,
707 max_sockets_per_group,
708 unused_idle_socket_timeout,
709 used_idle_socket_timeout,
714 new ConnectJobFactoryAdaptor(connect_job_factory)) {} 710 new ConnectJobFactoryAdaptor(connect_job_factory)) {}
715 711
716 virtual ~ClientSocketPoolBase() {} 712 virtual ~ClientSocketPoolBase() {}
717 713
718 // These member functions simply forward to ClientSocketPoolBaseHelper. 714 // These member functions simply forward to ClientSocketPoolBaseHelper.
719 void AddLowerLayeredPool(LowerLayeredPool* lower_pool) { 715 void AddLowerLayeredPool(LowerLayeredPool* lower_pool) {
720 helper_.AddLowerLayeredPool(lower_pool); 716 helper_.AddLowerLayeredPool(lower_pool);
721 } 717 }
722 718
723 void AddHigherLayeredPool(HigherLayeredPool* higher_pool) { 719 void AddHigherLayeredPool(HigherLayeredPool* higher_pool) {
724 helper_.AddHigherLayeredPool(higher_pool); 720 helper_.AddHigherLayeredPool(higher_pool);
725 } 721 }
726 722
727 void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) { 723 void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) {
728 helper_.RemoveHigherLayeredPool(higher_pool); 724 helper_.RemoveHigherLayeredPool(higher_pool);
729 } 725 }
730 726
731 // RequestSocket bundles up the parameters into a Request and then forwards to 727 // RequestSocket bundles up the parameters into a Request and then forwards to
732 // ClientSocketPoolBaseHelper::RequestSocket(). 728 // ClientSocketPoolBaseHelper::RequestSocket().
733 int RequestSocket(const std::string& group_name, 729 int RequestSocket(const std::string& group_name,
734 const scoped_refptr<SocketParams>& params, 730 const scoped_refptr<SocketParams>& params,
735 RequestPriority priority, 731 RequestPriority priority,
736 ClientSocketHandle* handle, 732 ClientSocketHandle* handle,
737 const CompletionCallback& callback, 733 const CompletionCallback& callback,
738 const BoundNetLog& net_log) { 734 const BoundNetLog& net_log) {
739 scoped_ptr<const Request> request( 735 scoped_ptr<const Request> request(
740 new Request(handle, callback, priority, 736 new Request(handle,
737 callback,
738 priority,
741 internal::ClientSocketPoolBaseHelper::NORMAL, 739 internal::ClientSocketPoolBaseHelper::NORMAL,
742 params->ignore_limits(), 740 params->ignore_limits(),
743 params, net_log)); 741 params,
742 net_log));
744 return helper_.RequestSocket( 743 return helper_.RequestSocket(
745 group_name, 744 group_name,
746 request.template PassAs< 745 request.template PassAs<
747 const internal::ClientSocketPoolBaseHelper::Request>()); 746 const internal::ClientSocketPoolBaseHelper::Request>());
748 } 747 }
749 748
750 // RequestSockets bundles up the parameters into a Request and then forwards 749 // RequestSockets bundles up the parameters into a Request and then forwards
751 // to ClientSocketPoolBaseHelper::RequestSockets(). Note that it assigns the 750 // to ClientSocketPoolBaseHelper::RequestSockets(). Note that it assigns the
752 // priority to DEFAULT_PRIORITY and specifies the NO_IDLE_SOCKETS flag. 751 // priority to DEFAULT_PRIORITY and specifies the NO_IDLE_SOCKETS flag.
753 void RequestSockets(const std::string& group_name, 752 void RequestSockets(const std::string& group_name,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 817
819 base::DictionaryValue* GetInfoAsValue(const std::string& name, 818 base::DictionaryValue* GetInfoAsValue(const std::string& name,
820 const std::string& type) const { 819 const std::string& type) const {
821 return helper_.GetInfoAsValue(name, type); 820 return helper_.GetInfoAsValue(name, type);
822 } 821 }
823 822
824 base::TimeDelta ConnectionTimeout() const { 823 base::TimeDelta ConnectionTimeout() const {
825 return helper_.ConnectionTimeout(); 824 return helper_.ConnectionTimeout();
826 } 825 }
827 826
828 ClientSocketPoolHistograms* histograms() const { 827 ClientSocketPoolHistograms* histograms() const { return histograms_; }
829 return histograms_;
830 }
831 828
832 void EnableConnectBackupJobs() { helper_.EnableConnectBackupJobs(); } 829 void EnableConnectBackupJobs() { helper_.EnableConnectBackupJobs(); }
833 830
834 bool CloseOneIdleSocket() { return helper_.CloseOneIdleSocket(); } 831 bool CloseOneIdleSocket() { return helper_.CloseOneIdleSocket(); }
835 832
836 bool CloseOneIdleConnectionInHigherLayeredPool() { 833 bool CloseOneIdleConnectionInHigherLayeredPool() {
837 return helper_.CloseOneIdleConnectionInHigherLayeredPool(); 834 return helper_.CloseOneIdleConnectionInHigherLayeredPool();
838 } 835 }
839 836
840 private: 837 private:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 // Histograms for the pool 869 // Histograms for the pool
873 ClientSocketPoolHistograms* const histograms_; 870 ClientSocketPoolHistograms* const histograms_;
874 internal::ClientSocketPoolBaseHelper helper_; 871 internal::ClientSocketPoolBaseHelper helper_;
875 872
876 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); 873 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase);
877 }; 874 };
878 875
879 } // namespace net 876 } // namespace net
880 877
881 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ 878 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698