| 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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 return OK; | 639 return OK; |
| 640 } | 640 } |
| 641 | 641 |
| 642 if (HasActiveJob(server_id)) { | 642 if (HasActiveJob(server_id)) { |
| 643 Job* job = active_jobs_[server_id]; | 643 Job* job = active_jobs_[server_id]; |
| 644 active_requests_[request] = job; | 644 active_requests_[request] = job; |
| 645 job_requests_map_[job].insert(request); | 645 job_requests_map_[job].insert(request); |
| 646 return ERR_IO_PENDING; | 646 return ERR_IO_PENDING; |
| 647 } | 647 } |
| 648 | 648 |
| 649 bool was_alternate_protocol_recently_broken = false; |
| 650 AlternateProtocolInfo alternate_protocol; |
| 651 if (http_server_properties_) { |
| 652 alternate_protocol = |
| 653 http_server_properties_->GetAlternateProtocol(host_port_pair); |
| 654 if (alternate_protocol.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 655 was_alternate_protocol_recently_broken = |
| 656 http_server_properties_->WasAlternateProtocolRecentlyBroken( |
| 657 host_port_pair, alternate_protocol); |
| 658 } |
| 659 } |
| 660 |
| 649 QuicServerInfo* quic_server_info = nullptr; | 661 QuicServerInfo* quic_server_info = nullptr; |
| 650 if (quic_server_info_factory_) { | 662 if (quic_server_info_factory_) { |
| 651 bool load_from_disk_cache = true; | 663 // If there is no entry for QUIC, consider that as a new server and |
| 652 if (http_server_properties_) { | 664 // don't wait for Cache thread to load the data for that server. |
| 653 const AlternateProtocolMap& alternate_protocol_map = | 665 const bool load_from_disk_cache = |
| 654 http_server_properties_->alternate_protocol_map(); | 666 !http_server_properties_ || alternate_protocol.protocol == QUIC; |
| 655 AlternateProtocolMap::const_iterator it = | |
| 656 alternate_protocol_map.Peek(server_id.host_port_pair()); | |
| 657 if (it == alternate_protocol_map.end() || it->second.protocol != QUIC) { | |
| 658 // If there is no entry for QUIC, consider that as a new server and | |
| 659 // don't wait for Cache thread to load the data for that server. | |
| 660 load_from_disk_cache = false; | |
| 661 } | |
| 662 } | |
| 663 if (load_from_disk_cache) { | 667 if (load_from_disk_cache) { |
| 664 QuicCryptoClientConfig::CachedState* cached = | 668 QuicCryptoClientConfig::CachedState* cached = |
| 665 crypto_config_.LookupOrCreate(server_id); | 669 crypto_config_.LookupOrCreate(server_id); |
| 666 DCHECK(cached); | 670 DCHECK(cached); |
| 667 if (cached->IsEmpty()) { | 671 if (cached->IsEmpty()) { |
| 668 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | 672 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
| 669 } | 673 } |
| 670 } | 674 } |
| 671 } | 675 } |
| 672 // TODO(rtenneti): Initialize task_runner_ in the constructor after | 676 // TODO(rtenneti): Initialize task_runner_ in the constructor after |
| 673 // WebRequestActionWithThreadsTest.* tests are fixed. | 677 // WebRequestActionWithThreadsTest.* tests are fixed. |
| 674 if (!task_runner_) | 678 if (!task_runner_) |
| 675 task_runner_ = base::MessageLoop::current()->message_loop_proxy().get(); | 679 task_runner_ = base::MessageLoop::current()->message_loop_proxy().get(); |
| 676 | 680 |
| 677 bool was_alternate_protocol_recently_broken = | |
| 678 http_server_properties_ && | |
| 679 http_server_properties_->WasAlternateProtocolRecentlyBroken( | |
| 680 server_id.host_port_pair()); | |
| 681 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, is_https, | 681 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, is_https, |
| 682 was_alternate_protocol_recently_broken, | 682 was_alternate_protocol_recently_broken, |
| 683 privacy_mode, method, quic_server_info, net_log)); | 683 privacy_mode, method, quic_server_info, net_log)); |
| 684 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 684 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
| 685 base::Unretained(this), job.get())); | 685 base::Unretained(this), job.get())); |
| 686 | 686 |
| 687 if (rv == ERR_IO_PENDING) { | 687 if (rv == ERR_IO_PENDING) { |
| 688 active_requests_[request] = job.get(); | 688 active_requests_[request] = job.get(); |
| 689 job_requests_map_[job.get()].insert(request); | 689 job_requests_map_[job.get()].insert(request); |
| 690 active_jobs_[server_id] = job.release(); | 690 active_jobs_[server_id] = job.release(); |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 if (!server_info) | 1179 if (!server_info) |
| 1180 return; | 1180 return; |
| 1181 | 1181 |
| 1182 QuicCryptoClientConfig::CachedState* cached = | 1182 QuicCryptoClientConfig::CachedState* cached = |
| 1183 crypto_config_.LookupOrCreate(server_id); | 1183 crypto_config_.LookupOrCreate(server_id); |
| 1184 if (!cached->IsEmpty()) | 1184 if (!cached->IsEmpty()) |
| 1185 return; | 1185 return; |
| 1186 | 1186 |
| 1187 if (http_server_properties_) { | 1187 if (http_server_properties_) { |
| 1188 if (quic_supported_servers_at_startup_.empty()) { | 1188 if (quic_supported_servers_at_startup_.empty()) { |
| 1189 for (const std::pair<const net::HostPortPair, net::AlternateProtocolInfo>& | 1189 for (const std::pair<const HostPortPair, AlternateProtocols>& key_value : |
| 1190 key_value : http_server_properties_->alternate_protocol_map()) { | 1190 http_server_properties_->alternate_protocol_map()) { |
| 1191 if (key_value.second.protocol == QUIC) { | 1191 for (const AlternateProtocolInfo& alternate_protocol : |
| 1192 quic_supported_servers_at_startup_.insert(key_value.first); | 1192 key_value.second) { |
| 1193 if (alternate_protocol.protocol == QUIC) { |
| 1194 quic_supported_servers_at_startup_.insert(key_value.first); |
| 1195 } |
| 1193 } | 1196 } |
| 1194 } | 1197 } |
| 1195 } | 1198 } |
| 1196 | 1199 |
| 1197 // TODO(rtenneti): Delete the following histogram after collecting stats. | 1200 // TODO(rtenneti): Delete the following histogram after collecting stats. |
| 1198 // If the AlternateProtocolMap contained an entry for this host, check if | 1201 // If the AlternateProtocolMap contained an entry for this host, check if |
| 1199 // the disk cache contained an entry for it. | 1202 // the disk cache contained an entry for it. |
| 1200 if (ContainsKey(quic_supported_servers_at_startup_, | 1203 if (ContainsKey(quic_supported_servers_at_startup_, |
| 1201 server_id.host_port_pair())) { | 1204 server_id.host_port_pair())) { |
| 1202 UMA_HISTOGRAM_BOOLEAN( | 1205 UMA_HISTOGRAM_BOOLEAN( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 | 1245 |
| 1243 UMA_HISTOGRAM_COUNTS("Net.QuicHandshakeNotConfirmedNumPacketsReceived", | 1246 UMA_HISTOGRAM_COUNTS("Net.QuicHandshakeNotConfirmedNumPacketsReceived", |
| 1244 stats.packets_received); | 1247 stats.packets_received); |
| 1245 | 1248 |
| 1246 if (!session_was_active) | 1249 if (!session_was_active) |
| 1247 return; | 1250 return; |
| 1248 | 1251 |
| 1249 const HostPortPair& server = server_id.host_port_pair(); | 1252 const HostPortPair& server = server_id.host_port_pair(); |
| 1250 // Don't try to change the alternate-protocol state, if the | 1253 // Don't try to change the alternate-protocol state, if the |
| 1251 // alternate-protocol state is unknown. | 1254 // alternate-protocol state is unknown. |
| 1252 if (!http_server_properties_->HasAlternateProtocol(server)) | 1255 const AlternateProtocolInfo alternate = |
| 1256 http_server_properties_->GetAlternateProtocol(server); |
| 1257 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 1253 return; | 1258 return; |
| 1254 | 1259 |
| 1255 // TODO(rch): In the special case where the session has received no | 1260 // TODO(rch): In the special case where the session has received no |
| 1256 // packets from the peer, we should consider blacklisting this | 1261 // packets from the peer, we should consider blacklisting this |
| 1257 // differently so that we still race TCP but we don't consider the | 1262 // differently so that we still race TCP but we don't consider the |
| 1258 // session connected until the handshake has been confirmed. | 1263 // session connected until the handshake has been confirmed. |
| 1259 HistogramBrokenAlternateProtocolLocation( | 1264 HistogramBrokenAlternateProtocolLocation( |
| 1260 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY); | 1265 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY); |
| 1261 AlternateProtocolInfo alternate = | 1266 |
| 1262 http_server_properties_->GetAlternateProtocol(server); | |
| 1263 DCHECK_EQ(QUIC, alternate.protocol); | 1267 DCHECK_EQ(QUIC, alternate.protocol); |
| 1264 | 1268 |
| 1265 // Since the session was active, there's no longer an | 1269 // Since the session was active, there's no longer an |
| 1266 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the | 1270 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the |
| 1267 // TCP job also fails. So to avoid not using QUIC when we otherwise could, | 1271 // TCP job also fails. So to avoid not using QUIC when we otherwise could, |
| 1268 // we mark it as broken, and then immediately re-enable it. This leaves | 1272 // we mark it as broken, and then immediately re-enable it. This leaves |
| 1269 // QUIC as "recently broken" which means that 0-RTT will be disabled but | 1273 // QUIC as "recently broken" which means that 0-RTT will be disabled but |
| 1270 // we'll still race. | 1274 // we'll still race. |
| 1271 http_server_properties_->SetBrokenAlternateProtocol(server); | 1275 http_server_properties_->SetBrokenAlternateProtocol(server, alternate); |
| 1272 http_server_properties_->ClearAlternateProtocol(server); | 1276 http_server_properties_->RemoveAlternateProtocol(server, alternate); |
| 1273 http_server_properties_->SetAlternateProtocol( | 1277 http_server_properties_->AddAlternateProtocol(server, alternate.port, |
| 1274 server, alternate.port, alternate.protocol, 1); | 1278 alternate.protocol, 1.0); |
| 1275 DCHECK_EQ(QUIC, | |
| 1276 http_server_properties_->GetAlternateProtocol(server).protocol); | |
| 1277 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( | 1279 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( |
| 1278 server)); | 1280 server, alternate)); |
| 1279 } | 1281 } |
| 1280 | 1282 |
| 1281 } // namespace net | 1283 } // namespace net |
| OLD | NEW |