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 <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 #include "net/base/socket_performance_watcher.h" |
| 23 #include "net/base/socket_performance_watcher_factory.h" |
22 #include "net/cert/cert_verifier.h" | 24 #include "net/cert/cert_verifier.h" |
23 #include "net/dns/host_resolver.h" | 25 #include "net/dns/host_resolver.h" |
24 #include "net/dns/single_request_host_resolver.h" | 26 #include "net/dns/single_request_host_resolver.h" |
25 #include "net/http/http_server_properties.h" | 27 #include "net/http/http_server_properties.h" |
26 #include "net/quic/crypto/channel_id_chromium.h" | 28 #include "net/quic/crypto/channel_id_chromium.h" |
27 #include "net/quic/crypto/proof_verifier_chromium.h" | 29 #include "net/quic/crypto/proof_verifier_chromium.h" |
28 #include "net/quic/crypto/quic_random.h" | 30 #include "net/quic/crypto/quic_random.h" |
29 #include "net/quic/crypto/quic_server_info.h" | 31 #include "net/quic/crypto/quic_server_info.h" |
30 #include "net/quic/port_suggester.h" | 32 #include "net/quic/port_suggester.h" |
31 #include "net/quic/quic_chromium_client_session.h" | 33 #include "net/quic/quic_chromium_client_session.h" |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 } | 553 } |
552 | 554 |
553 QuicStreamFactory::QuicStreamFactory( | 555 QuicStreamFactory::QuicStreamFactory( |
554 HostResolver* host_resolver, | 556 HostResolver* host_resolver, |
555 ClientSocketFactory* client_socket_factory, | 557 ClientSocketFactory* client_socket_factory, |
556 base::WeakPtr<HttpServerProperties> http_server_properties, | 558 base::WeakPtr<HttpServerProperties> http_server_properties, |
557 CertVerifier* cert_verifier, | 559 CertVerifier* cert_verifier, |
558 CertPolicyEnforcer* cert_policy_enforcer, | 560 CertPolicyEnforcer* cert_policy_enforcer, |
559 ChannelIDService* channel_id_service, | 561 ChannelIDService* channel_id_service, |
560 TransportSecurityState* transport_security_state, | 562 TransportSecurityState* transport_security_state, |
| 563 const SocketPerformanceWatcherFactory* socket_performance_watcher_factory, |
561 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory, | 564 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory, |
562 QuicRandom* random_generator, | 565 QuicRandom* random_generator, |
563 QuicClock* clock, | 566 QuicClock* clock, |
564 size_t max_packet_length, | 567 size_t max_packet_length, |
565 const std::string& user_agent_id, | 568 const std::string& user_agent_id, |
566 const QuicVersionVector& supported_versions, | 569 const QuicVersionVector& supported_versions, |
567 bool enable_port_selection, | 570 bool enable_port_selection, |
568 bool always_require_handshake_confirmation, | 571 bool always_require_handshake_confirmation, |
569 bool disable_connection_pooling, | 572 bool disable_connection_pooling, |
570 float load_server_info_timeout_srtt_multiplier, | 573 float load_server_info_timeout_srtt_multiplier, |
(...skipping 11 matching lines...) Expand all Loading... |
582 : require_confirmation_(true), | 585 : require_confirmation_(true), |
583 host_resolver_(host_resolver), | 586 host_resolver_(host_resolver), |
584 client_socket_factory_(client_socket_factory), | 587 client_socket_factory_(client_socket_factory), |
585 http_server_properties_(http_server_properties), | 588 http_server_properties_(http_server_properties), |
586 transport_security_state_(transport_security_state), | 589 transport_security_state_(transport_security_state), |
587 quic_server_info_factory_(nullptr), | 590 quic_server_info_factory_(nullptr), |
588 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), | 591 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), |
589 random_generator_(random_generator), | 592 random_generator_(random_generator), |
590 clock_(clock), | 593 clock_(clock), |
591 max_packet_length_(max_packet_length), | 594 max_packet_length_(max_packet_length), |
| 595 socket_performance_watcher_factory_(socket_performance_watcher_factory), |
592 config_(InitializeQuicConfig(connection_options)), | 596 config_(InitializeQuicConfig(connection_options)), |
593 supported_versions_(supported_versions), | 597 supported_versions_(supported_versions), |
594 enable_port_selection_(enable_port_selection), | 598 enable_port_selection_(enable_port_selection), |
595 always_require_handshake_confirmation_( | 599 always_require_handshake_confirmation_( |
596 always_require_handshake_confirmation), | 600 always_require_handshake_confirmation), |
597 disable_connection_pooling_(disable_connection_pooling), | 601 disable_connection_pooling_(disable_connection_pooling), |
598 load_server_info_timeout_srtt_multiplier_( | 602 load_server_info_timeout_srtt_multiplier_( |
599 load_server_info_timeout_srtt_multiplier), | 603 load_server_info_timeout_srtt_multiplier), |
600 enable_connection_racing_(enable_connection_racing), | 604 enable_connection_racing_(enable_connection_racing), |
601 enable_non_blocking_io_(enable_non_blocking_io), | 605 enable_non_blocking_io_(enable_non_blocking_io), |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 } | 1222 } |
1219 | 1223 |
1220 DefaultPacketWriterFactory packet_writer_factory(socket.get()); | 1224 DefaultPacketWriterFactory packet_writer_factory(socket.get()); |
1221 | 1225 |
1222 if (!helper_.get()) { | 1226 if (!helper_.get()) { |
1223 helper_.reset( | 1227 helper_.reset( |
1224 new QuicConnectionHelper(base::ThreadTaskRunnerHandle::Get().get(), | 1228 new QuicConnectionHelper(base::ThreadTaskRunnerHandle::Get().get(), |
1225 clock_.get(), random_generator_)); | 1229 clock_.get(), random_generator_)); |
1226 } | 1230 } |
1227 | 1231 |
| 1232 // Use the factory to create a new socket performance watcher, and pass the |
| 1233 // ownership to the QUIC connection. |
| 1234 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher; |
| 1235 if (socket_performance_watcher_factory_) { |
| 1236 socket_performance_watcher = socket_performance_watcher_factory_ |
| 1237 ->CreateUDPSocketPerformanceWatcher(); |
| 1238 } |
| 1239 |
1228 QuicConnection* connection = new QuicConnection( | 1240 QuicConnection* connection = new QuicConnection( |
1229 connection_id, addr, helper_.get(), packet_writer_factory, | 1241 connection_id, addr, helper_.get(), packet_writer_factory, |
1230 true /* owns_writer */, Perspective::IS_CLIENT, server_id.is_https(), | 1242 true /* owns_writer */, Perspective::IS_CLIENT, server_id.is_https(), |
1231 supported_versions_); | 1243 supported_versions_); |
1232 connection->set_max_packet_length(max_packet_length_); | 1244 connection->set_max_packet_length(max_packet_length_); |
1233 | 1245 |
1234 InitializeCachedStateInCryptoConfig(server_id, server_info); | 1246 InitializeCachedStateInCryptoConfig(server_id, server_info); |
1235 | 1247 |
1236 QuicConfig config = config_; | 1248 QuicConfig config = config_; |
1237 config.SetSocketReceiveBufferToSend(socket_receive_buffer_size_); | 1249 config.SetSocketReceiveBufferToSend(socket_receive_buffer_size_); |
(...skipping 12 matching lines...) Expand all Loading... |
1250 // |server_info|. | 1262 // |server_info|. |
1251 server_info.reset(quic_server_info_factory_->GetForServer(server_id)); | 1263 server_info.reset(quic_server_info_factory_->GetForServer(server_id)); |
1252 server_info->Start(); | 1264 server_info->Start(); |
1253 } | 1265 } |
1254 | 1266 |
1255 *session = new QuicChromiumClientSession( | 1267 *session = new QuicChromiumClientSession( |
1256 connection, socket.Pass(), this, quic_crypto_client_stream_factory_, | 1268 connection, socket.Pass(), this, quic_crypto_client_stream_factory_, |
1257 transport_security_state_, server_info.Pass(), server_id, | 1269 transport_security_state_, server_info.Pass(), server_id, |
1258 cert_verify_flags, config, &crypto_config_, | 1270 cert_verify_flags, config, &crypto_config_, |
1259 network_connection_.GetDescription(), dns_resolution_end_time, | 1271 network_connection_.GetDescription(), dns_resolution_end_time, |
1260 base::ThreadTaskRunnerHandle::Get().get(), net_log.net_log()); | 1272 base::ThreadTaskRunnerHandle::Get().get(), net_log.net_log(), |
| 1273 socket_performance_watcher.Pass()); |
1261 | 1274 |
1262 all_sessions_[*session] = server_id; // owning pointer | 1275 all_sessions_[*session] = server_id; // owning pointer |
1263 | 1276 |
1264 (*session)->Initialize(); | 1277 (*session)->Initialize(); |
1265 bool closed_during_initialize = | 1278 bool closed_during_initialize = |
1266 !ContainsKey(all_sessions_, *session) || | 1279 !ContainsKey(all_sessions_, *session) || |
1267 !(*session)->connection()->connected(); | 1280 !(*session)->connection()->connected(); |
1268 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", | 1281 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", |
1269 closed_during_initialize); | 1282 closed_during_initialize); |
1270 if (closed_during_initialize) { | 1283 if (closed_during_initialize) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 // Since the session was active, there's no longer an | 1416 // Since the session was active, there's no longer an |
1404 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1417 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
1405 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1418 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
1406 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1419 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1407 // still race. | 1420 // still race. |
1408 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1421 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1409 alternative_service); | 1422 alternative_service); |
1410 } | 1423 } |
1411 | 1424 |
1412 } // namespace net | 1425 } // namespace net |
OLD | NEW |