OLD | NEW |
---|---|
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 #include "net/quic/quic_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // Responsible for creating a new QUIC session to the specified server, and | 134 // Responsible for creating a new QUIC session to the specified server, and |
135 // for notifying any associated requests when complete. | 135 // for notifying any associated requests when complete. |
136 class QuicStreamFactory::Job { | 136 class QuicStreamFactory::Job { |
137 public: | 137 public: |
138 Job(QuicStreamFactory* factory, | 138 Job(QuicStreamFactory* factory, |
139 HostResolver* host_resolver, | 139 HostResolver* host_resolver, |
140 const HostPortPair& host_port_pair, | 140 const HostPortPair& host_port_pair, |
141 bool is_https, | 141 bool is_https, |
142 bool was_alternate_protocol_recently_broken, | 142 bool was_alternate_protocol_recently_broken, |
143 PrivacyMode privacy_mode, | 143 PrivacyMode privacy_mode, |
144 base::StringPiece method, | 144 bool is_post, |
145 QuicServerInfo* server_info, | 145 QuicServerInfo* server_info, |
146 const BoundNetLog& net_log); | 146 const BoundNetLog& net_log); |
147 | 147 |
148 // Creates a new job to handle the resumption of for connecting an | 148 // Creates a new job to handle the resumption of for connecting an |
149 // existing session. | 149 // existing session. |
150 Job(QuicStreamFactory* factory, | 150 Job(QuicStreamFactory* factory, |
151 HostResolver* host_resolver, | 151 HostResolver* host_resolver, |
152 QuicClientSession* session, | 152 QuicClientSession* session, |
153 QuicServerId server_id); | 153 QuicServerId server_id); |
154 | 154 |
155 ~Job(); | 155 ~Job(); |
156 | 156 |
157 int Run(const CompletionCallback& callback); | 157 int Run(const CompletionCallback& callback); |
158 | 158 |
159 int DoLoop(int rv); | 159 int DoLoop(int rv); |
160 int DoResolveHost(); | 160 int DoResolveHost(); |
161 int DoResolveHostComplete(int rv); | 161 int DoResolveHostComplete(int rv); |
162 int DoLoadServerInfo(); | 162 int DoLoadServerInfo(); |
163 int DoLoadServerInfoComplete(int rv); | 163 int DoLoadServerInfoComplete(int rv); |
164 int DoConnect(); | 164 int DoConnect(); |
165 int DoResumeConnect(); | 165 int DoResumeConnect(); |
166 int DoConnectComplete(int rv); | 166 int DoConnectComplete(int rv); |
167 | 167 |
168 void OnIOComplete(int rv); | 168 void OnIOComplete(int rv); |
169 | 169 |
170 void RunAuxilaryJob(); | |
171 | |
172 void CancelWaitForDataReadyPendingCallback(); | |
ramant (doing other things)
2015/02/06 19:30:31
Deleted this method. The name of the function was
| |
173 | |
174 void Cancel(); | |
175 | |
170 void CancelWaitForDataReadyCallback(); | 176 void CancelWaitForDataReadyCallback(); |
171 | 177 |
172 CompletionCallback callback() { | 178 const QuicServerId server_id() const { return server_id_; } |
173 return callback_; | |
174 } | |
175 | 179 |
176 const QuicServerId server_id() const { | 180 base::WeakPtr<Job> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } |
177 return server_id_; | |
178 } | |
179 | 181 |
180 private: | 182 private: |
181 enum IoState { | 183 enum IoState { |
182 STATE_NONE, | 184 STATE_NONE, |
183 STATE_RESOLVE_HOST, | 185 STATE_RESOLVE_HOST, |
184 STATE_RESOLVE_HOST_COMPLETE, | 186 STATE_RESOLVE_HOST_COMPLETE, |
185 STATE_LOAD_SERVER_INFO, | 187 STATE_LOAD_SERVER_INFO, |
186 STATE_LOAD_SERVER_INFO_COMPLETE, | 188 STATE_LOAD_SERVER_INFO_COMPLETE, |
187 STATE_CONNECT, | 189 STATE_CONNECT, |
188 STATE_RESUME_CONNECT, | 190 STATE_RESUME_CONNECT, |
189 STATE_CONNECT_COMPLETE, | 191 STATE_CONNECT_COMPLETE, |
190 }; | 192 }; |
191 IoState io_state_; | 193 IoState io_state_; |
192 | 194 |
193 QuicStreamFactory* factory_; | 195 QuicStreamFactory* factory_; |
194 SingleRequestHostResolver host_resolver_; | 196 SingleRequestHostResolver host_resolver_; |
195 QuicServerId server_id_; | 197 QuicServerId server_id_; |
196 bool is_post_; | 198 bool is_post_; |
197 bool was_alternate_protocol_recently_broken_; | 199 bool was_alternate_protocol_recently_broken_; |
198 scoped_ptr<QuicServerInfo> server_info_; | 200 scoped_ptr<QuicServerInfo> server_info_; |
201 bool started_another_job_; | |
199 const BoundNetLog net_log_; | 202 const BoundNetLog net_log_; |
200 QuicClientSession* session_; | 203 QuicClientSession* session_; |
201 CompletionCallback callback_; | 204 CompletionCallback callback_; |
202 AddressList address_list_; | 205 AddressList address_list_; |
203 base::TimeTicks disk_cache_load_start_time_; | 206 base::TimeTicks disk_cache_load_start_time_; |
204 base::TimeTicks dns_resolution_start_time_; | 207 base::TimeTicks dns_resolution_start_time_; |
205 base::WeakPtrFactory<Job> weak_factory_; | 208 base::WeakPtrFactory<Job> weak_factory_; |
206 DISALLOW_COPY_AND_ASSIGN(Job); | 209 DISALLOW_COPY_AND_ASSIGN(Job); |
207 }; | 210 }; |
208 | 211 |
209 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | 212 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, |
210 HostResolver* host_resolver, | 213 HostResolver* host_resolver, |
211 const HostPortPair& host_port_pair, | 214 const HostPortPair& host_port_pair, |
212 bool is_https, | 215 bool is_https, |
213 bool was_alternate_protocol_recently_broken, | 216 bool was_alternate_protocol_recently_broken, |
214 PrivacyMode privacy_mode, | 217 PrivacyMode privacy_mode, |
215 base::StringPiece method, | 218 bool is_post, |
216 QuicServerInfo* server_info, | 219 QuicServerInfo* server_info, |
217 const BoundNetLog& net_log) | 220 const BoundNetLog& net_log) |
218 : io_state_(STATE_RESOLVE_HOST), | 221 : io_state_(STATE_RESOLVE_HOST), |
219 factory_(factory), | 222 factory_(factory), |
220 host_resolver_(host_resolver), | 223 host_resolver_(host_resolver), |
221 server_id_(host_port_pair, is_https, privacy_mode), | 224 server_id_(host_port_pair, is_https, privacy_mode), |
222 is_post_(method == "POST"), | 225 is_post_(is_post), |
223 was_alternate_protocol_recently_broken_( | 226 was_alternate_protocol_recently_broken_( |
224 was_alternate_protocol_recently_broken), | 227 was_alternate_protocol_recently_broken), |
225 server_info_(server_info), | 228 server_info_(server_info), |
229 started_another_job_(false), | |
226 net_log_(net_log), | 230 net_log_(net_log), |
227 session_(nullptr), | 231 session_(nullptr), |
228 weak_factory_(this) {} | 232 weak_factory_(this) { |
233 } | |
229 | 234 |
230 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | 235 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, |
231 HostResolver* host_resolver, | 236 HostResolver* host_resolver, |
232 QuicClientSession* session, | 237 QuicClientSession* session, |
233 QuicServerId server_id) | 238 QuicServerId server_id) |
234 : io_state_(STATE_RESUME_CONNECT), | 239 : io_state_(STATE_RESUME_CONNECT), |
235 factory_(factory), | 240 factory_(factory), |
236 host_resolver_(host_resolver), // unused | 241 host_resolver_(host_resolver), // unused |
237 server_id_(server_id), | 242 server_id_(server_id), |
238 is_post_(false), // unused | 243 is_post_(false), // unused |
239 was_alternate_protocol_recently_broken_(false), // unused | 244 was_alternate_protocol_recently_broken_(false), // unused |
240 net_log_(session->net_log()), // unused | 245 started_another_job_(false), // unused |
246 net_log_(session->net_log()), // unused | |
241 session_(session), | 247 session_(session), |
242 weak_factory_(this) {} | 248 weak_factory_(this) { |
249 } | |
243 | 250 |
244 QuicStreamFactory::Job::~Job() { | 251 QuicStreamFactory::Job::~Job() { |
252 CancelWaitForDataReadyPendingCallback(); | |
245 } | 253 } |
246 | 254 |
247 int QuicStreamFactory::Job::Run(const CompletionCallback& callback) { | 255 int QuicStreamFactory::Job::Run(const CompletionCallback& callback) { |
248 int rv = DoLoop(OK); | 256 int rv = DoLoop(OK); |
249 if (rv == ERR_IO_PENDING) | 257 if (rv == ERR_IO_PENDING) |
250 callback_ = callback; | 258 callback_ = callback; |
251 | 259 |
252 return rv > 0 ? OK : rv; | 260 return rv > 0 ? OK : rv; |
253 } | 261 } |
254 | 262 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 | 308 |
301 tracked_objects::ScopedTracker tracking_profile2( | 309 tracked_objects::ScopedTracker tracking_profile2( |
302 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 310 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
303 "422516 QuicStreamFactory::Job::OnIOComplete2")); | 311 "422516 QuicStreamFactory::Job::OnIOComplete2")); |
304 | 312 |
305 if (rv != ERR_IO_PENDING && !callback_.is_null()) { | 313 if (rv != ERR_IO_PENDING && !callback_.is_null()) { |
306 callback_.Run(rv); | 314 callback_.Run(rv); |
307 } | 315 } |
308 } | 316 } |
309 | 317 |
318 void QuicStreamFactory::Job::RunAuxilaryJob() { | |
319 int rv = Run(base::Bind(&QuicStreamFactory::OnJobComplete, | |
320 base::Unretained(factory_), this)); | |
321 if (rv == OK) | |
322 factory_->OnJobComplete(this, rv); | |
323 } | |
324 | |
325 void QuicStreamFactory::Job::CancelWaitForDataReadyPendingCallback() { | |
326 // If we are waiting for WaitForDataReadyCallback, then cancel the pending | |
327 // callback. | |
328 if (server_info_ && io_state_ == STATE_LOAD_SERVER_INFO_COMPLETE) | |
329 server_info_->CancelWaitForDataReadyCallback(); | |
330 } | |
331 | |
332 void QuicStreamFactory::Job::Cancel() { | |
333 callback_.Reset(); | |
334 if (session_) | |
335 session_->connection()->SendConnectionClose(QUIC_CONNECTION_CANCELLED); | |
336 } | |
337 | |
310 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { | 338 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { |
311 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. | 339 CancelWaitForDataReadyPendingCallback(); |
Ryan Hamilton
2015/02/06 18:22:47
Does this call itself?
ramant (doing other things)
2015/02/06 19:30:31
Undid this change. Restored the original code.
IM
| |
312 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) | |
313 return; | |
314 server_info_->CancelWaitForDataReadyCallback(); | |
315 OnIOComplete(OK); | 340 OnIOComplete(OK); |
316 } | 341 } |
317 | 342 |
318 int QuicStreamFactory::Job::DoResolveHost() { | 343 int QuicStreamFactory::Job::DoResolveHost() { |
319 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 344 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
320 tracked_objects::ScopedTracker tracking_profile( | 345 tracked_objects::ScopedTracker tracking_profile( |
321 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 346 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
322 "422516 QuicStreamFactory::Job::DoResolveHost")); | 347 "422516 QuicStreamFactory::Job::DoResolveHost")); |
323 | 348 |
324 // Start loading the data now, and wait for it after we resolve the host. | 349 // Start loading the data now, and wait for it after we resolve the host. |
325 if (server_info_) { | 350 if (server_info_) { |
326 server_info_->Start(); | 351 server_info_->Start(); |
327 } | 352 } |
328 | 353 |
329 io_state_ = STATE_RESOLVE_HOST_COMPLETE; | 354 io_state_ = STATE_RESOLVE_HOST_COMPLETE; |
330 dns_resolution_start_time_ = base::TimeTicks::Now(); | 355 dns_resolution_start_time_ = base::TimeTicks::Now(); |
331 return host_resolver_.Resolve( | 356 return host_resolver_.Resolve( |
332 HostResolver::RequestInfo(server_id_.host_port_pair()), | 357 HostResolver::RequestInfo(server_id_.host_port_pair()), DEFAULT_PRIORITY, |
333 DEFAULT_PRIORITY, | |
334 &address_list_, | 358 &address_list_, |
335 base::Bind(&QuicStreamFactory::Job::OnIOComplete, | 359 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), |
336 weak_factory_.GetWeakPtr()), | |
337 net_log_); | 360 net_log_); |
338 } | 361 } |
339 | 362 |
340 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { | 363 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { |
341 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 364 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
342 tracked_objects::ScopedTracker tracking_profile( | 365 tracked_objects::ScopedTracker tracking_profile( |
343 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 366 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
344 "422516 QuicStreamFactory::Job::DoResolveHostComplete")); | 367 "422516 QuicStreamFactory::Job::DoResolveHostComplete")); |
345 | 368 |
346 UMA_HISTOGRAM_TIMES("Net.QuicSession.HostResolutionTime", | 369 UMA_HISTOGRAM_TIMES("Net.QuicSession.HostResolutionTime", |
347 base::TimeTicks::Now() - dns_resolution_start_time_); | 370 base::TimeTicks::Now() - dns_resolution_start_time_); |
348 if (rv != OK) | 371 if (rv != OK) |
349 return rv; | 372 return rv; |
350 | 373 |
351 DCHECK(!factory_->HasActiveSession(server_id_)); | 374 DCHECK(!factory_->HasActiveSession(server_id_)); |
352 | 375 |
353 // Inform the factory of this resolution, which will set up | 376 // Inform the factory of this resolution, which will set up |
354 // a session alias, if possible. | 377 // a session alias, if possible. |
355 if (factory_->OnResolution(server_id_, address_list_)) { | 378 if (factory_->OnResolution(server_id_, address_list_)) { |
356 return OK; | 379 return OK; |
357 } | 380 } |
358 | 381 |
359 io_state_ = STATE_LOAD_SERVER_INFO; | 382 if (server_info_) |
383 io_state_ = STATE_LOAD_SERVER_INFO; | |
384 else | |
385 io_state_ = STATE_CONNECT; | |
360 return OK; | 386 return OK; |
361 } | 387 } |
362 | 388 |
363 int QuicStreamFactory::Job::DoLoadServerInfo() { | 389 int QuicStreamFactory::Job::DoLoadServerInfo() { |
364 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 390 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
365 tracked_objects::ScopedTracker tracking_profile( | 391 tracked_objects::ScopedTracker tracking_profile( |
366 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 392 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
367 "422516 QuicStreamFactory::Job::DoLoadServerInfo")); | 393 "422516 QuicStreamFactory::Job::DoLoadServerInfo")); |
368 | 394 |
369 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE; | 395 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE; |
370 | 396 |
371 if (!server_info_) | 397 DCHECK(server_info_); |
372 return OK; | |
373 | 398 |
374 // To mitigate the effects of disk cache taking too long to load QUIC server | 399 // To mitigate the effects of disk cache taking too long to load QUIC server |
375 // information, set up a timer to cancel WaitForDataReady's callback. | 400 // information, set up a timer to cancel WaitForDataReady's callback. |
376 int64 load_server_info_timeout_ms = factory_->load_server_info_timeout_ms_; | 401 int64 load_server_info_timeout_ms = factory_->load_server_info_timeout_ms_; |
377 if (factory_->load_server_info_timeout_srtt_multiplier_ > 0) { | 402 if (factory_->load_server_info_timeout_srtt_multiplier_ > 0) { |
378 DCHECK_EQ(0, load_server_info_timeout_ms); | 403 DCHECK_EQ(0, load_server_info_timeout_ms); |
379 load_server_info_timeout_ms = | 404 load_server_info_timeout_ms = |
380 (factory_->load_server_info_timeout_srtt_multiplier_ * | 405 (factory_->load_server_info_timeout_srtt_multiplier_ * |
381 factory_->GetServerNetworkStatsSmoothedRttInMicroseconds(server_id_)) / | 406 factory_->GetServerNetworkStatsSmoothedRttInMicroseconds(server_id_)) / |
382 1000; | 407 1000; |
383 } | 408 } |
384 if (load_server_info_timeout_ms > 0) { | 409 if (load_server_info_timeout_ms > 0) { |
385 factory_->task_runner_->PostDelayedTask( | 410 factory_->task_runner_->PostDelayedTask( |
386 FROM_HERE, | 411 FROM_HERE, |
387 base::Bind(&QuicStreamFactory::Job::CancelWaitForDataReadyCallback, | 412 base::Bind(&QuicStreamFactory::Job::CancelWaitForDataReadyCallback, |
388 weak_factory_.GetWeakPtr()), | 413 GetWeakPtr()), |
389 base::TimeDelta::FromMilliseconds(load_server_info_timeout_ms)); | 414 base::TimeDelta::FromMilliseconds(load_server_info_timeout_ms)); |
390 } | 415 } |
391 | 416 |
392 disk_cache_load_start_time_ = base::TimeTicks::Now(); | 417 disk_cache_load_start_time_ = base::TimeTicks::Now(); |
393 return server_info_->WaitForDataReady( | 418 int rv = server_info_->WaitForDataReady( |
394 base::Bind(&QuicStreamFactory::Job::OnIOComplete, | 419 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
395 weak_factory_.GetWeakPtr())); | 420 if (rv == ERR_IO_PENDING && factory_->enable_connection_racing()) { |
421 // If we are waiting to load server config from the disk cache, then start | |
422 // another job. | |
423 started_another_job_ = true; | |
424 factory_->CreateAuxilaryJob(server_id_, is_post_, net_log_); | |
Ryan Hamilton
2015/02/06 18:22:47
Nice! This block of code is clear, and obvious. Lo
ramant (doing other things)
2015/02/06 19:30:31
Thanks much. Both of us are making this code bette
| |
425 } | |
426 return rv; | |
396 } | 427 } |
397 | 428 |
398 int QuicStreamFactory::Job::DoLoadServerInfoComplete(int rv) { | 429 int QuicStreamFactory::Job::DoLoadServerInfoComplete(int rv) { |
399 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 430 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
400 tracked_objects::ScopedTracker tracking_profile( | 431 tracked_objects::ScopedTracker tracking_profile( |
401 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 432 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
402 "422516 QuicStreamFactory::Job::DoLoadServerInfoComplete")); | 433 "422516 QuicStreamFactory::Job::DoLoadServerInfoComplete")); |
403 | 434 |
404 if (server_info_) { | 435 UMA_HISTOGRAM_TIMES("Net.QuicServerInfo.DiskCacheWaitForDataReadyTime", |
405 UMA_HISTOGRAM_TIMES("Net.QuicServerInfo.DiskCacheWaitForDataReadyTime", | 436 base::TimeTicks::Now() - disk_cache_load_start_time_); |
406 base::TimeTicks::Now() - disk_cache_load_start_time_); | |
407 } | |
408 | 437 |
409 if (rv != OK) { | 438 if (rv != OK) |
410 server_info_.reset(); | 439 server_info_.reset(); |
440 | |
441 if (started_another_job_ && | |
442 (!server_info_ || server_info_->state().server_config.empty() || | |
443 !factory_->CryptoConfigCacheIsEmpty(server_id_))) { | |
444 // If we have started another job and if we didn't load the server config | |
445 // from the disk cache or if we have received a new server config from the | |
446 // server, then cancel the current job. | |
447 io_state_ = STATE_NONE; | |
448 return ERR_CONNECTION_CLOSED; | |
411 } | 449 } |
412 | 450 |
413 io_state_ = STATE_CONNECT; | 451 io_state_ = STATE_CONNECT; |
414 return OK; | 452 return OK; |
415 } | 453 } |
416 | 454 |
417 int QuicStreamFactory::Job::DoConnect() { | 455 int QuicStreamFactory::Job::DoConnect() { |
418 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 456 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
419 tracked_objects::ScopedTracker tracking_profile( | 457 tracked_objects::ScopedTracker tracking_profile( |
420 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 458 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
(...skipping 26 matching lines...) Expand all Loading... | |
447 factory_->require_confirmation() || is_post_ || | 485 factory_->require_confirmation() || is_post_ || |
448 was_alternate_protocol_recently_broken_; | 486 was_alternate_protocol_recently_broken_; |
449 | 487 |
450 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 488 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
451 tracked_objects::ScopedTracker tracking_profile2( | 489 tracked_objects::ScopedTracker tracking_profile2( |
452 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 490 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
453 "422516 QuicStreamFactory::Job::DoConnect2")); | 491 "422516 QuicStreamFactory::Job::DoConnect2")); |
454 | 492 |
455 rv = session_->CryptoConnect( | 493 rv = session_->CryptoConnect( |
456 require_confirmation, | 494 require_confirmation, |
457 base::Bind(&QuicStreamFactory::Job::OnIOComplete, | 495 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
458 base::Unretained(this))); | |
459 return rv; | 496 return rv; |
460 } | 497 } |
461 | 498 |
462 int QuicStreamFactory::Job::DoResumeConnect() { | 499 int QuicStreamFactory::Job::DoResumeConnect() { |
463 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 500 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
464 tracked_objects::ScopedTracker tracking_profile( | 501 tracked_objects::ScopedTracker tracking_profile( |
465 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 502 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
466 "422516 QuicStreamFactory::Job::DoResumeConnect")); | 503 "422516 QuicStreamFactory::Job::DoResumeConnect")); |
467 | 504 |
468 io_state_ = STATE_CONNECT_COMPLETE; | 505 io_state_ = STATE_CONNECT_COMPLETE; |
469 | 506 |
470 int rv = session_->ResumeCryptoConnect( | 507 int rv = session_->ResumeCryptoConnect( |
471 base::Bind(&QuicStreamFactory::Job::OnIOComplete, | 508 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
472 base::Unretained(this))); | |
473 | 509 |
474 return rv; | 510 return rv; |
475 } | 511 } |
476 | 512 |
477 int QuicStreamFactory::Job::DoConnectComplete(int rv) { | 513 int QuicStreamFactory::Job::DoConnectComplete(int rv) { |
478 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 514 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
479 tracked_objects::ScopedTracker tracking_profile( | 515 tracked_objects::ScopedTracker tracking_profile( |
480 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 516 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
481 "422516 QuicStreamFactory::Job::DoConnectComplete")); | 517 "422516 QuicStreamFactory::Job::DoConnectComplete")); |
482 | 518 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 config_(InitializeQuicConfig(connection_options)), | 614 config_(InitializeQuicConfig(connection_options)), |
579 supported_versions_(supported_versions), | 615 supported_versions_(supported_versions), |
580 enable_port_selection_(enable_port_selection), | 616 enable_port_selection_(enable_port_selection), |
581 always_require_handshake_confirmation_( | 617 always_require_handshake_confirmation_( |
582 always_require_handshake_confirmation), | 618 always_require_handshake_confirmation), |
583 disable_connection_pooling_(disable_connection_pooling), | 619 disable_connection_pooling_(disable_connection_pooling), |
584 load_server_info_timeout_ms_(load_server_info_timeout), | 620 load_server_info_timeout_ms_(load_server_info_timeout), |
585 load_server_info_timeout_srtt_multiplier_( | 621 load_server_info_timeout_srtt_multiplier_( |
586 load_server_info_timeout_srtt_multiplier), | 622 load_server_info_timeout_srtt_multiplier), |
587 enable_truncated_connection_ids_(enable_truncated_connection_ids), | 623 enable_truncated_connection_ids_(enable_truncated_connection_ids), |
624 enable_connection_racing_(false), | |
588 port_seed_(random_generator_->RandUint64()), | 625 port_seed_(random_generator_->RandUint64()), |
589 check_persisted_supports_quic_(true), | 626 check_persisted_supports_quic_(true), |
590 task_runner_(nullptr), | 627 task_runner_(nullptr), |
591 weak_factory_(this) { | 628 weak_factory_(this) { |
592 DCHECK(transport_security_state_); | 629 DCHECK(transport_security_state_); |
593 crypto_config_.set_user_agent_id(user_agent_id); | 630 crypto_config_.set_user_agent_id(user_agent_id); |
594 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); | 631 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); |
595 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); | 632 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); |
596 crypto_config_.SetProofVerifier( | 633 crypto_config_.SetProofVerifier( |
597 new ProofVerifierChromium(cert_verifier, transport_security_state)); | 634 new ProofVerifierChromium(cert_verifier, transport_security_state)); |
598 crypto_config_.SetChannelIDSource( | 635 crypto_config_.SetChannelIDSource( |
599 new ChannelIDSourceChromium(channel_id_service)); | 636 new ChannelIDSourceChromium(channel_id_service)); |
600 base::CPU cpu; | 637 base::CPU cpu; |
601 if (cpu.has_aesni() && cpu.has_avx()) | 638 if (cpu.has_aesni() && cpu.has_avx()) |
602 crypto_config_.PreferAesGcm(); | 639 crypto_config_.PreferAesGcm(); |
603 if (!IsEcdsaSupported()) | 640 if (!IsEcdsaSupported()) |
604 crypto_config_.DisableEcdsa(); | 641 crypto_config_.DisableEcdsa(); |
605 } | 642 } |
606 | 643 |
607 QuicStreamFactory::~QuicStreamFactory() { | 644 QuicStreamFactory::~QuicStreamFactory() { |
608 CloseAllSessions(ERR_ABORTED); | 645 CloseAllSessions(ERR_ABORTED); |
609 while (!all_sessions_.empty()) { | 646 while (!all_sessions_.empty()) { |
610 delete all_sessions_.begin()->first; | 647 delete all_sessions_.begin()->first; |
611 all_sessions_.erase(all_sessions_.begin()); | 648 all_sessions_.erase(all_sessions_.begin()); |
612 } | 649 } |
613 STLDeleteValues(&active_jobs_); | 650 while (!active_jobs_.empty()) { |
651 const QuicServerId server_id = active_jobs_.begin()->first; | |
652 STLDeleteElements(&(active_jobs_[server_id])); | |
653 active_jobs_.erase(server_id); | |
654 } | |
614 } | 655 } |
615 | 656 |
616 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { | 657 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { |
617 require_confirmation_ = require_confirmation; | 658 require_confirmation_ = require_confirmation; |
618 if (http_server_properties_ && (!(local_address_ == IPEndPoint()))) { | 659 if (http_server_properties_ && (!(local_address_ == IPEndPoint()))) { |
619 http_server_properties_->SetSupportsQuic(!require_confirmation, | 660 http_server_properties_->SetSupportsQuic(!require_confirmation, |
620 local_address_.address()); | 661 local_address_.address()); |
621 } | 662 } |
622 } | 663 } |
623 | 664 |
624 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, | 665 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, |
625 bool is_https, | 666 bool is_https, |
626 PrivacyMode privacy_mode, | 667 PrivacyMode privacy_mode, |
627 base::StringPiece method, | 668 base::StringPiece method, |
628 const BoundNetLog& net_log, | 669 const BoundNetLog& net_log, |
629 QuicStreamRequest* request) { | 670 QuicStreamRequest* request) { |
630 QuicServerId server_id(host_port_pair, is_https, privacy_mode); | 671 QuicServerId server_id(host_port_pair, is_https, privacy_mode); |
631 if (HasActiveSession(server_id)) { | 672 if (HasActiveSession(server_id)) { |
632 request->set_stream(CreateIfSessionExists(server_id, net_log)); | 673 request->set_stream(CreateIfSessionExists(server_id, net_log)); |
633 return OK; | 674 return OK; |
634 } | 675 } |
635 | 676 |
636 if (HasActiveJob(server_id)) { | 677 if (HasActiveJob(server_id)) { |
637 Job* job = active_jobs_[server_id]; | 678 active_requests_[request] = server_id; |
638 active_requests_[request] = job; | 679 job_requests_map_[server_id].insert(request); |
639 job_requests_map_[job].insert(request); | |
640 return ERR_IO_PENDING; | 680 return ERR_IO_PENDING; |
641 } | 681 } |
642 | 682 |
683 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ | |
684 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. | |
685 if (!task_runner_) | |
686 task_runner_ = base::MessageLoop::current()->message_loop_proxy().get(); | |
687 | |
643 QuicServerInfo* quic_server_info = nullptr; | 688 QuicServerInfo* quic_server_info = nullptr; |
644 if (quic_server_info_factory_) { | 689 if (quic_server_info_factory_) { |
645 bool load_from_disk_cache = true; | 690 bool load_from_disk_cache = true; |
646 if (http_server_properties_) { | 691 if (http_server_properties_) { |
647 const AlternateProtocolMap& alternate_protocol_map = | 692 const AlternateProtocolMap& alternate_protocol_map = |
648 http_server_properties_->alternate_protocol_map(); | 693 http_server_properties_->alternate_protocol_map(); |
649 AlternateProtocolMap::const_iterator it = | 694 AlternateProtocolMap::const_iterator it = |
650 alternate_protocol_map.Peek(server_id.host_port_pair()); | 695 alternate_protocol_map.Peek(server_id.host_port_pair()); |
651 if (it == alternate_protocol_map.end() || it->second.protocol != QUIC) { | 696 if (it == alternate_protocol_map.end() || it->second.protocol != QUIC) { |
652 // If there is no entry for QUIC, consider that as a new server and | 697 // If there is no entry for QUIC, consider that as a new server and |
653 // don't wait for Cache thread to load the data for that server. | 698 // don't wait for Cache thread to load the data for that server. |
654 load_from_disk_cache = false; | 699 load_from_disk_cache = false; |
655 } | 700 } |
656 } | 701 } |
657 if (load_from_disk_cache) { | 702 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) { |
658 QuicCryptoClientConfig::CachedState* cached = | 703 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
659 crypto_config_.LookupOrCreate(server_id); | |
660 DCHECK(cached); | |
661 if (cached->IsEmpty()) { | |
662 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | |
663 } | |
664 } | 704 } |
665 } | 705 } |
666 // TODO(rtenneti): Initialize task_runner_ in the constructor after | |
667 // WebRequestActionWithThreadsTest.* tests are fixed. | |
668 if (!task_runner_) | |
669 task_runner_ = base::MessageLoop::current()->message_loop_proxy().get(); | |
670 | 706 |
671 bool was_alternate_protocol_recently_broken = | |
672 http_server_properties_ && | |
673 http_server_properties_->WasAlternateProtocolRecentlyBroken( | |
674 server_id.host_port_pair()); | |
675 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, is_https, | 707 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, is_https, |
676 was_alternate_protocol_recently_broken, | 708 WasAlternateProtocolRecentlyBroken(server_id), |
677 privacy_mode, method, quic_server_info, net_log)); | 709 privacy_mode, method == "POST" /* is_post */, |
710 quic_server_info, net_log)); | |
678 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 711 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
679 base::Unretained(this), job.get())); | 712 base::Unretained(this), job.get())); |
680 | |
681 if (rv == ERR_IO_PENDING) { | 713 if (rv == ERR_IO_PENDING) { |
682 active_requests_[request] = job.get(); | 714 active_requests_[request] = server_id; |
683 job_requests_map_[job.get()].insert(request); | 715 job_requests_map_[server_id].insert(request); |
684 active_jobs_[server_id] = job.release(); | 716 active_jobs_[server_id].insert(job.release()); |
717 return rv; | |
685 } | 718 } |
686 if (rv == OK) { | 719 if (rv == OK) { |
687 DCHECK(HasActiveSession(server_id)); | 720 DCHECK(HasActiveSession(server_id)); |
688 request->set_stream(CreateIfSessionExists(server_id, net_log)); | 721 request->set_stream(CreateIfSessionExists(server_id, net_log)); |
689 } | 722 } |
690 return rv; | 723 return rv; |
691 } | 724 } |
692 | 725 |
726 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, | |
727 bool is_post, | |
728 const BoundNetLog& net_log) { | |
729 Job* aux_job = new Job(this, host_resolver_, server_id.host_port_pair(), | |
730 server_id.is_https(), | |
731 WasAlternateProtocolRecentlyBroken(server_id), | |
732 server_id.privacy_mode(), is_post, nullptr, net_log); | |
733 active_jobs_[server_id].insert(aux_job); | |
734 task_runner_->PostTask(FROM_HERE, | |
735 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, | |
736 aux_job->GetWeakPtr())); | |
737 } | |
738 | |
693 bool QuicStreamFactory::OnResolution( | 739 bool QuicStreamFactory::OnResolution( |
694 const QuicServerId& server_id, | 740 const QuicServerId& server_id, |
695 const AddressList& address_list) { | 741 const AddressList& address_list) { |
696 DCHECK(!HasActiveSession(server_id)); | 742 DCHECK(!HasActiveSession(server_id)); |
697 if (disable_connection_pooling_) { | 743 if (disable_connection_pooling_) { |
698 return false; | 744 return false; |
699 } | 745 } |
700 for (const IPEndPoint& address : address_list) { | 746 for (const IPEndPoint& address : address_list) { |
701 const IpAliasKey ip_alias_key(address, server_id.is_https()); | 747 const IpAliasKey ip_alias_key(address, server_id.is_https()); |
702 if (!ContainsKey(ip_aliases_, ip_alias_key)) | 748 if (!ContainsKey(ip_aliases_, ip_alias_key)) |
703 continue; | 749 continue; |
704 | 750 |
705 const SessionSet& sessions = ip_aliases_[ip_alias_key]; | 751 const SessionSet& sessions = ip_aliases_[ip_alias_key]; |
706 for (QuicClientSession* session : sessions) { | 752 for (QuicClientSession* session : sessions) { |
707 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) | 753 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) |
708 continue; | 754 continue; |
709 active_sessions_[server_id] = session; | 755 active_sessions_[server_id] = session; |
710 session_aliases_[session].insert(server_id); | 756 session_aliases_[session].insert(server_id); |
711 return true; | 757 return true; |
712 } | 758 } |
713 } | 759 } |
714 return false; | 760 return false; |
715 } | 761 } |
716 | 762 |
717 void QuicStreamFactory::OnJobComplete(Job* job, int rv) { | 763 void QuicStreamFactory::OnJobComplete(Job* job, int rv) { |
764 QuicServerId server_id = job->server_id(); | |
718 if (rv == OK) { | 765 if (rv == OK) { |
719 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 766 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
720 tracked_objects::ScopedTracker tracking_profile1( | 767 tracked_objects::ScopedTracker tracking_profile1( |
721 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 768 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
722 "422516 QuicStreamFactory::OnJobComplete1")); | 769 "422516 QuicStreamFactory::OnJobComplete1")); |
723 | 770 |
724 if (!always_require_handshake_confirmation_) | 771 if (!always_require_handshake_confirmation_) |
725 set_require_confirmation(false); | 772 set_require_confirmation(false); |
726 | 773 |
727 // Create all the streams, but do not notify them yet. | 774 // Create all the streams, but do not notify them yet. |
728 for (RequestSet::iterator it = job_requests_map_[job].begin(); | 775 for (RequestSet::iterator it = job_requests_map_[server_id].begin(); |
729 it != job_requests_map_[job].end() ; ++it) { | 776 it != job_requests_map_[server_id].end(); ++it) { |
Ryan Hamilton
2015/02/06 18:22:48
nit: As long as you're here I think you can probab
ramant (doing other things)
2015/02/06 19:30:31
+1 to the above. Thanks much.
Done.
| |
730 DCHECK(HasActiveSession(job->server_id())); | 777 DCHECK(HasActiveSession(server_id)); |
731 (*it)->set_stream(CreateIfSessionExists(job->server_id(), | 778 (*it)->set_stream(CreateIfSessionExists(server_id, (*it)->net_log())); |
732 (*it)->net_log())); | 779 } |
780 } else { | |
781 JobSet* jobs = &(active_jobs_[server_id]); | |
Ryan Hamilton
2015/02/06 18:22:47
Can you add a comment here explaining what this co
ramant (doing other things)
2015/02/06 19:30:31
Done.
| |
782 if (jobs->size() > 1) { | |
783 job->Cancel(); | |
784 jobs->erase(job); | |
785 delete job; | |
786 return; | |
733 } | 787 } |
734 } | 788 } |
735 | 789 |
736 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 790 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
737 tracked_objects::ScopedTracker tracking_profile2( | 791 tracked_objects::ScopedTracker tracking_profile2( |
738 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 792 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
739 "422516 QuicStreamFactory::OnJobComplete2")); | 793 "422516 QuicStreamFactory::OnJobComplete2")); |
740 | 794 |
741 while (!job_requests_map_[job].empty()) { | 795 while (!job_requests_map_[server_id].empty()) { |
742 RequestSet::iterator it = job_requests_map_[job].begin(); | 796 RequestSet::iterator it = job_requests_map_[server_id].begin(); |
743 QuicStreamRequest* request = *it; | 797 QuicStreamRequest* request = *it; |
744 job_requests_map_[job].erase(it); | 798 job_requests_map_[server_id].erase(it); |
745 active_requests_.erase(request); | 799 active_requests_.erase(request); |
746 // Even though we're invoking callbacks here, we don't need to worry | 800 // Even though we're invoking callbacks here, we don't need to worry |
747 // about |this| being deleted, because the factory is owned by the | 801 // about |this| being deleted, because the factory is owned by the |
748 // profile which can not be deleted via callbacks. | 802 // profile which can not be deleted via callbacks. |
749 request->OnRequestComplete(rv); | 803 request->OnRequestComplete(rv); |
750 } | 804 } |
751 | 805 |
752 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 806 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
753 tracked_objects::ScopedTracker tracking_profile3( | 807 tracked_objects::ScopedTracker tracking_profile3( |
754 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 808 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
755 "422516 QuicStreamFactory::OnJobComplete3")); | 809 "422516 QuicStreamFactory::OnJobComplete3")); |
756 | 810 |
757 active_jobs_.erase(job->server_id()); | 811 for (Job* other_job : active_jobs_[server_id]) { |
758 job_requests_map_.erase(job); | 812 if (other_job != job) |
759 delete job; | 813 other_job->Cancel(); |
760 return; | 814 } |
815 | |
816 STLDeleteElements(&(active_jobs_[server_id])); | |
817 active_jobs_.erase(server_id); | |
818 job_requests_map_.erase(server_id); | |
761 } | 819 } |
762 | 820 |
763 // Returns a newly created QuicHttpStream owned by the caller, if a | 821 // Returns a newly created QuicHttpStream owned by the caller, if a |
764 // matching session already exists. Returns nullptr otherwise. | 822 // matching session already exists. Returns nullptr otherwise. |
765 scoped_ptr<QuicHttpStream> QuicStreamFactory::CreateIfSessionExists( | 823 scoped_ptr<QuicHttpStream> QuicStreamFactory::CreateIfSessionExists( |
766 const QuicServerId& server_id, | 824 const QuicServerId& server_id, |
767 const BoundNetLog& net_log) { | 825 const BoundNetLog& net_log) { |
768 if (!HasActiveSession(server_id)) { | 826 if (!HasActiveSession(server_id)) { |
769 DVLOG(1) << "No active session"; | 827 DVLOG(1) << "No active session"; |
770 return scoped_ptr<QuicHttpStream>(); | 828 return scoped_ptr<QuicHttpStream>(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
829 | 887 |
830 const IpAliasKey ip_alias_key(session->connection()->peer_address(), | 888 const IpAliasKey ip_alias_key(session->connection()->peer_address(), |
831 aliases.begin()->is_https()); | 889 aliases.begin()->is_https()); |
832 ip_aliases_[ip_alias_key].erase(session); | 890 ip_aliases_[ip_alias_key].erase(session); |
833 if (ip_aliases_[ip_alias_key].empty()) { | 891 if (ip_aliases_[ip_alias_key].empty()) { |
834 ip_aliases_.erase(ip_alias_key); | 892 ip_aliases_.erase(ip_alias_key); |
835 } | 893 } |
836 QuicServerId server_id = *aliases.begin(); | 894 QuicServerId server_id = *aliases.begin(); |
837 session_aliases_.erase(session); | 895 session_aliases_.erase(session); |
838 Job* job = new Job(this, host_resolver_, session, server_id); | 896 Job* job = new Job(this, host_resolver_, session, server_id); |
839 active_jobs_[server_id] = job; | 897 active_jobs_[server_id].insert(job); |
840 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 898 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
841 base::Unretained(this), job)); | 899 base::Unretained(this), job)); |
842 DCHECK_EQ(ERR_IO_PENDING, rv); | 900 DCHECK_EQ(ERR_IO_PENDING, rv); |
843 } | 901 } |
844 | 902 |
845 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { | 903 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { |
846 DCHECK(ContainsKey(active_requests_, request)); | 904 DCHECK(ContainsKey(active_requests_, request)); |
847 Job* job = active_requests_[request]; | 905 QuicServerId server_id = active_requests_[request]; |
848 job_requests_map_[job].erase(request); | 906 job_requests_map_[server_id].erase(request); |
849 active_requests_.erase(request); | 907 active_requests_.erase(request); |
850 } | 908 } |
851 | 909 |
852 void QuicStreamFactory::CloseAllSessions(int error) { | 910 void QuicStreamFactory::CloseAllSessions(int error) { |
853 while (!active_sessions_.empty()) { | 911 while (!active_sessions_.empty()) { |
854 size_t initial_size = active_sessions_.size(); | 912 size_t initial_size = active_sessions_.size(); |
855 active_sessions_.begin()->second->CloseSessionOnError(error); | 913 active_sessions_.begin()->second->CloseSessionOnError(error); |
856 DCHECK_NE(initial_size, active_sessions_.size()); | 914 DCHECK_NE(initial_size, active_sessions_.size()); |
857 } | 915 } |
858 while (!all_sessions_.empty()) { | 916 while (!all_sessions_.empty()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 // kind of change it is, we have to flush the socket | 966 // kind of change it is, we have to flush the socket |
909 // pools to be safe. | 967 // pools to be safe. |
910 CloseAllSessions(ERR_CERT_DATABASE_CHANGED); | 968 CloseAllSessions(ERR_CERT_DATABASE_CHANGED); |
911 } | 969 } |
912 | 970 |
913 bool QuicStreamFactory::HasActiveSession( | 971 bool QuicStreamFactory::HasActiveSession( |
914 const QuicServerId& server_id) const { | 972 const QuicServerId& server_id) const { |
915 return ContainsKey(active_sessions_, server_id); | 973 return ContainsKey(active_sessions_, server_id); |
916 } | 974 } |
917 | 975 |
976 bool QuicStreamFactory::HasActiveJob(const QuicServerId& key) const { | |
977 return ContainsKey(active_jobs_, key); | |
978 } | |
979 | |
Ryan Hamilton
2015/02/06 18:22:47
Did this move to match the order in the .h file?
ramant (doing other things)
2015/02/06 19:30:31
Acknowledged.
| |
918 int QuicStreamFactory::CreateSession( | 980 int QuicStreamFactory::CreateSession( |
919 const QuicServerId& server_id, | 981 const QuicServerId& server_id, |
920 scoped_ptr<QuicServerInfo> server_info, | 982 scoped_ptr<QuicServerInfo> server_info, |
921 const AddressList& address_list, | 983 const AddressList& address_list, |
922 const BoundNetLog& net_log, | 984 const BoundNetLog& net_log, |
923 QuicClientSession** session) { | 985 QuicClientSession** session) { |
924 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 986 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
925 tracked_objects::ScopedTracker tracking_profile1( | 987 tracked_objects::ScopedTracker tracking_profile1( |
926 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 988 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
927 "422516 QuicStreamFactory::CreateSession1")); | 989 "422516 QuicStreamFactory::CreateSession1")); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1122 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", | 1184 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", |
1123 closed_during_initialize); | 1185 closed_during_initialize); |
1124 if (closed_during_initialize) { | 1186 if (closed_during_initialize) { |
1125 DLOG(DFATAL) << "Session closed during initialize"; | 1187 DLOG(DFATAL) << "Session closed during initialize"; |
1126 *session = nullptr; | 1188 *session = nullptr; |
1127 return ERR_CONNECTION_CLOSED; | 1189 return ERR_CONNECTION_CLOSED; |
1128 } | 1190 } |
1129 return OK; | 1191 return OK; |
1130 } | 1192 } |
1131 | 1193 |
1132 bool QuicStreamFactory::HasActiveJob(const QuicServerId& key) const { | |
1133 return ContainsKey(active_jobs_, key); | |
1134 } | |
1135 | |
1136 void QuicStreamFactory::ActivateSession( | 1194 void QuicStreamFactory::ActivateSession( |
1137 const QuicServerId& server_id, | 1195 const QuicServerId& server_id, |
1138 QuicClientSession* session) { | 1196 QuicClientSession* session) { |
1139 DCHECK(!HasActiveSession(server_id)); | 1197 DCHECK(!HasActiveSession(server_id)); |
1140 UMA_HISTOGRAM_COUNTS("Net.QuicActiveSessions", active_sessions_.size()); | 1198 UMA_HISTOGRAM_COUNTS("Net.QuicActiveSessions", active_sessions_.size()); |
1141 active_sessions_[server_id] = session; | 1199 active_sessions_[server_id] = session; |
1142 session_aliases_[session].insert(server_id); | 1200 session_aliases_[session].insert(server_id); |
1143 const IpAliasKey ip_alias_key(session->connection()->peer_address(), | 1201 const IpAliasKey ip_alias_key(session->connection()->peer_address(), |
1144 server_id.is_https()); | 1202 server_id.is_https()); |
1145 DCHECK(!ContainsKey(ip_aliases_[ip_alias_key], session)); | 1203 DCHECK(!ContainsKey(ip_aliases_[ip_alias_key], session)); |
1146 ip_aliases_[ip_alias_key].insert(session); | 1204 ip_aliases_[ip_alias_key].insert(session); |
1147 } | 1205 } |
1148 | 1206 |
1149 int64 QuicStreamFactory::GetServerNetworkStatsSmoothedRttInMicroseconds( | 1207 int64 QuicStreamFactory::GetServerNetworkStatsSmoothedRttInMicroseconds( |
1150 const QuicServerId& server_id) const { | 1208 const QuicServerId& server_id) const { |
1151 if (!http_server_properties_) | 1209 if (!http_server_properties_) |
1152 return 0; | 1210 return 0; |
1153 const ServerNetworkStats* stats = | 1211 const ServerNetworkStats* stats = |
1154 http_server_properties_->GetServerNetworkStats( | 1212 http_server_properties_->GetServerNetworkStats( |
1155 server_id.host_port_pair()); | 1213 server_id.host_port_pair()); |
1156 if (stats == nullptr) | 1214 if (stats == nullptr) |
1157 return 0; | 1215 return 0; |
1158 return stats->srtt.InMicroseconds(); | 1216 return stats->srtt.InMicroseconds(); |
1159 } | 1217 } |
1160 | 1218 |
1219 bool QuicStreamFactory::WasAlternateProtocolRecentlyBroken( | |
1220 const QuicServerId& server_id) const { | |
1221 return http_server_properties_ && | |
1222 http_server_properties_->WasAlternateProtocolRecentlyBroken( | |
1223 server_id.host_port_pair()); | |
1224 } | |
1225 | |
1226 bool QuicStreamFactory::CryptoConfigCacheIsEmpty( | |
1227 const QuicServerId& server_id) { | |
1228 QuicCryptoClientConfig::CachedState* cached = | |
1229 crypto_config_.LookupOrCreate(server_id); | |
1230 return cached->IsEmpty(); | |
1231 } | |
1232 | |
1161 void QuicStreamFactory::InitializeCachedStateInCryptoConfig( | 1233 void QuicStreamFactory::InitializeCachedStateInCryptoConfig( |
1162 const QuicServerId& server_id, | 1234 const QuicServerId& server_id, |
1163 const scoped_ptr<QuicServerInfo>& server_info) { | 1235 const scoped_ptr<QuicServerInfo>& server_info) { |
1164 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. | 1236 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
1165 tracked_objects::ScopedTracker tracking_profile1( | 1237 tracked_objects::ScopedTracker tracking_profile1( |
1166 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1238 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1167 "422516 QuicStreamFactory::InitializeCachedStateInCryptoConfig1")); | 1239 "422516 QuicStreamFactory::InitializeCachedStateInCryptoConfig1")); |
1168 | 1240 |
1169 // |server_info| will be NULL, if a non-empty server config already exists in | 1241 // |server_info| will be NULL, if a non-empty server config already exists in |
1170 // the memory cache. This is a minor optimization to avoid LookupOrCreate. | 1242 // the memory cache. This is a minor optimization to avoid LookupOrCreate. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1264 http_server_properties_->ClearAlternateProtocol(server); | 1336 http_server_properties_->ClearAlternateProtocol(server); |
1265 http_server_properties_->SetAlternateProtocol( | 1337 http_server_properties_->SetAlternateProtocol( |
1266 server, alternate.port, alternate.protocol, 1); | 1338 server, alternate.port, alternate.protocol, 1); |
1267 DCHECK_EQ(QUIC, | 1339 DCHECK_EQ(QUIC, |
1268 http_server_properties_->GetAlternateProtocol(server).protocol); | 1340 http_server_properties_->GetAlternateProtocol(server).protocol); |
1269 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( | 1341 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( |
1270 server)); | 1342 server)); |
1271 } | 1343 } |
1272 | 1344 |
1273 } // namespace net | 1345 } // namespace net |
OLD | NEW |