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

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

Issue 2077683002: Move the logic for delaying 0-RTT QUIC POST from the QuicStreamFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@QuicHttpStream
Patch Set: tweak Created 4 years, 6 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 <openssl/aead.h> 7 #include <openssl/aead.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <tuple> 10 #include <tuple>
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 // Responsible for creating a new QUIC session to the specified server, and 170 // Responsible for creating a new QUIC session to the specified server, and
171 // for notifying any associated requests when complete. 171 // for notifying any associated requests when complete.
172 class QuicStreamFactory::Job { 172 class QuicStreamFactory::Job {
173 public: 173 public:
174 Job(QuicStreamFactory* factory, 174 Job(QuicStreamFactory* factory,
175 HostResolver* host_resolver, 175 HostResolver* host_resolver,
176 const QuicSessionKey& key, 176 const QuicSessionKey& key,
177 bool was_alternative_service_recently_broken, 177 bool was_alternative_service_recently_broken,
178 int cert_verify_flags, 178 int cert_verify_flags,
179 bool is_post,
180 QuicServerInfo* server_info, 179 QuicServerInfo* server_info,
181 const BoundNetLog& net_log); 180 const BoundNetLog& net_log);
182 181
183 // Creates a new job to handle the resumption of for connecting an 182 // Creates a new job to handle the resumption of for connecting an
184 // existing session. 183 // existing session.
185 Job(QuicStreamFactory* factory, 184 Job(QuicStreamFactory* factory,
186 HostResolver* host_resolver, 185 HostResolver* host_resolver,
187 QuicChromiumClientSession* session, 186 QuicChromiumClientSession* session,
188 const QuicSessionKey& key); 187 const QuicSessionKey& key);
189 188
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 STATE_CONNECT, 221 STATE_CONNECT,
223 STATE_RESUME_CONNECT, 222 STATE_RESUME_CONNECT,
224 STATE_CONNECT_COMPLETE, 223 STATE_CONNECT_COMPLETE,
225 }; 224 };
226 IoState io_state_; 225 IoState io_state_;
227 226
228 QuicStreamFactory* factory_; 227 QuicStreamFactory* factory_;
229 SingleRequestHostResolver host_resolver_; 228 SingleRequestHostResolver host_resolver_;
230 QuicSessionKey key_; 229 QuicSessionKey key_;
231 int cert_verify_flags_; 230 int cert_verify_flags_;
232 bool is_post_;
233 bool was_alternative_service_recently_broken_; 231 bool was_alternative_service_recently_broken_;
234 std::unique_ptr<QuicServerInfo> server_info_; 232 std::unique_ptr<QuicServerInfo> server_info_;
235 bool started_another_job_; 233 bool started_another_job_;
236 const BoundNetLog net_log_; 234 const BoundNetLog net_log_;
237 int num_sent_client_hellos_; 235 int num_sent_client_hellos_;
238 QuicChromiumClientSession* session_; 236 QuicChromiumClientSession* session_;
239 CompletionCallback callback_; 237 CompletionCallback callback_;
240 AddressList address_list_; 238 AddressList address_list_;
241 base::TimeTicks dns_resolution_start_time_; 239 base::TimeTicks dns_resolution_start_time_;
242 base::TimeTicks dns_resolution_end_time_; 240 base::TimeTicks dns_resolution_end_time_;
243 base::WeakPtrFactory<Job> weak_factory_; 241 base::WeakPtrFactory<Job> weak_factory_;
244 DISALLOW_COPY_AND_ASSIGN(Job); 242 DISALLOW_COPY_AND_ASSIGN(Job);
245 }; 243 };
246 244
247 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, 245 QuicStreamFactory::Job::Job(QuicStreamFactory* factory,
248 HostResolver* host_resolver, 246 HostResolver* host_resolver,
249 const QuicSessionKey& key, 247 const QuicSessionKey& key,
250 bool was_alternative_service_recently_broken, 248 bool was_alternative_service_recently_broken,
251 int cert_verify_flags, 249 int cert_verify_flags,
252 bool is_post,
253 QuicServerInfo* server_info, 250 QuicServerInfo* server_info,
254 const BoundNetLog& net_log) 251 const BoundNetLog& net_log)
255 : io_state_(STATE_RESOLVE_HOST), 252 : io_state_(STATE_RESOLVE_HOST),
256 factory_(factory), 253 factory_(factory),
257 host_resolver_(host_resolver), 254 host_resolver_(host_resolver),
258 key_(key), 255 key_(key),
259 cert_verify_flags_(cert_verify_flags), 256 cert_verify_flags_(cert_verify_flags),
260 is_post_(is_post),
261 was_alternative_service_recently_broken_( 257 was_alternative_service_recently_broken_(
262 was_alternative_service_recently_broken), 258 was_alternative_service_recently_broken),
263 server_info_(server_info), 259 server_info_(server_info),
264 started_another_job_(false), 260 started_another_job_(false),
265 net_log_(net_log), 261 net_log_(net_log),
266 num_sent_client_hellos_(0), 262 num_sent_client_hellos_(0),
267 session_(nullptr), 263 session_(nullptr),
268 weak_factory_(this) {} 264 weak_factory_(this) {}
269 265
270 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, 266 QuicStreamFactory::Job::Job(QuicStreamFactory* factory,
271 HostResolver* host_resolver, 267 HostResolver* host_resolver,
272 QuicChromiumClientSession* session, 268 QuicChromiumClientSession* session,
273 const QuicSessionKey& key) 269 const QuicSessionKey& key)
274 : io_state_(STATE_RESUME_CONNECT), 270 : io_state_(STATE_RESUME_CONNECT),
275 factory_(factory), 271 factory_(factory),
276 host_resolver_(host_resolver), // unused 272 host_resolver_(host_resolver), // unused
277 key_(key), 273 key_(key),
278 cert_verify_flags_(0), // unused 274 cert_verify_flags_(0), // unused
279 is_post_(false), // unused
280 was_alternative_service_recently_broken_(false), // unused 275 was_alternative_service_recently_broken_(false), // unused
281 started_another_job_(false), // unused 276 started_another_job_(false), // unused
282 net_log_(session->net_log()), // unused 277 net_log_(session->net_log()), // unused
283 num_sent_client_hellos_(0), 278 num_sent_client_hellos_(0),
284 session_(session), 279 session_(session),
285 weak_factory_(this) {} 280 weak_factory_(this) {}
286 281
287 QuicStreamFactory::Job::~Job() { 282 QuicStreamFactory::Job::~Job() {
288 // If disk cache has a pending WaitForDataReadyCallback, cancel that callback. 283 // If disk cache has a pending WaitForDataReadyCallback, cancel that callback.
289 if (server_info_) 284 if (server_info_)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 base::TimeDelta::FromMilliseconds(load_server_info_timeout_ms)); 424 base::TimeDelta::FromMilliseconds(load_server_info_timeout_ms));
430 } 425 }
431 } 426 }
432 427
433 int rv = server_info_->WaitForDataReady( 428 int rv = server_info_->WaitForDataReady(
434 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); 429 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()));
435 if (rv == ERR_IO_PENDING && factory_->enable_connection_racing()) { 430 if (rv == ERR_IO_PENDING && factory_->enable_connection_racing()) {
436 // If we are waiting to load server config from the disk cache, then start 431 // If we are waiting to load server config from the disk cache, then start
437 // another job. 432 // another job.
438 started_another_job_ = true; 433 started_another_job_ = true;
439 factory_->CreateAuxilaryJob(key_, cert_verify_flags_, is_post_, net_log_); 434 factory_->CreateAuxilaryJob(key_, cert_verify_flags_, net_log_);
440 } 435 }
441 return rv; 436 return rv;
442 } 437 }
443 438
444 int QuicStreamFactory::Job::DoLoadServerInfoComplete(int rv) { 439 int QuicStreamFactory::Job::DoLoadServerInfoComplete(int rv) {
445 UMA_HISTOGRAM_TIMES("Net.QuicServerInfo.DiskCacheWaitForDataReadyTime", 440 UMA_HISTOGRAM_TIMES("Net.QuicServerInfo.DiskCacheWaitForDataReadyTime",
446 base::TimeTicks::Now() - dns_resolution_end_time_); 441 base::TimeTicks::Now() - dns_resolution_end_time_);
447 442
448 if (rv != OK) 443 if (rv != OK)
449 server_info_.reset(); 444 server_info_.reset();
(...skipping 25 matching lines...) Expand all
475 } 470 }
476 471
477 if (!session_->connection()->connected()) { 472 if (!session_->connection()->connected()) {
478 return ERR_CONNECTION_CLOSED; 473 return ERR_CONNECTION_CLOSED;
479 } 474 }
480 475
481 session_->StartReading(); 476 session_->StartReading();
482 if (!session_->connection()->connected()) { 477 if (!session_->connection()->connected()) {
483 return ERR_QUIC_PROTOCOL_ERROR; 478 return ERR_QUIC_PROTOCOL_ERROR;
484 } 479 }
485 bool require_confirmation = factory_->require_confirmation() || is_post_ || 480 bool require_confirmation = factory_->require_confirmation() ||
486 was_alternative_service_recently_broken_; 481 was_alternative_service_recently_broken_;
487 482
488 rv = session_->CryptoConnect( 483 rv = session_->CryptoConnect(
489 require_confirmation, 484 require_confirmation,
490 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); 485 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()));
491 486
492 if (!session_->connection()->connected() && 487 if (!session_->connection()->connected() &&
493 session_->error() == QUIC_PROOF_INVALID) 488 session_->error() == QUIC_PROOF_INVALID)
494 return ERR_QUIC_HANDSHAKE_FAILED; 489 return ERR_QUIC_HANDSHAKE_FAILED;
495 490
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 load_from_disk_cache = false; 878 load_from_disk_cache = false;
884 } 879 }
885 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) { 880 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) {
886 quic_server_info = quic_server_info_factory_->GetForServer(server_id); 881 quic_server_info = quic_server_info_factory_->GetForServer(server_id);
887 } 882 }
888 } 883 }
889 884
890 QuicSessionKey key(destination, server_id); 885 QuicSessionKey key(destination, server_id);
891 std::unique_ptr<Job> job( 886 std::unique_ptr<Job> job(
892 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id), 887 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id),
893 cert_verify_flags, method == "POST" /* is_post */, 888 cert_verify_flags, quic_server_info, net_log));
894 quic_server_info, net_log));
895 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 889 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
896 base::Unretained(this), job.get())); 890 base::Unretained(this), job.get()));
897 if (rv == ERR_IO_PENDING) { 891 if (rv == ERR_IO_PENDING) {
898 active_requests_[request] = server_id; 892 active_requests_[request] = server_id;
899 job_requests_map_[server_id].insert(request); 893 job_requests_map_[server_id].insert(request);
900 active_jobs_[server_id].insert(job.release()); 894 active_jobs_[server_id].insert(job.release());
901 return rv; 895 return rv;
902 } 896 }
903 if (rv == OK) { 897 if (rv == OK) {
904 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() 898 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty()
(...skipping 22 matching lines...) Expand all
927 } 921 }
928 922
929 bool QuicStreamFactory::QuicSessionKey::operator==( 923 bool QuicStreamFactory::QuicSessionKey::operator==(
930 const QuicSessionKey& other) const { 924 const QuicSessionKey& other) const {
931 return destination_.Equals(other.destination_) && 925 return destination_.Equals(other.destination_) &&
932 server_id_ == other.server_id_; 926 server_id_ == other.server_id_;
933 } 927 }
934 928
935 void QuicStreamFactory::CreateAuxilaryJob(const QuicSessionKey& key, 929 void QuicStreamFactory::CreateAuxilaryJob(const QuicSessionKey& key,
936 int cert_verify_flags, 930 int cert_verify_flags,
937 bool is_post,
938 const BoundNetLog& net_log) { 931 const BoundNetLog& net_log) {
939 Job* aux_job = 932 Job* aux_job =
940 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(key.server_id()), 933 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(key.server_id()),
941 cert_verify_flags, is_post, nullptr, net_log); 934 cert_verify_flags, nullptr, net_log);
942 active_jobs_[key.server_id()].insert(aux_job); 935 active_jobs_[key.server_id()].insert(aux_job);
943 task_runner_->PostTask(FROM_HERE, 936 task_runner_->PostTask(FROM_HERE,
944 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, 937 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob,
945 aux_job->GetWeakPtr())); 938 aux_job->GetWeakPtr()));
946 } 939 }
947 940
948 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, 941 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key,
949 const AddressList& address_list) { 942 const AddressList& address_list) {
950 const QuicServerId& server_id(key.server_id()); 943 const QuicServerId& server_id(key.server_id());
951 DCHECK(!HasActiveSession(server_id)); 944 DCHECK(!HasActiveSession(server_id));
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 // Since the session was active, there's no longer an 1870 // Since the session was active, there's no longer an
1878 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1871 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP
1879 // job also fails. So to avoid not using QUIC when we otherwise could, we mark 1872 // job also fails. So to avoid not using QUIC when we otherwise could, we mark
1880 // it as recently broken, which means that 0-RTT will be disabled but we'll 1873 // it as recently broken, which means that 0-RTT will be disabled but we'll
1881 // still race. 1874 // still race.
1882 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1875 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
1883 alternative_service); 1876 alternative_service);
1884 } 1877 }
1885 1878
1886 } // namespace net 1879 } // 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