| 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 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 } | 650 } |
| 651 | 651 |
| 652 QuicServerInfo* quic_server_info = nullptr; | 652 QuicServerInfo* quic_server_info = nullptr; |
| 653 if (quic_server_info_factory_) { | 653 if (quic_server_info_factory_) { |
| 654 bool load_from_disk_cache = true; | 654 bool load_from_disk_cache = true; |
| 655 if (disable_loading_server_info_for_new_servers_) { | 655 if (disable_loading_server_info_for_new_servers_) { |
| 656 const AlternateProtocolMap& alternate_protocol_map = | 656 const AlternateProtocolMap& alternate_protocol_map = |
| 657 http_server_properties_->alternate_protocol_map(); | 657 http_server_properties_->alternate_protocol_map(); |
| 658 AlternateProtocolMap::const_iterator it = | 658 AlternateProtocolMap::const_iterator it = |
| 659 alternate_protocol_map.Peek(server_id.host_port_pair()); | 659 alternate_protocol_map.Peek(server_id.host_port_pair()); |
| 660 if (it == alternate_protocol_map.end() || it->second.protocol != QUIC) { | 660 // If there is no entry for QUIC, consider that as a new server and |
| 661 // If there is no entry for QUIC, consider that as a new server and | 661 // don't wait for Cache thread to load the data for that server. |
| 662 // don't wait for Cache thread to load the data for that server. | 662 if (it == alternate_protocol_map.end()) { |
| 663 load_from_disk_cache = false; | 663 load_from_disk_cache = false; |
| 664 } else { |
| 665 AlternateProtocols alternate_protocols = it->second; |
| 666 AlternateProtocols::iterator alternate; |
| 667 for (alternate = alternate_protocols.begin(); |
| 668 alternate != alternate_protocols.end(); ++alternate) { |
| 669 if (alternate->protocol == QUIC) { |
| 670 break; |
| 671 } |
| 672 } |
| 673 if (alternate == alternate_protocols.end()) { |
| 674 load_from_disk_cache = false; |
| 675 } |
| 664 } | 676 } |
| 665 } | 677 } |
| 666 if (load_from_disk_cache) { | 678 if (load_from_disk_cache) { |
| 667 QuicCryptoClientConfig::CachedState* cached = | 679 QuicCryptoClientConfig::CachedState* cached = |
| 668 crypto_config_.LookupOrCreate(server_id); | 680 crypto_config_.LookupOrCreate(server_id); |
| 669 DCHECK(cached); | 681 DCHECK(cached); |
| 670 if (cached->IsEmpty()) { | 682 if (cached->IsEmpty()) { |
| 671 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | 683 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
| 672 } | 684 } |
| 673 } | 685 } |
| 674 } | 686 } |
| 675 // TODO(rtenneti): Initialize task_runner_ in the constructor after | 687 // TODO(rtenneti): Initialize task_runner_ in the constructor after |
| 676 // WebRequestActionWithThreadsTest.* tests are fixed. | 688 // WebRequestActionWithThreadsTest.* tests are fixed. |
| 677 if (!task_runner_) | 689 if (!task_runner_) |
| 678 task_runner_ = base::MessageLoop::current()->message_loop_proxy().get(); | 690 task_runner_ = base::MessageLoop::current()->message_loop_proxy().get(); |
| 679 | 691 |
| 680 bool was_alternate_protocol_recently_broken = | 692 bool was_alternate_protocol_recently_broken = false; |
| 681 http_server_properties_ && | 693 if (http_server_properties_ && |
| 682 http_server_properties_->WasAlternateProtocolRecentlyBroken( | 694 http_server_properties_->HasAlternateProtocol( |
| 683 server_id.host_port_pair()); | 695 server_id.host_port_pair())) { |
| 696 AlternateProtocols alternate_protocols = |
| 697 http_server_properties_->GetAlternateProtocols( |
| 698 server_id.host_port_pair()); |
| 699 AlternateProtocolInfo alternate_protocol = alternate_protocols[0]; |
| 700 was_alternate_protocol_recently_broken = |
| 701 http_server_properties_->WasAlternateProtocolRecentlyBroken( |
| 702 server_id.host_port_pair(), alternate_protocol); |
| 703 } |
| 684 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, is_https, | 704 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, is_https, |
| 685 was_alternate_protocol_recently_broken, | 705 was_alternate_protocol_recently_broken, |
| 686 privacy_mode, method, quic_server_info, net_log)); | 706 privacy_mode, method, quic_server_info, net_log)); |
| 687 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 707 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
| 688 base::Unretained(this), job.get())); | 708 base::Unretained(this), job.get())); |
| 689 | 709 |
| 690 if (rv == ERR_IO_PENDING) { | 710 if (rv == ERR_IO_PENDING) { |
| 691 active_requests_[request] = job.get(); | 711 active_requests_[request] = job.get(); |
| 692 job_requests_map_[job.get()].insert(request); | 712 job_requests_map_[job.get()].insert(request); |
| 693 active_jobs_[server_id] = job.release(); | 713 active_jobs_[server_id] = job.release(); |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 if (!server_info) | 1159 if (!server_info) |
| 1140 return; | 1160 return; |
| 1141 | 1161 |
| 1142 QuicCryptoClientConfig::CachedState* cached = | 1162 QuicCryptoClientConfig::CachedState* cached = |
| 1143 crypto_config_.LookupOrCreate(server_id); | 1163 crypto_config_.LookupOrCreate(server_id); |
| 1144 if (!cached->IsEmpty()) | 1164 if (!cached->IsEmpty()) |
| 1145 return; | 1165 return; |
| 1146 | 1166 |
| 1147 if (http_server_properties_) { | 1167 if (http_server_properties_) { |
| 1148 if (quic_supported_servers_at_startup_.empty()) { | 1168 if (quic_supported_servers_at_startup_.empty()) { |
| 1149 for (const std::pair<const net::HostPortPair, net::AlternateProtocolInfo>& | 1169 for (auto key_value : http_server_properties_->alternate_protocol_map()) { |
| 1150 key_value : http_server_properties_->alternate_protocol_map()) { | 1170 for (auto alternate_protocol : key_value.second) { |
| 1151 if (key_value.second.protocol == QUIC) { | 1171 if (alternate_protocol.protocol == QUIC) { |
| 1152 quic_supported_servers_at_startup_.insert(key_value.first); | 1172 quic_supported_servers_at_startup_.insert(key_value.first); |
| 1173 } |
| 1153 } | 1174 } |
| 1154 } | 1175 } |
| 1155 } | 1176 } |
| 1156 | 1177 |
| 1157 // TODO(rtenneti): Delete the following histogram after collecting stats. | 1178 // TODO(rtenneti): Delete the following histogram after collecting stats. |
| 1158 // If the AlternateProtocolMap contained an entry for this host, check if | 1179 // If the AlternateProtocolMap contained an entry for this host, check if |
| 1159 // the disk cache contained an entry for it. | 1180 // the disk cache contained an entry for it. |
| 1160 if (ContainsKey(quic_supported_servers_at_startup_, | 1181 if (ContainsKey(quic_supported_servers_at_startup_, |
| 1161 server_id.host_port_pair())) { | 1182 server_id.host_port_pair())) { |
| 1162 UMA_HISTOGRAM_BOOLEAN( | 1183 UMA_HISTOGRAM_BOOLEAN( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 // alternate-protocol state is unknown. | 1232 // alternate-protocol state is unknown. |
| 1212 if (!http_server_properties_->HasAlternateProtocol(server)) | 1233 if (!http_server_properties_->HasAlternateProtocol(server)) |
| 1213 return; | 1234 return; |
| 1214 | 1235 |
| 1215 // TODO(rch): In the special case where the session has received no | 1236 // TODO(rch): In the special case where the session has received no |
| 1216 // packets from the peer, we should consider blacklisting this | 1237 // packets from the peer, we should consider blacklisting this |
| 1217 // differently so that we still race TCP but we don't consider the | 1238 // differently so that we still race TCP but we don't consider the |
| 1218 // session connected until the handshake has been confirmed. | 1239 // session connected until the handshake has been confirmed. |
| 1219 HistogramBrokenAlternateProtocolLocation( | 1240 HistogramBrokenAlternateProtocolLocation( |
| 1220 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY); | 1241 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY); |
| 1221 AlternateProtocolInfo alternate = | 1242 |
| 1222 http_server_properties_->GetAlternateProtocol(server); | 1243 const AlternateProtocols alternate_protocols = |
| 1223 DCHECK_EQ(QUIC, alternate.protocol); | 1244 http_server_properties_->GetAlternateProtocols(server); |
| 1245 AlternateProtocols::const_iterator alternate; |
| 1246 for (alternate = alternate_protocols.begin(); |
| 1247 alternate != alternate_protocols.end(); ++alternate) { |
| 1248 if (alternate->protocol == QUIC) { |
| 1249 break; |
| 1250 } |
| 1251 } |
| 1252 // Do not use DCHECK_NE as operator<<(ostream, iterator) is not defined. |
| 1253 DCHECK(alternate != alternate_protocols.end()) |
| 1254 << "No QUIC alternate protocol found"; |
| 1224 | 1255 |
| 1225 // Since the session was active, there's no longer an | 1256 // Since the session was active, there's no longer an |
| 1226 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the | 1257 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the |
| 1227 // TCP job also fails. So to avoid not using QUIC when we otherwise could, | 1258 // TCP job also fails. So to avoid not using QUIC when we otherwise could, |
| 1228 // we mark it as broken, and then immediately re-enable it. This leaves | 1259 // we mark it as broken, and then immediately re-enable it. This leaves |
| 1229 // QUIC as "recently broken" which means that 0-RTT will be disabled but | 1260 // QUIC as "recently broken" which means that 0-RTT will be disabled but |
| 1230 // we'll still race. | 1261 // we'll still race. |
| 1231 http_server_properties_->SetBrokenAlternateProtocol(server); | 1262 http_server_properties_->SetBrokenAlternateProtocol(server, *alternate); |
| 1232 http_server_properties_->ClearAlternateProtocol(server); | 1263 http_server_properties_->RemoveAlternateProtocol(server, *alternate); |
| 1233 http_server_properties_->SetAlternateProtocol( | 1264 http_server_properties_->AddAlternateProtocol(server, alternate->port, |
| 1234 server, alternate.port, alternate.protocol, 1); | 1265 alternate->protocol, 1); |
| 1235 DCHECK_EQ(QUIC, | |
| 1236 http_server_properties_->GetAlternateProtocol(server).protocol); | |
| 1237 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( | 1266 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( |
| 1238 server)); | 1267 server, *alternate)); |
| 1239 } | 1268 } |
| 1240 | 1269 |
| 1241 } // namespace net | 1270 } // namespace net |
| OLD | NEW |