OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/stats_counters.h" | 10 #include "base/stats_counters.h" |
11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "net/base/load_log.h" | 14 #include "net/base/net_log.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
17 | 17 |
18 using base::TimeDelta; | 18 using base::TimeDelta; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // The timeout value, in seconds, used to clean up idle sockets that can't be | 22 // The timeout value, in seconds, used to clean up idle sockets that can't be |
23 // reused. | 23 // reused. |
24 // | 24 // |
25 // Note: It's important to close idle sockets that have received data as soon | 25 // Note: It's important to close idle sockets that have received data as soon |
26 // as possible because the received data may cause BSOD on Windows XP under | 26 // as possible because the received data may cause BSOD on Windows XP under |
27 // some conditions. See http://crbug.com/4606. | 27 // some conditions. See http://crbug.com/4606. |
28 const int kCleanupInterval = 10; // DO NOT INCREASE THIS TIMEOUT. | 28 const int kCleanupInterval = 10; // DO NOT INCREASE THIS TIMEOUT. |
29 | 29 |
30 // The maximum size of the ConnectJob's LoadLog. | |
31 const int kMaxNumLoadLogEntries = 50; | |
32 | |
33 } // namespace | 30 } // namespace |
34 | 31 |
35 namespace net { | 32 namespace net { |
36 | 33 |
37 ConnectJob::ConnectJob(const std::string& group_name, | 34 ConnectJob::ConnectJob(const std::string& group_name, |
38 base::TimeDelta timeout_duration, | 35 base::TimeDelta timeout_duration, |
39 Delegate* delegate, | 36 Delegate* delegate, |
40 LoadLog* load_log) | 37 const BoundNetLog& net_log) |
41 : group_name_(group_name), | 38 : group_name_(group_name), |
42 timeout_duration_(timeout_duration), | 39 timeout_duration_(timeout_duration), |
43 delegate_(delegate), | 40 delegate_(delegate), |
44 load_log_(load_log) { | 41 net_log_(net_log) { |
45 DCHECK(!group_name.empty()); | 42 DCHECK(!group_name.empty()); |
46 DCHECK(delegate); | 43 DCHECK(delegate); |
47 } | 44 } |
48 | 45 |
49 ConnectJob::~ConnectJob() { | 46 ConnectJob::~ConnectJob() { |
50 if (delegate_) { | 47 if (delegate_) { |
51 // If the delegate was not NULLed, then NotifyDelegateOfCompletion has | 48 // If the delegate was not NULLed, then NotifyDelegateOfCompletion has |
52 // not been called yet (hence we are cancelling). | 49 // not been called yet (hence we are cancelling). |
53 LoadLog::AddEvent(load_log_, LoadLog::TYPE_CANCELLED); | 50 net_log_.AddEvent(NetLog::TYPE_CANCELLED); |
54 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKET_POOL_CONNECT_JOB); | 51 net_log_.EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB); |
55 } | 52 } |
56 } | 53 } |
57 | 54 |
58 int ConnectJob::Connect() { | 55 int ConnectJob::Connect() { |
59 if (timeout_duration_ != base::TimeDelta()) | 56 if (timeout_duration_ != base::TimeDelta()) |
60 timer_.Start(timeout_duration_, this, &ConnectJob::OnTimeout); | 57 timer_.Start(timeout_duration_, this, &ConnectJob::OnTimeout); |
61 | 58 |
62 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_SOCKET_POOL_CONNECT_JOB); | 59 net_log_.BeginEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB); |
63 | 60 |
64 int rv = ConnectInternal(); | 61 int rv = ConnectInternal(); |
65 | 62 |
66 if (rv != ERR_IO_PENDING) { | 63 if (rv != ERR_IO_PENDING) { |
67 delegate_ = NULL; | 64 delegate_ = NULL; |
68 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKET_POOL_CONNECT_JOB); | 65 net_log_.EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB); |
69 } | 66 } |
70 | 67 |
71 return rv; | 68 return rv; |
72 } | 69 } |
73 | 70 |
74 void ConnectJob::NotifyDelegateOfCompletion(int rv) { | 71 void ConnectJob::NotifyDelegateOfCompletion(int rv) { |
75 // The delegate will delete |this|. | 72 // The delegate will delete |this|. |
76 Delegate *delegate = delegate_; | 73 Delegate *delegate = delegate_; |
77 delegate_ = NULL; | 74 delegate_ = NULL; |
78 | 75 |
79 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKET_POOL_CONNECT_JOB); | 76 net_log_.EndEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB); |
80 | 77 |
81 delegate->OnConnectJobComplete(rv, this); | 78 delegate->OnConnectJobComplete(rv, this); |
82 } | 79 } |
83 | 80 |
84 void ConnectJob::OnTimeout() { | 81 void ConnectJob::OnTimeout() { |
85 // Make sure the socket is NULL before calling into |delegate|. | 82 // Make sure the socket is NULL before calling into |delegate|. |
86 set_socket(NULL); | 83 set_socket(NULL); |
87 | 84 |
88 LoadLog::AddEvent(load_log_, | 85 net_log_.AddEvent(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT); |
89 LoadLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT); | |
90 | 86 |
91 NotifyDelegateOfCompletion(ERR_TIMED_OUT); | 87 NotifyDelegateOfCompletion(ERR_TIMED_OUT); |
92 } | 88 } |
93 | 89 |
94 namespace internal { | 90 namespace internal { |
95 | 91 |
96 ClientSocketPoolBaseHelper::Request::Request( | 92 ClientSocketPoolBaseHelper::Request::Request( |
97 ClientSocketHandle* handle, | 93 ClientSocketHandle* handle, |
98 CompletionCallback* callback, | 94 CompletionCallback* callback, |
99 RequestPriority priority, | 95 RequestPriority priority, |
100 LoadLog* load_log) | 96 const BoundNetLog& net_log) |
101 : handle_(handle), callback_(callback), priority_(priority), | 97 : handle_(handle), callback_(callback), priority_(priority), |
102 load_log_(load_log) {} | 98 net_log_(net_log) {} |
103 | 99 |
104 ClientSocketPoolBaseHelper::Request::~Request() {} | 100 ClientSocketPoolBaseHelper::Request::~Request() {} |
105 | 101 |
106 ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( | 102 ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( |
107 int max_sockets, | 103 int max_sockets, |
108 int max_sockets_per_group, | 104 int max_sockets_per_group, |
109 base::TimeDelta unused_idle_socket_timeout, | 105 base::TimeDelta unused_idle_socket_timeout, |
110 base::TimeDelta used_idle_socket_timeout, | 106 base::TimeDelta used_idle_socket_timeout, |
111 ConnectJobFactory* connect_job_factory, | 107 ConnectJobFactory* connect_job_factory, |
112 NetworkChangeNotifier* network_change_notifier) | 108 NetworkChangeNotifier* network_change_notifier) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 ClientSocketPoolBaseHelper::RemoveRequestFromQueue( | 156 ClientSocketPoolBaseHelper::RemoveRequestFromQueue( |
161 RequestQueue::iterator it, RequestQueue* pending_requests) { | 157 RequestQueue::iterator it, RequestQueue* pending_requests) { |
162 const Request* req = *it; | 158 const Request* req = *it; |
163 pending_requests->erase(it); | 159 pending_requests->erase(it); |
164 return req; | 160 return req; |
165 } | 161 } |
166 | 162 |
167 int ClientSocketPoolBaseHelper::RequestSocket( | 163 int ClientSocketPoolBaseHelper::RequestSocket( |
168 const std::string& group_name, | 164 const std::string& group_name, |
169 const Request* request) { | 165 const Request* request) { |
170 LoadLog::BeginEvent(request->load_log(), LoadLog::TYPE_SOCKET_POOL); | 166 request->net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL); |
171 Group& group = group_map_[group_name]; | 167 Group& group = group_map_[group_name]; |
172 int rv = RequestSocketInternal(group_name, request); | 168 int rv = RequestSocketInternal(group_name, request); |
173 if (rv != ERR_IO_PENDING) | 169 if (rv != ERR_IO_PENDING) |
174 LoadLog::EndEvent(request->load_log(), LoadLog::TYPE_SOCKET_POOL); | 170 request->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL); |
175 else | 171 else |
176 InsertRequestIntoQueue(request, &group.pending_requests); | 172 InsertRequestIntoQueue(request, &group.pending_requests); |
177 return rv; | 173 return rv; |
178 } | 174 } |
179 | 175 |
180 int ClientSocketPoolBaseHelper::RequestSocketInternal( | 176 int ClientSocketPoolBaseHelper::RequestSocketInternal( |
181 const std::string& group_name, | 177 const std::string& group_name, |
182 const Request* request) { | 178 const Request* request) { |
183 DCHECK_GE(request->priority(), 0); | 179 DCHECK_GE(request->priority(), 0); |
184 CompletionCallback* const callback = request->callback(); | 180 CompletionCallback* const callback = request->callback(); |
185 CHECK(callback); | 181 CHECK(callback); |
186 ClientSocketHandle* const handle = request->handle(); | 182 ClientSocketHandle* const handle = request->handle(); |
187 CHECK(handle); | 183 CHECK(handle); |
188 Group& group = group_map_[group_name]; | 184 Group& group = group_map_[group_name]; |
189 | 185 |
190 // Can we make another active socket now? | 186 // Can we make another active socket now? |
191 if (ReachedMaxSocketsLimit() || | 187 if (ReachedMaxSocketsLimit() || |
192 !group.HasAvailableSocketSlot(max_sockets_per_group_)) { | 188 !group.HasAvailableSocketSlot(max_sockets_per_group_)) { |
193 if (ReachedMaxSocketsLimit()) { | 189 if (ReachedMaxSocketsLimit()) { |
194 // We could check if we really have a stalled group here, but it requires | 190 // We could check if we really have a stalled group here, but it requires |
195 // a scan of all groups, so just flip a flag here, and do the check later. | 191 // a scan of all groups, so just flip a flag here, and do the check later. |
196 may_have_stalled_group_ = true; | 192 may_have_stalled_group_ = true; |
197 | 193 |
198 LoadLog::AddEvent( | 194 request->net_log().AddEvent(NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS); |
199 request->load_log(), | |
200 LoadLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS); | |
201 } else { | 195 } else { |
202 LoadLog::AddEvent( | 196 request->net_log().AddEvent(NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS_P
ER_GROUP); |
203 request->load_log(), | |
204 LoadLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP); | |
205 } | 197 } |
206 return ERR_IO_PENDING; | 198 return ERR_IO_PENDING; |
207 } | 199 } |
208 | 200 |
209 // Try to reuse a socket. | 201 // Try to reuse a socket. |
210 while (!group.idle_sockets.empty()) { | 202 while (!group.idle_sockets.empty()) { |
211 IdleSocket idle_socket = group.idle_sockets.back(); | 203 IdleSocket idle_socket = group.idle_sockets.back(); |
212 group.idle_sockets.pop_back(); | 204 group.idle_sockets.pop_back(); |
213 DecrementIdleCount(); | 205 DecrementIdleCount(); |
214 if (idle_socket.socket->IsConnectedAndIdle()) { | 206 if (idle_socket.socket->IsConnectedAndIdle()) { |
215 // We found one we can reuse! | 207 // We found one we can reuse! |
216 base::TimeDelta idle_time = | 208 base::TimeDelta idle_time = |
217 base::TimeTicks::Now() - idle_socket.start_time; | 209 base::TimeTicks::Now() - idle_socket.start_time; |
218 HandOutSocket( | 210 HandOutSocket( |
219 idle_socket.socket, idle_socket.used, handle, idle_time, &group, | 211 idle_socket.socket, idle_socket.used, handle, idle_time, &group, |
220 request->load_log()); | 212 request->net_log()); |
221 return OK; | 213 return OK; |
222 } | 214 } |
223 delete idle_socket.socket; | 215 delete idle_socket.socket; |
224 } | 216 } |
225 | 217 |
226 // See if we already have enough connect jobs or sockets that will be released | 218 // See if we already have enough connect jobs or sockets that will be released |
227 // soon. | 219 // soon. |
228 if (group.HasReleasingSockets()) { | 220 if (group.HasReleasingSockets()) { |
229 return ERR_IO_PENDING; | 221 return ERR_IO_PENDING; |
230 } | 222 } |
231 | 223 |
232 // We couldn't find a socket to reuse, so allocate and connect a new one. | 224 // We couldn't find a socket to reuse, so allocate and connect a new one. |
233 scoped_refptr<LoadLog> job_load_log = new LoadLog(kMaxNumLoadLogEntries); | 225 BoundNetLog job_net_log = BoundNetLog::Make( |
| 226 request->net_log().net_log(), NetLog::SOURCE_CONNECT_JOB); |
234 | 227 |
235 scoped_ptr<ConnectJob> connect_job( | 228 scoped_ptr<ConnectJob> connect_job( |
236 connect_job_factory_->NewConnectJob(group_name, *request, this, | 229 connect_job_factory_->NewConnectJob(group_name, *request, this, |
237 job_load_log)); | 230 job_net_log)); |
238 | 231 |
239 int rv = connect_job->Connect(); | 232 int rv = connect_job->Connect(); |
240 | 233 |
241 if (rv != ERR_IO_PENDING && request->load_log()) | 234 if (rv != ERR_IO_PENDING) { |
242 request->load_log()->Append(job_load_log); | 235 request->net_log().AddEventWithInteger(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_
ID, |
| 236 job_net_log.source().id); |
| 237 } |
243 | 238 |
244 if (rv == OK) { | 239 if (rv == OK) { |
245 HandOutSocket(connect_job->ReleaseSocket(), false /* not reused */, | 240 HandOutSocket(connect_job->ReleaseSocket(), false /* not reused */, |
246 handle, base::TimeDelta(), &group, request->load_log()); | 241 handle, base::TimeDelta(), &group, request->net_log()); |
247 } else if (rv == ERR_IO_PENDING) { | 242 } else if (rv == ERR_IO_PENDING) { |
248 // If we don't have any sockets in this group, set a timer for potentially | 243 // If we don't have any sockets in this group, set a timer for potentially |
249 // creating a new one. If the SYN is lost, this backup socket may complete | 244 // creating a new one. If the SYN is lost, this backup socket may complete |
250 // before the slow socket, improving end user latency. | 245 // before the slow socket, improving end user latency. |
251 if (group.IsEmpty() && !group.backup_job) { | 246 if (group.IsEmpty() && !group.backup_job) { |
252 group.backup_job = connect_job_factory_->NewConnectJob(group_name, | 247 group.backup_job = connect_job_factory_->NewConnectJob(group_name, |
253 *request, | 248 *request, |
254 this, | 249 this, |
255 job_load_log); | 250 job_net_log); |
256 StartBackupSocketTimer(group_name); | 251 StartBackupSocketTimer(group_name); |
257 } | 252 } |
258 | 253 |
259 connecting_socket_count_++; | 254 connecting_socket_count_++; |
260 | 255 |
261 ConnectJob* job = connect_job.release(); | 256 ConnectJob* job = connect_job.release(); |
262 group.jobs.insert(job); | 257 group.jobs.insert(job); |
263 } else if (group.IsEmpty()) { | 258 } else if (group.IsEmpty()) { |
264 group_map_.erase(group_name); | 259 group_map_.erase(group_name); |
265 } | 260 } |
(...skipping 23 matching lines...) Expand all Loading... |
289 Group& group = group_map_[group_name]; | 284 Group& group = group_map_[group_name]; |
290 | 285 |
291 CHECK(group.backup_task); | 286 CHECK(group.backup_task); |
292 group.backup_task = NULL; | 287 group.backup_task = NULL; |
293 | 288 |
294 CHECK(group.backup_job); | 289 CHECK(group.backup_job); |
295 | 290 |
296 // If our backup job is waiting on DNS, just reset the timer. | 291 // If our backup job is waiting on DNS, just reset the timer. |
297 CHECK(group.jobs.size()); | 292 CHECK(group.jobs.size()); |
298 if ((*group.jobs.begin())->GetLoadState() == LOAD_STATE_RESOLVING_HOST) { | 293 if ((*group.jobs.begin())->GetLoadState() == LOAD_STATE_RESOLVING_HOST) { |
299 LoadLog::AddEvent(group.backup_job->load_log(), | 294 group.backup_job->net_log().EndEvent( |
300 LoadLog::TYPE_SOCKET_BACKUP_TIMER_EXTENDED); | 295 NetLog::TYPE_SOCKET_BACKUP_TIMER_EXTENDED); |
301 StartBackupSocketTimer(group_name); | 296 StartBackupSocketTimer(group_name); |
302 return; | 297 return; |
303 } | 298 } |
304 | 299 |
305 LoadLog::AddEvent(group.backup_job->load_log(), | 300 group.backup_job->net_log().AddEvent(NetLog::TYPE_SOCKET_BACKUP_CREATED); |
306 LoadLog::TYPE_SOCKET_BACKUP_CREATED); | |
307 SIMPLE_STATS_COUNTER("socket.backup_created"); | 301 SIMPLE_STATS_COUNTER("socket.backup_created"); |
308 int rv = group.backup_job->Connect(); | 302 int rv = group.backup_job->Connect(); |
309 if (rv == ERR_IO_PENDING) { | 303 if (rv == ERR_IO_PENDING) { |
310 connecting_socket_count_++; | 304 connecting_socket_count_++; |
311 group.jobs.insert(group.backup_job); | 305 group.jobs.insert(group.backup_job); |
312 group.backup_job = NULL; | 306 group.backup_job = NULL; |
313 } else { | 307 } else { |
314 OnConnectJobComplete(rv, group.backup_job); | 308 OnConnectJobComplete(rv, group.backup_job); |
315 } | 309 } |
316 } | 310 } |
317 | 311 |
318 void ClientSocketPoolBaseHelper::CancelRequest( | 312 void ClientSocketPoolBaseHelper::CancelRequest( |
319 const std::string& group_name, const ClientSocketHandle* handle) { | 313 const std::string& group_name, const ClientSocketHandle* handle) { |
320 CHECK(ContainsKey(group_map_, group_name)); | 314 CHECK(ContainsKey(group_map_, group_name)); |
321 | 315 |
322 Group& group = group_map_[group_name]; | 316 Group& group = group_map_[group_name]; |
323 | 317 |
324 // Search pending_requests for matching handle. | 318 // Search pending_requests for matching handle. |
325 RequestQueue::iterator it = group.pending_requests.begin(); | 319 RequestQueue::iterator it = group.pending_requests.begin(); |
326 for (; it != group.pending_requests.end(); ++it) { | 320 for (; it != group.pending_requests.end(); ++it) { |
327 if ((*it)->handle() == handle) { | 321 if ((*it)->handle() == handle) { |
328 const Request* req = RemoveRequestFromQueue(it, &group.pending_requests); | 322 const Request* req = RemoveRequestFromQueue(it, &group.pending_requests); |
329 LoadLog::AddEvent(req->load_log(), LoadLog::TYPE_CANCELLED); | 323 req->net_log().AddEvent(NetLog::TYPE_CANCELLED); |
330 LoadLog::EndEvent(req->load_log(), LoadLog::TYPE_SOCKET_POOL); | 324 req->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL); |
331 delete req; | 325 delete req; |
332 if (group.jobs.size() > group.pending_requests.size() + 1) { | 326 if (group.jobs.size() > group.pending_requests.size() + 1) { |
333 // TODO(willchan): Cancel the job in the earliest LoadState. | 327 // TODO(willchan): Cancel the job in the earliest LoadState. |
334 RemoveConnectJob(*group.jobs.begin(), &group); | 328 RemoveConnectJob(*group.jobs.begin(), &group); |
335 OnAvailableSocketSlot(group_name, &group); | 329 OnAvailableSocketSlot(group_name, &group); |
336 } | 330 } |
337 return; | 331 return; |
338 } | 332 } |
339 } | 333 } |
340 } | 334 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 GroupMap::iterator group_it = group_map_.find(group_name); | 540 GroupMap::iterator group_it = group_map_.find(group_name); |
547 CHECK(group_it != group_map_.end()); | 541 CHECK(group_it != group_map_.end()); |
548 Group& group = group_it->second; | 542 Group& group = group_it->second; |
549 | 543 |
550 // We've had a connect on the socket; discard any pending backup job | 544 // We've had a connect on the socket; discard any pending backup job |
551 // for this group and kill the pending task. | 545 // for this group and kill the pending task. |
552 group.CleanupBackupJob(); | 546 group.CleanupBackupJob(); |
553 | 547 |
554 scoped_ptr<ClientSocket> socket(job->ReleaseSocket()); | 548 scoped_ptr<ClientSocket> socket(job->ReleaseSocket()); |
555 | 549 |
556 scoped_refptr<LoadLog> job_load_log(job->load_log()); | 550 BoundNetLog job_log = job->net_log(); |
557 RemoveConnectJob(job, &group); | 551 RemoveConnectJob(job, &group); |
558 | 552 |
559 LoadLog::EndEvent(job_load_log, LoadLog::TYPE_SOCKET_POOL); | |
560 | |
561 if (result == OK) { | 553 if (result == OK) { |
562 DCHECK(socket.get()); | 554 DCHECK(socket.get()); |
563 if (!group.pending_requests.empty()) { | 555 if (!group.pending_requests.empty()) { |
564 scoped_ptr<const Request> r(RemoveRequestFromQueue( | 556 scoped_ptr<const Request> r(RemoveRequestFromQueue( |
565 group.pending_requests.begin(), &group.pending_requests)); | 557 group.pending_requests.begin(), &group.pending_requests)); |
566 if (r->load_log()) | 558 r->net_log().AddEventWithInteger(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, |
567 r->load_log()->Append(job_load_log); | 559 job_log.source().id); |
| 560 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL); |
568 HandOutSocket( | 561 HandOutSocket( |
569 socket.release(), false /* unused socket */, r->handle(), | 562 socket.release(), false /* unused socket */, r->handle(), |
570 base::TimeDelta(), &group, r->load_log()); | 563 base::TimeDelta(), &group, r->net_log()); |
571 r->callback()->Run(result); | 564 r->callback()->Run(result); |
572 } else { | 565 } else { |
573 AddIdleSocket(socket.release(), false /* unused socket */, &group); | 566 AddIdleSocket(socket.release(), false /* unused socket */, &group); |
574 OnAvailableSocketSlot(group_name, &group); | 567 OnAvailableSocketSlot(group_name, &group); |
575 } | 568 } |
576 } else { | 569 } else { |
577 DCHECK(!socket.get()); | 570 DCHECK(!socket.get()); |
578 if (!group.pending_requests.empty()) { | 571 if (!group.pending_requests.empty()) { |
579 scoped_ptr<const Request> r(RemoveRequestFromQueue( | 572 scoped_ptr<const Request> r(RemoveRequestFromQueue( |
580 group.pending_requests.begin(), &group.pending_requests)); | 573 group.pending_requests.begin(), &group.pending_requests)); |
581 if (r->load_log()) | 574 r->net_log().AddEventWithInteger(NetLog::TYPE_SOCKET_POOL_CONNECT_JOB_ID, |
582 r->load_log()->Append(job_load_log); | 575 job_log.source().id); |
| 576 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL); |
583 r->callback()->Run(result); | 577 r->callback()->Run(result); |
584 } | 578 } |
585 MaybeOnAvailableSocketSlot(group_name); | 579 MaybeOnAvailableSocketSlot(group_name); |
586 } | 580 } |
587 } | 581 } |
588 | 582 |
589 void ClientSocketPoolBaseHelper::OnIPAddressChanged() { | 583 void ClientSocketPoolBaseHelper::OnIPAddressChanged() { |
590 CloseIdleSockets(); | 584 CloseIdleSockets(); |
591 } | 585 } |
592 | 586 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 group_map_.erase(group_name); | 627 group_map_.erase(group_name); |
634 } | 628 } |
635 } | 629 } |
636 | 630 |
637 void ClientSocketPoolBaseHelper::ProcessPendingRequest( | 631 void ClientSocketPoolBaseHelper::ProcessPendingRequest( |
638 const std::string& group_name, Group* group) { | 632 const std::string& group_name, Group* group) { |
639 scoped_ptr<const Request> r(*group->pending_requests.begin()); | 633 scoped_ptr<const Request> r(*group->pending_requests.begin()); |
640 int rv = RequestSocketInternal(group_name, r.get()); | 634 int rv = RequestSocketInternal(group_name, r.get()); |
641 | 635 |
642 if (rv != ERR_IO_PENDING) { | 636 if (rv != ERR_IO_PENDING) { |
643 LoadLog::EndEvent(r->load_log(), LoadLog::TYPE_SOCKET_POOL); | 637 r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL); |
644 RemoveRequestFromQueue(group->pending_requests.begin(), | 638 RemoveRequestFromQueue(group->pending_requests.begin(), |
645 &group->pending_requests); | 639 &group->pending_requests); |
646 r->callback()->Run(rv); | 640 r->callback()->Run(rv); |
647 if (rv != OK) { | 641 if (rv != OK) { |
648 // |group| may be invalid after the callback, we need to search | 642 // |group| may be invalid after the callback, we need to search |
649 // |group_map_| again. | 643 // |group_map_| again. |
650 MaybeOnAvailableSocketSlot(group_name); | 644 MaybeOnAvailableSocketSlot(group_name); |
651 } | 645 } |
652 } else { | 646 } else { |
653 r.release(); | 647 r.release(); |
654 } | 648 } |
655 } | 649 } |
656 | 650 |
657 void ClientSocketPoolBaseHelper::HandOutSocket( | 651 void ClientSocketPoolBaseHelper::HandOutSocket( |
658 ClientSocket* socket, | 652 ClientSocket* socket, |
659 bool reused, | 653 bool reused, |
660 ClientSocketHandle* handle, | 654 ClientSocketHandle* handle, |
661 base::TimeDelta idle_time, | 655 base::TimeDelta idle_time, |
662 Group* group, | 656 Group* group, |
663 LoadLog* load_log) { | 657 const BoundNetLog& net_log) { |
664 DCHECK(socket); | 658 DCHECK(socket); |
665 handle->set_socket(socket); | 659 handle->set_socket(socket); |
666 handle->set_is_reused(reused); | 660 handle->set_is_reused(reused); |
667 handle->set_idle_time(idle_time); | 661 handle->set_idle_time(idle_time); |
668 | 662 |
669 if (reused) | 663 if (reused) |
670 LoadLog::AddStringLiteral(load_log, "Reusing socket."); | 664 net_log.AddStringLiteral("Reusing socket."); |
671 if (idle_time != base::TimeDelta()) { | 665 if (idle_time != base::TimeDelta()) { |
672 LoadLog::AddString( | 666 net_log.AddString( |
673 load_log, | |
674 StringPrintf("Socket sat idle for %" PRId64 " milliseconds", | 667 StringPrintf("Socket sat idle for %" PRId64 " milliseconds", |
675 idle_time.InMilliseconds())); | 668 idle_time.InMilliseconds())); |
676 } | 669 } |
677 | 670 |
678 handed_out_socket_count_++; | 671 handed_out_socket_count_++; |
679 group->active_socket_count++; | 672 group->active_socket_count++; |
680 } | 673 } |
681 | 674 |
682 void ClientSocketPoolBaseHelper::AddIdleSocket( | 675 void ClientSocketPoolBaseHelper::AddIdleSocket( |
683 ClientSocket* socket, bool used, Group* group) { | 676 ClientSocket* socket, bool used, Group* group) { |
(...skipping 30 matching lines...) Expand all Loading... |
714 bool ClientSocketPoolBaseHelper::ReachedMaxSocketsLimit() const { | 707 bool ClientSocketPoolBaseHelper::ReachedMaxSocketsLimit() const { |
715 // Each connecting socket will eventually connect and be handed out. | 708 // Each connecting socket will eventually connect and be handed out. |
716 int total = handed_out_socket_count_ + connecting_socket_count_; | 709 int total = handed_out_socket_count_ + connecting_socket_count_; |
717 DCHECK_LE(total, max_sockets_); | 710 DCHECK_LE(total, max_sockets_); |
718 return total == max_sockets_; | 711 return total == max_sockets_; |
719 } | 712 } |
720 | 713 |
721 } // namespace internal | 714 } // namespace internal |
722 | 715 |
723 } // namespace net | 716 } // namespace net |
OLD | NEW |