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

Side by Side Diff: net/quic/quic_stream_factory.cc

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

Powered by Google App Engine
This is Rietveld 408576698