| 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 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 } | 647 } |
| 648 | 648 |
| 649 QuicServerInfo* quic_server_info = nullptr; | 649 QuicServerInfo* quic_server_info = nullptr; |
| 650 if (quic_server_info_factory_) { | 650 if (quic_server_info_factory_) { |
| 651 bool load_from_disk_cache = true; | 651 bool load_from_disk_cache = true; |
| 652 if (http_server_properties_) { | 652 if (http_server_properties_) { |
| 653 const AlternateProtocolMap& alternate_protocol_map = | 653 const AlternateProtocolMap& alternate_protocol_map = |
| 654 http_server_properties_->alternate_protocol_map(); | 654 http_server_properties_->alternate_protocol_map(); |
| 655 AlternateProtocolMap::const_iterator it = | 655 AlternateProtocolMap::const_iterator it = |
| 656 alternate_protocol_map.Peek(server_id.host_port_pair()); | 656 alternate_protocol_map.Peek(server_id.host_port_pair()); |
| 657 if (it == alternate_protocol_map.end() || it->second.protocol != QUIC) { | 657 // If there is no entry for QUIC, consider that as a new server and |
| 658 // If there is no entry for QUIC, consider that as a new server and | 658 // don't wait for Cache thread to load the data for that server. |
| 659 // don't wait for Cache thread to load the data for that server. | 659 if (it == alternate_protocol_map.end()) { |
| 660 load_from_disk_cache = false; | 660 load_from_disk_cache = false; |
| 661 } else { |
| 662 AlternateProtocols alternate_protocols = it->second; |
| 663 AlternateProtocols::iterator alternate; |
| 664 for (alternate = alternate_protocols.begin(); |
| 665 alternate != alternate_protocols.end(); ++alternate) { |
| 666 if (alternate->protocol == QUIC) { |
| 667 break; |
| 668 } |
| 669 } |
| 670 if (alternate == alternate_protocols.end()) { |
| 671 load_from_disk_cache = false; |
| 672 } |
| 661 } | 673 } |
| 662 } | 674 } |
| 663 if (load_from_disk_cache) { | 675 if (load_from_disk_cache) { |
| 664 QuicCryptoClientConfig::CachedState* cached = | 676 QuicCryptoClientConfig::CachedState* cached = |
| 665 crypto_config_.LookupOrCreate(server_id); | 677 crypto_config_.LookupOrCreate(server_id); |
| 666 DCHECK(cached); | 678 DCHECK(cached); |
| 667 if (cached->IsEmpty()) { | 679 if (cached->IsEmpty()) { |
| 668 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | 680 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
| 669 } | 681 } |
| 670 } | 682 } |
| 671 } | 683 } |
| 672 // TODO(rtenneti): Initialize task_runner_ in the constructor after | 684 // TODO(rtenneti): Initialize task_runner_ in the constructor after |
| 673 // WebRequestActionWithThreadsTest.* tests are fixed. | 685 // WebRequestActionWithThreadsTest.* tests are fixed. |
| 674 if (!task_runner_) | 686 if (!task_runner_) |
| 675 task_runner_ = base::MessageLoop::current()->message_loop_proxy().get(); | 687 task_runner_ = base::MessageLoop::current()->message_loop_proxy().get(); |
| 676 | 688 |
| 677 bool was_alternate_protocol_recently_broken = | 689 bool was_alternate_protocol_recently_broken = false; |
| 678 http_server_properties_ && | 690 if (http_server_properties_ && |
| 679 http_server_properties_->WasAlternateProtocolRecentlyBroken( | 691 http_server_properties_->HasAlternateProtocol( |
| 680 server_id.host_port_pair()); | 692 server_id.host_port_pair())) { |
| 693 AlternateProtocols alternate_protocols = |
| 694 http_server_properties_->GetAlternateProtocols( |
| 695 server_id.host_port_pair()); |
| 696 AlternateProtocolInfo alternate_protocol = alternate_protocols[0]; |
| 697 was_alternate_protocol_recently_broken = |
| 698 http_server_properties_->WasAlternateProtocolRecentlyBroken( |
| 699 server_id.host_port_pair(), alternate_protocol); |
| 700 } |
| 681 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, is_https, | 701 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, is_https, |
| 682 was_alternate_protocol_recently_broken, | 702 was_alternate_protocol_recently_broken, |
| 683 privacy_mode, method, quic_server_info, net_log)); | 703 privacy_mode, method, quic_server_info, net_log)); |
| 684 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 704 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
| 685 base::Unretained(this), job.get())); | 705 base::Unretained(this), job.get())); |
| 686 | 706 |
| 687 if (rv == ERR_IO_PENDING) { | 707 if (rv == ERR_IO_PENDING) { |
| 688 active_requests_[request] = job.get(); | 708 active_requests_[request] = job.get(); |
| 689 job_requests_map_[job.get()].insert(request); | 709 job_requests_map_[job.get()].insert(request); |
| 690 active_jobs_[server_id] = job.release(); | 710 active_jobs_[server_id] = job.release(); |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 if (!server_info) | 1199 if (!server_info) |
| 1180 return; | 1200 return; |
| 1181 | 1201 |
| 1182 QuicCryptoClientConfig::CachedState* cached = | 1202 QuicCryptoClientConfig::CachedState* cached = |
| 1183 crypto_config_.LookupOrCreate(server_id); | 1203 crypto_config_.LookupOrCreate(server_id); |
| 1184 if (!cached->IsEmpty()) | 1204 if (!cached->IsEmpty()) |
| 1185 return; | 1205 return; |
| 1186 | 1206 |
| 1187 if (http_server_properties_) { | 1207 if (http_server_properties_) { |
| 1188 if (quic_supported_servers_at_startup_.empty()) { | 1208 if (quic_supported_servers_at_startup_.empty()) { |
| 1189 for (const std::pair<const net::HostPortPair, net::AlternateProtocolInfo>& | 1209 for (auto key_value : http_server_properties_->alternate_protocol_map()) { |
| 1190 key_value : http_server_properties_->alternate_protocol_map()) { | 1210 for (auto alternate_protocol : key_value.second) { |
| 1191 if (key_value.second.protocol == QUIC) { | 1211 if (alternate_protocol.protocol == QUIC) { |
| 1192 quic_supported_servers_at_startup_.insert(key_value.first); | 1212 quic_supported_servers_at_startup_.insert(key_value.first); |
| 1213 } |
| 1193 } | 1214 } |
| 1194 } | 1215 } |
| 1195 } | 1216 } |
| 1196 | 1217 |
| 1197 // TODO(rtenneti): Delete the following histogram after collecting stats. | 1218 // TODO(rtenneti): Delete the following histogram after collecting stats. |
| 1198 // If the AlternateProtocolMap contained an entry for this host, check if | 1219 // If the AlternateProtocolMap contained an entry for this host, check if |
| 1199 // the disk cache contained an entry for it. | 1220 // the disk cache contained an entry for it. |
| 1200 if (ContainsKey(quic_supported_servers_at_startup_, | 1221 if (ContainsKey(quic_supported_servers_at_startup_, |
| 1201 server_id.host_port_pair())) { | 1222 server_id.host_port_pair())) { |
| 1202 UMA_HISTOGRAM_BOOLEAN( | 1223 UMA_HISTOGRAM_BOOLEAN( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 // alternate-protocol state is unknown. | 1272 // alternate-protocol state is unknown. |
| 1252 if (!http_server_properties_->HasAlternateProtocol(server)) | 1273 if (!http_server_properties_->HasAlternateProtocol(server)) |
| 1253 return; | 1274 return; |
| 1254 | 1275 |
| 1255 // TODO(rch): In the special case where the session has received no | 1276 // TODO(rch): In the special case where the session has received no |
| 1256 // packets from the peer, we should consider blacklisting this | 1277 // packets from the peer, we should consider blacklisting this |
| 1257 // differently so that we still race TCP but we don't consider the | 1278 // differently so that we still race TCP but we don't consider the |
| 1258 // session connected until the handshake has been confirmed. | 1279 // session connected until the handshake has been confirmed. |
| 1259 HistogramBrokenAlternateProtocolLocation( | 1280 HistogramBrokenAlternateProtocolLocation( |
| 1260 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY); | 1281 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY); |
| 1261 AlternateProtocolInfo alternate = | 1282 |
| 1262 http_server_properties_->GetAlternateProtocol(server); | 1283 const AlternateProtocols alternate_protocols = |
| 1263 DCHECK_EQ(QUIC, alternate.protocol); | 1284 http_server_properties_->GetAlternateProtocols(server); |
| 1285 AlternateProtocols::const_iterator alternate; |
| 1286 for (alternate = alternate_protocols.begin(); |
| 1287 alternate != alternate_protocols.end(); ++alternate) { |
| 1288 if (alternate->protocol == QUIC) { |
| 1289 break; |
| 1290 } |
| 1291 } |
| 1292 // Do not use DCHECK_NE as operator<<(ostream, iterator) is not defined. |
| 1293 DCHECK(alternate != alternate_protocols.end()) |
| 1294 << "No QUIC alternate protocol found"; |
| 1264 | 1295 |
| 1265 // Since the session was active, there's no longer an | 1296 // Since the session was active, there's no longer an |
| 1266 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the | 1297 // 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, | 1298 // 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 | 1299 // 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 | 1300 // QUIC as "recently broken" which means that 0-RTT will be disabled but |
| 1270 // we'll still race. | 1301 // we'll still race. |
| 1271 http_server_properties_->SetBrokenAlternateProtocol(server); | 1302 http_server_properties_->SetBrokenAlternateProtocol(server, *alternate); |
| 1272 http_server_properties_->ClearAlternateProtocol(server); | 1303 http_server_properties_->RemoveAlternateProtocol(server, *alternate); |
| 1273 http_server_properties_->SetAlternateProtocol( | 1304 http_server_properties_->AddAlternateProtocol(server, alternate->port, |
| 1274 server, alternate.port, alternate.protocol, 1); | 1305 alternate->protocol, 1); |
| 1275 DCHECK_EQ(QUIC, | |
| 1276 http_server_properties_->GetAlternateProtocol(server).protocol); | |
| 1277 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( | 1306 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( |
| 1278 server)); | 1307 server, *alternate)); |
| 1279 } | 1308 } |
| 1280 | 1309 |
| 1281 } // namespace net | 1310 } // namespace net |
| OLD | NEW |