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

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

Issue 6930014: Rename ClientSocket to StreamSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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
« no previous file with comments | « net/socket/client_socket_pool_base.h ('k') | net/socket/client_socket_pool_base_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "net/socket/client_socket_pool_base.h" 5 #include "net/socket/client_socket_pool_base.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/stats_counters.h" 10 #include "base/metrics/stats_counters.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 return rv; 80 return rv;
81 } 81 }
82 82
83 void ConnectJob::UseForNormalRequest() { 83 void ConnectJob::UseForNormalRequest() {
84 DCHECK_EQ(UNUSED_PRECONNECT, preconnect_state_); 84 DCHECK_EQ(UNUSED_PRECONNECT, preconnect_state_);
85 preconnect_state_ = USED_PRECONNECT; 85 preconnect_state_ = USED_PRECONNECT;
86 } 86 }
87 87
88 void ConnectJob::set_socket(ClientSocket* socket) { 88 void ConnectJob::set_socket(StreamSocket* socket) {
89 if (socket) { 89 if (socket) {
90 net_log().AddEvent(NetLog::TYPE_CONNECT_JOB_SET_SOCKET, make_scoped_refptr( 90 net_log().AddEvent(NetLog::TYPE_CONNECT_JOB_SET_SOCKET, make_scoped_refptr(
91 new NetLogSourceParameter("source_dependency", 91 new NetLogSourceParameter("source_dependency",
92 socket->NetLog().source()))); 92 socket->NetLog().source())));
93 } 93 }
94 socket_.reset(socket); 94 socket_.reset(socket);
95 } 95 }
96 96
97 void ConnectJob::NotifyDelegateOfCompletion(int rv) { 97 void ConnectJob::NotifyDelegateOfCompletion(int rv) {
98 // The delegate will delete |this|. 98 // The delegate will delete |this|.
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 group->IsEmpty() && !group->HasBackupJob() && 336 group->IsEmpty() && !group->HasBackupJob() &&
337 handle) { 337 handle) {
338 group->StartBackupSocketTimer(group_name, this); 338 group->StartBackupSocketTimer(group_name, this);
339 } 339 }
340 340
341 connecting_socket_count_++; 341 connecting_socket_count_++;
342 342
343 group->AddJob(connect_job.release()); 343 group->AddJob(connect_job.release());
344 } else { 344 } else {
345 LogBoundConnectJobToRequest(connect_job->net_log().source(), request); 345 LogBoundConnectJobToRequest(connect_job->net_log().source(), request);
346 ClientSocket* error_socket = NULL; 346 StreamSocket* error_socket = NULL;
347 if (!preconnecting) { 347 if (!preconnecting) {
348 DCHECK(handle); 348 DCHECK(handle);
349 connect_job->GetAdditionalErrorState(handle); 349 connect_job->GetAdditionalErrorState(handle);
350 error_socket = connect_job->ReleaseSocket(); 350 error_socket = connect_job->ReleaseSocket();
351 } 351 }
352 if (error_socket) { 352 if (error_socket) {
353 HandOutSocket(error_socket, false /* not reused */, handle, 353 HandOutSocket(error_socket, false /* not reused */, handle,
354 base::TimeDelta(), group, request->net_log()); 354 base::TimeDelta(), group, request->net_log());
355 } else if (group->IsEmpty()) { 355 } else if (group->IsEmpty()) {
356 RemoveGroup(group_name); 356 RemoveGroup(group_name);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 make_scoped_refptr(new NetLogSourceParameter( 419 make_scoped_refptr(new NetLogSourceParameter(
420 "source_dependency", connect_job_source))); 420 "source_dependency", connect_job_source)));
421 } 421 }
422 422
423 void ClientSocketPoolBaseHelper::CancelRequest( 423 void ClientSocketPoolBaseHelper::CancelRequest(
424 const std::string& group_name, ClientSocketHandle* handle) { 424 const std::string& group_name, ClientSocketHandle* handle) {
425 PendingCallbackMap::iterator callback_it = pending_callback_map_.find(handle); 425 PendingCallbackMap::iterator callback_it = pending_callback_map_.find(handle);
426 if (callback_it != pending_callback_map_.end()) { 426 if (callback_it != pending_callback_map_.end()) {
427 int result = callback_it->second.result; 427 int result = callback_it->second.result;
428 pending_callback_map_.erase(callback_it); 428 pending_callback_map_.erase(callback_it);
429 ClientSocket* socket = handle->release_socket(); 429 StreamSocket* socket = handle->release_socket();
430 if (socket) { 430 if (socket) {
431 if (result != OK) 431 if (result != OK)
432 socket->Disconnect(); 432 socket->Disconnect();
433 ReleaseSocket(handle->group_name(), socket, handle->id()); 433 ReleaseSocket(handle->group_name(), socket, handle->id());
434 } 434 }
435 return; 435 return;
436 } 436 }
437 437
438 CHECK(ContainsKey(group_map_, group_name)); 438 CHECK(ContainsKey(group_map_, group_name));
439 439
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 timer_.Start(TimeDelta::FromSeconds(kCleanupInterval), this, 659 timer_.Start(TimeDelta::FromSeconds(kCleanupInterval), this,
660 &ClientSocketPoolBaseHelper::OnCleanupTimerFired); 660 &ClientSocketPoolBaseHelper::OnCleanupTimerFired);
661 } 661 }
662 662
663 void ClientSocketPoolBaseHelper::DecrementIdleCount() { 663 void ClientSocketPoolBaseHelper::DecrementIdleCount() {
664 if (--idle_socket_count_ == 0) 664 if (--idle_socket_count_ == 0)
665 timer_.Stop(); 665 timer_.Stop();
666 } 666 }
667 667
668 void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name, 668 void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name,
669 ClientSocket* socket, 669 StreamSocket* socket,
670 int id) { 670 int id) {
671 GroupMap::iterator i = group_map_.find(group_name); 671 GroupMap::iterator i = group_map_.find(group_name);
672 CHECK(i != group_map_.end()); 672 CHECK(i != group_map_.end());
673 673
674 Group* group = i->second; 674 Group* group = i->second;
675 675
676 CHECK_GT(handed_out_socket_count_, 0); 676 CHECK_GT(handed_out_socket_count_, 0);
677 handed_out_socket_count_--; 677 handed_out_socket_count_--;
678 678
679 CHECK_GT(group->active_socket_count(), 0); 679 CHECK_GT(group->active_socket_count(), 0);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 } 750 }
751 751
752 void ClientSocketPoolBaseHelper::OnConnectJobComplete( 752 void ClientSocketPoolBaseHelper::OnConnectJobComplete(
753 int result, ConnectJob* job) { 753 int result, ConnectJob* job) {
754 DCHECK_NE(ERR_IO_PENDING, result); 754 DCHECK_NE(ERR_IO_PENDING, result);
755 const std::string group_name = job->group_name(); 755 const std::string group_name = job->group_name();
756 GroupMap::iterator group_it = group_map_.find(group_name); 756 GroupMap::iterator group_it = group_map_.find(group_name);
757 CHECK(group_it != group_map_.end()); 757 CHECK(group_it != group_map_.end());
758 Group* group = group_it->second; 758 Group* group = group_it->second;
759 759
760 scoped_ptr<ClientSocket> socket(job->ReleaseSocket()); 760 scoped_ptr<StreamSocket> socket(job->ReleaseSocket());
761 761
762 BoundNetLog job_log = job->net_log(); 762 BoundNetLog job_log = job->net_log();
763 763
764 if (result == OK) { 764 if (result == OK) {
765 DCHECK(socket.get()); 765 DCHECK(socket.get());
766 RemoveConnectJob(job, group); 766 RemoveConnectJob(job, group);
767 if (!group->pending_requests().empty()) { 767 if (!group->pending_requests().empty()) {
768 scoped_ptr<const Request> r(RemoveRequestFromQueue( 768 scoped_ptr<const Request> r(RemoveRequestFromQueue(
769 group->mutable_pending_requests()->begin(), group)); 769 group->mutable_pending_requests()->begin(), group));
770 LogBoundConnectJobToRequest(job_log.source(), r.get()); 770 LogBoundConnectJobToRequest(job_log.source(), r.get());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 if (group->IsEmpty()) 854 if (group->IsEmpty())
855 RemoveGroup(group_name); 855 RemoveGroup(group_name);
856 856
857 request->net_log().EndEventWithNetErrorCode(NetLog::TYPE_SOCKET_POOL, rv); 857 request->net_log().EndEventWithNetErrorCode(NetLog::TYPE_SOCKET_POOL, rv);
858 InvokeUserCallbackLater( 858 InvokeUserCallbackLater(
859 request->handle(), request->callback(), rv); 859 request->handle(), request->callback(), rv);
860 } 860 }
861 } 861 }
862 862
863 void ClientSocketPoolBaseHelper::HandOutSocket( 863 void ClientSocketPoolBaseHelper::HandOutSocket(
864 ClientSocket* socket, 864 StreamSocket* socket,
865 bool reused, 865 bool reused,
866 ClientSocketHandle* handle, 866 ClientSocketHandle* handle,
867 base::TimeDelta idle_time, 867 base::TimeDelta idle_time,
868 Group* group, 868 Group* group,
869 const BoundNetLog& net_log) { 869 const BoundNetLog& net_log) {
870 DCHECK(socket); 870 DCHECK(socket);
871 handle->set_socket(socket); 871 handle->set_socket(socket);
872 handle->set_is_reused(reused); 872 handle->set_is_reused(reused);
873 handle->set_idle_time(idle_time); 873 handle->set_idle_time(idle_time);
874 handle->set_pool_id(pool_generation_number_); 874 handle->set_pool_id(pool_generation_number_);
875 875
876 if (reused) { 876 if (reused) {
877 net_log.AddEvent( 877 net_log.AddEvent(
878 NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET, 878 NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET,
879 make_scoped_refptr(new NetLogIntegerParameter( 879 make_scoped_refptr(new NetLogIntegerParameter(
880 "idle_ms", static_cast<int>(idle_time.InMilliseconds())))); 880 "idle_ms", static_cast<int>(idle_time.InMilliseconds()))));
881 } 881 }
882 882
883 net_log.AddEvent(NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET, 883 net_log.AddEvent(NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
884 make_scoped_refptr(new NetLogSourceParameter( 884 make_scoped_refptr(new NetLogSourceParameter(
885 "source_dependency", socket->NetLog().source()))); 885 "source_dependency", socket->NetLog().source())));
886 886
887 handed_out_socket_count_++; 887 handed_out_socket_count_++;
888 group->IncrementActiveSocketCount(); 888 group->IncrementActiveSocketCount();
889 } 889 }
890 890
891 void ClientSocketPoolBaseHelper::AddIdleSocket( 891 void ClientSocketPoolBaseHelper::AddIdleSocket(
892 ClientSocket* socket, Group* group) { 892 StreamSocket* socket, Group* group) {
893 DCHECK(socket); 893 DCHECK(socket);
894 IdleSocket idle_socket; 894 IdleSocket idle_socket;
895 idle_socket.socket = socket; 895 idle_socket.socket = socket;
896 idle_socket.start_time = base::TimeTicks::Now(); 896 idle_socket.start_time = base::TimeTicks::Now();
897 897
898 group->mutable_idle_sockets()->push_back(idle_socket); 898 group->mutable_idle_sockets()->push_back(idle_socket);
899 IncrementIdleCount(); 899 IncrementIdleCount();
900 } 900 }
901 901
902 void ClientSocketPoolBaseHelper::CancelAllConnectJobs() { 902 void ClientSocketPoolBaseHelper::CancelAllConnectJobs() {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 // Delete active jobs. 1084 // Delete active jobs.
1085 STLDeleteElements(&jobs_); 1085 STLDeleteElements(&jobs_);
1086 1086
1087 // Cancel pending backup job. 1087 // Cancel pending backup job.
1088 method_factory_.RevokeAll(); 1088 method_factory_.RevokeAll();
1089 } 1089 }
1090 1090
1091 } // namespace internal 1091 } // namespace internal
1092 1092
1093 } // namespace net 1093 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base.h ('k') | net/socket/client_socket_pool_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698