OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/network_session_configurator/network_session_configurator.h
" |
| 6 |
| 7 #include <map> |
| 8 |
| 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" |
| 14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
| 15 #include "components/network_session_configurator/switches.h" |
| 16 #include "components/variations/variations_associated_data.h" |
| 17 #include "components/version_info/version_info.h" |
| 18 #include "net/http/http_stream_factory.h" |
| 19 #include "net/quic/quic_protocol.h" |
| 20 #include "net/quic/quic_utils.h" |
| 21 #include "net/url_request/url_fetcher.h" |
| 22 |
| 23 namespace { |
| 24 |
| 25 // Map from name to value for all parameters associate with a field trial. |
| 26 using VariationParameters = std::map<std::string, std::string>; |
| 27 |
| 28 const char kTCPFastOpenFieldTrialName[] = "TCPFastOpen"; |
| 29 const char kTCPFastOpenHttpsEnabledGroupName[] = "HttpsEnabled"; |
| 30 |
| 31 const char kQuicFieldTrialName[] = "QUIC"; |
| 32 const char kQuicFieldTrialEnabledGroupName[] = "Enabled"; |
| 33 const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled"; |
| 34 |
| 35 // The SPDY trial composes two different trial plus control groups: |
| 36 // * A "holdback" group with SPDY disabled, and corresponding control |
| 37 // (SPDY/3.1). The primary purpose of the holdback group is to encourage site |
| 38 // operators to do feature detection rather than UA-sniffing. As such, this |
| 39 // trial runs continuously. |
| 40 // * A SPDY/4 experiment, for SPDY/4 (aka HTTP/2) vs SPDY/3.1 comparisons and |
| 41 // eventual SPDY/4 deployment. |
| 42 const char kSpdyFieldTrialName[] = "SPDY"; |
| 43 const char kSpdyFieldTrialHoldbackGroupNamePrefix[] = "SpdyDisabled"; |
| 44 const char kSpdyFieldTrialSpdy31GroupNamePrefix[] = "Spdy31Enabled"; |
| 45 const char kSpdyFieldTrialSpdy4GroupNamePrefix[] = "Spdy4Enabled"; |
| 46 const char kSpdyFieldTrialParametrizedPrefix[] = "Parametrized"; |
| 47 |
| 48 // The AltSvc trial controls whether Alt-Svc headers are parsed. |
| 49 // Disabled: |
| 50 // Alt-Svc headers are not parsed. |
| 51 // Alternate-Protocol headers are parsed. |
| 52 // Enabled: |
| 53 // Alt-Svc headers are parsed, but only same-host entries are used by |
| 54 // default. (Use "enable_alternative_service_with_different_host" QUIC |
| 55 // parameter to enable entries with different hosts.) |
| 56 // Alternate-Protocol headers are ignored for responses that have an Alt-Svc |
| 57 // header. |
| 58 const char kAltSvcFieldTrialName[] = "ParseAltSvc"; |
| 59 const char kAltSvcFieldTrialDisabledPrefix[] = "AltSvcDisabled"; |
| 60 const char kAltSvcFieldTrialEnabledPrefix[] = "AltSvcEnabled"; |
| 61 |
| 62 // Field trial for NPN. |
| 63 const char kNpnTrialName[] = "NPN"; |
| 64 const char kNpnTrialEnabledGroupNamePrefix[] = "Enable"; |
| 65 const char kNpnTrialDisabledGroupNamePrefix[] = "Disable"; |
| 66 |
| 67 // Field trial for priority dependencies. |
| 68 const char kSpdyDependenciesFieldTrial[] = "SpdyEnableDependencies"; |
| 69 const char kSpdyDependenciesFieldTrialEnable[] = "Enable"; |
| 70 const char kSpdyDepencenciesFieldTrialDisable[] = "Disable"; |
| 71 |
| 72 int GetSwitchValueAsInt(const base::CommandLine& command_line, |
| 73 const std::string& switch_name) { |
| 74 int value; |
| 75 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), |
| 76 &value)) { |
| 77 return 0; |
| 78 } |
| 79 return value; |
| 80 } |
| 81 |
| 82 // Returns the value associated with |key| in |params| or "" if the |
| 83 // key is not present in the map. |
| 84 const std::string& GetVariationParam( |
| 85 const std::map<std::string, std::string>& params, |
| 86 const std::string& key) { |
| 87 std::map<std::string, std::string>::const_iterator it = params.find(key); |
| 88 if (it == params.end()) |
| 89 return base::EmptyString(); |
| 90 |
| 91 return it->second; |
| 92 } |
| 93 |
| 94 void ConfigureTCPFastOpenParams(base::StringPiece tfo_trial_group, |
| 95 net::HttpNetworkSession::Params* params) { |
| 96 if (tfo_trial_group == kTCPFastOpenHttpsEnabledGroupName) |
| 97 params->enable_tcp_fast_open_for_ssl = true; |
| 98 } |
| 99 |
| 100 void ConfigureSpdyParams(const base::CommandLine& command_line, |
| 101 base::StringPiece spdy_trial_group, |
| 102 const VariationParameters& spdy_trial_params, |
| 103 bool is_spdy_allowed_by_policy, |
| 104 net::HttpNetworkSession::Params* params) { |
| 105 // Only handle SPDY field trial parameters and command line flags if |
| 106 // "spdy.disabled" preference is not forced via policy. |
| 107 if (!is_spdy_allowed_by_policy) { |
| 108 params->enable_spdy31 = false; |
| 109 params->enable_http2 = false; |
| 110 return; |
| 111 } |
| 112 |
| 113 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests)) |
| 114 net::URLFetcher::SetIgnoreCertificateRequests(true); |
| 115 |
| 116 if (command_line.HasSwitch(switches::kDisableHttp2)) { |
| 117 params->enable_spdy31 = false; |
| 118 params->enable_http2 = false; |
| 119 return; |
| 120 } |
| 121 |
| 122 if (spdy_trial_group.starts_with(kSpdyFieldTrialHoldbackGroupNamePrefix)) { |
| 123 net::HttpStreamFactory::set_spdy_enabled(false); |
| 124 return; |
| 125 } |
| 126 if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy31GroupNamePrefix)) { |
| 127 params->enable_spdy31 = true; |
| 128 params->enable_http2 = false; |
| 129 return; |
| 130 } |
| 131 if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy4GroupNamePrefix)) { |
| 132 params->enable_spdy31 = true; |
| 133 params->enable_http2 = true; |
| 134 return; |
| 135 } |
| 136 if (spdy_trial_group.starts_with(kSpdyFieldTrialParametrizedPrefix)) { |
| 137 bool spdy_enabled = false; |
| 138 params->enable_spdy31 = false; |
| 139 params->enable_http2 = false; |
| 140 if (base::LowerCaseEqualsASCII( |
| 141 GetVariationParam(spdy_trial_params, "enable_http2"), "true")) { |
| 142 spdy_enabled = true; |
| 143 params->enable_http2 = true; |
| 144 } |
| 145 if (base::LowerCaseEqualsASCII( |
| 146 GetVariationParam(spdy_trial_params, "enable_spdy31"), "true")) { |
| 147 spdy_enabled = true; |
| 148 params->enable_spdy31 = true; |
| 149 } |
| 150 // TODO(bnc): https://crbug.com/521597 |
| 151 // HttpStreamFactory::spdy_enabled_ is redundant with params->enable_http2 |
| 152 // and enable_spdy31, can it be eliminated? |
| 153 net::HttpStreamFactory::set_spdy_enabled(spdy_enabled); |
| 154 return; |
| 155 } |
| 156 } |
| 157 |
| 158 void ConfigureAltSvcParams(const base::CommandLine& command_line, |
| 159 base::StringPiece altsvc_trial_group, |
| 160 net::HttpNetworkSession::Params* params) { |
| 161 if (command_line.HasSwitch(switches::kEnableAlternativeServices) || |
| 162 altsvc_trial_group.starts_with(kAltSvcFieldTrialEnabledPrefix)) { |
| 163 params->parse_alternative_services = true; |
| 164 return; |
| 165 } |
| 166 if (altsvc_trial_group.starts_with(kAltSvcFieldTrialDisabledPrefix)) { |
| 167 params->parse_alternative_services = false; |
| 168 } |
| 169 } |
| 170 |
| 171 void ConfigureNPNParams(const base::CommandLine& command_line, |
| 172 base::StringPiece npn_trial_group, |
| 173 net::HttpNetworkSession::Params* params) { |
| 174 if (npn_trial_group.starts_with(kNpnTrialEnabledGroupNamePrefix)) { |
| 175 params->enable_npn = true; |
| 176 } else if (npn_trial_group.starts_with(kNpnTrialDisabledGroupNamePrefix)) { |
| 177 params->enable_npn = false; |
| 178 } |
| 179 } |
| 180 |
| 181 void ConfigurePriorityDependencies( |
| 182 base::StringPiece priority_dependencies_trial_group, |
| 183 net::HttpNetworkSession::Params* params) { |
| 184 if (priority_dependencies_trial_group.starts_with( |
| 185 kSpdyDependenciesFieldTrialEnable)) { |
| 186 params->enable_priority_dependencies = true; |
| 187 } else if (priority_dependencies_trial_group.starts_with( |
| 188 kSpdyDepencenciesFieldTrialDisable)) { |
| 189 params->enable_priority_dependencies = false; |
| 190 } |
| 191 } |
| 192 |
| 193 bool ShouldEnableQuic(const base::CommandLine& command_line, |
| 194 base::StringPiece quic_trial_group, |
| 195 bool is_quic_allowed_by_policy) { |
| 196 if (command_line.HasSwitch(switches::kDisableQuic) || |
| 197 !is_quic_allowed_by_policy) |
| 198 return false; |
| 199 |
| 200 if (command_line.HasSwitch(switches::kEnableQuic)) |
| 201 return true; |
| 202 |
| 203 return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) || |
| 204 quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName); |
| 205 } |
| 206 |
| 207 bool ShouldDisableQuicWhenConnectionTimesOutWithOpenStreams( |
| 208 const VariationParameters& quic_trial_params) { |
| 209 return base::LowerCaseEqualsASCII( |
| 210 GetVariationParam(quic_trial_params, |
| 211 "disable_quic_on_timeout_with_open_streams"), |
| 212 "true"); |
| 213 } |
| 214 |
| 215 bool ShouldQuicDisableConnectionPooling( |
| 216 const VariationParameters& quic_trial_params) { |
| 217 return base::LowerCaseEqualsASCII( |
| 218 GetVariationParam(quic_trial_params, "disable_connection_pooling"), |
| 219 "true"); |
| 220 } |
| 221 |
| 222 bool ShouldQuicEnableAlternativeServicesForDifferentHost( |
| 223 const base::CommandLine& command_line, |
| 224 const VariationParameters& quic_trial_params) { |
| 225 // TODO(bnc): Remove inaccurately named "use_alternative_services" parameter. |
| 226 return command_line.HasSwitch(switches::kEnableAlternativeServices) || |
| 227 base::LowerCaseEqualsASCII( |
| 228 GetVariationParam(quic_trial_params, "use_alternative_services"), |
| 229 "true") || |
| 230 base::LowerCaseEqualsASCII( |
| 231 GetVariationParam( |
| 232 quic_trial_params, |
| 233 "enable_alternative_service_with_different_host"), |
| 234 "true"); |
| 235 } |
| 236 |
| 237 bool ShouldEnableQuicPortSelection(const base::CommandLine& command_line) { |
| 238 if (command_line.HasSwitch(switches::kDisableQuicPortSelection)) |
| 239 return false; |
| 240 |
| 241 if (command_line.HasSwitch(switches::kEnableQuicPortSelection)) |
| 242 return true; |
| 243 |
| 244 return false; // Default to disabling port selection on all channels. |
| 245 } |
| 246 |
| 247 net::QuicTagVector GetQuicConnectionOptions( |
| 248 const base::CommandLine& command_line, |
| 249 const VariationParameters& quic_trial_params) { |
| 250 if (command_line.HasSwitch(switches::kQuicConnectionOptions)) { |
| 251 return net::QuicUtils::ParseQuicConnectionOptions( |
| 252 command_line.GetSwitchValueASCII(switches::kQuicConnectionOptions)); |
| 253 } |
| 254 |
| 255 VariationParameters::const_iterator it = |
| 256 quic_trial_params.find("connection_options"); |
| 257 if (it == quic_trial_params.end()) { |
| 258 return net::QuicTagVector(); |
| 259 } |
| 260 |
| 261 return net::QuicUtils::ParseQuicConnectionOptions(it->second); |
| 262 } |
| 263 |
| 264 bool ShouldQuicAlwaysRequireHandshakeConfirmation( |
| 265 const VariationParameters& quic_trial_params) { |
| 266 return base::LowerCaseEqualsASCII( |
| 267 GetVariationParam(quic_trial_params, |
| 268 "always_require_handshake_confirmation"), |
| 269 "true"); |
| 270 } |
| 271 |
| 272 float GetQuicLoadServerInfoTimeoutSrttMultiplier( |
| 273 const VariationParameters& quic_trial_params) { |
| 274 double value; |
| 275 if (base::StringToDouble( |
| 276 GetVariationParam(quic_trial_params, "load_server_info_time_to_srtt"), |
| 277 &value)) { |
| 278 return static_cast<float>(value); |
| 279 } |
| 280 return 0.0f; |
| 281 } |
| 282 |
| 283 bool ShouldQuicEnableConnectionRacing( |
| 284 const VariationParameters& quic_trial_params) { |
| 285 return base::LowerCaseEqualsASCII( |
| 286 GetVariationParam(quic_trial_params, "enable_connection_racing"), "true"); |
| 287 } |
| 288 |
| 289 bool ShouldQuicEnableNonBlockingIO( |
| 290 const VariationParameters& quic_trial_params) { |
| 291 return base::LowerCaseEqualsASCII( |
| 292 GetVariationParam(quic_trial_params, "enable_non_blocking_io"), "true"); |
| 293 } |
| 294 |
| 295 bool ShouldQuicDisableDiskCache(const VariationParameters& quic_trial_params) { |
| 296 return base::LowerCaseEqualsASCII( |
| 297 GetVariationParam(quic_trial_params, "disable_disk_cache"), "true"); |
| 298 } |
| 299 |
| 300 bool ShouldQuicPreferAes(const VariationParameters& quic_trial_params) { |
| 301 return base::LowerCaseEqualsASCII( |
| 302 GetVariationParam(quic_trial_params, "prefer_aes"), "true"); |
| 303 } |
| 304 |
| 305 int GetQuicMaxNumberOfLossyConnections( |
| 306 const VariationParameters& quic_trial_params) { |
| 307 int value; |
| 308 if (base::StringToInt(GetVariationParam(quic_trial_params, |
| 309 "max_number_of_lossy_connections"), |
| 310 &value)) { |
| 311 return value; |
| 312 } |
| 313 return 0; |
| 314 } |
| 315 |
| 316 float GetQuicPacketLossThreshold(const VariationParameters& quic_trial_params) { |
| 317 double value; |
| 318 if (base::StringToDouble( |
| 319 GetVariationParam(quic_trial_params, "packet_loss_threshold"), |
| 320 &value)) { |
| 321 return static_cast<float>(value); |
| 322 } |
| 323 return 0.0f; |
| 324 } |
| 325 |
| 326 int GetQuicSocketReceiveBufferSize( |
| 327 const VariationParameters& quic_trial_params) { |
| 328 int value; |
| 329 if (base::StringToInt( |
| 330 GetVariationParam(quic_trial_params, "receive_buffer_size"), |
| 331 &value)) { |
| 332 return value; |
| 333 } |
| 334 return 0; |
| 335 } |
| 336 |
| 337 bool ShouldQuicCloseSessionsOnIpChange( |
| 338 const VariationParameters& quic_trial_params) { |
| 339 return base::LowerCaseEqualsASCII( |
| 340 GetVariationParam(quic_trial_params, "close_sessions_on_ip_change"), |
| 341 "true"); |
| 342 } |
| 343 |
| 344 int GetQuicIdleConnectionTimeoutSeconds( |
| 345 const VariationParameters& quic_trial_params) { |
| 346 int value; |
| 347 if (base::StringToInt(GetVariationParam(quic_trial_params, |
| 348 "idle_connection_timeout_seconds"), |
| 349 &value)) { |
| 350 return value; |
| 351 } |
| 352 return 0; |
| 353 } |
| 354 |
| 355 bool ShouldQuicDisablePreConnectIfZeroRtt( |
| 356 const VariationParameters& quic_trial_params) { |
| 357 return base::LowerCaseEqualsASCII( |
| 358 GetVariationParam(quic_trial_params, "disable_preconnect_if_0rtt"), |
| 359 "true"); |
| 360 } |
| 361 |
| 362 std::unordered_set<std::string> GetQuicHostWhitelist( |
| 363 const base::CommandLine& command_line, |
| 364 const VariationParameters& quic_trial_params) { |
| 365 std::string whitelist; |
| 366 if (command_line.HasSwitch(switches::kQuicHostWhitelist)) { |
| 367 whitelist = command_line.GetSwitchValueASCII(switches::kQuicHostWhitelist); |
| 368 } else { |
| 369 whitelist = GetVariationParam(quic_trial_params, "quic_host_whitelist"); |
| 370 } |
| 371 std::unordered_set<std::string> hosts; |
| 372 for (const std::string& host : base::SplitString( |
| 373 whitelist, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 374 hosts.insert(host); |
| 375 } |
| 376 return hosts; |
| 377 } |
| 378 |
| 379 bool ShouldQuicMigrateSessionsOnNetworkChange( |
| 380 const VariationParameters& quic_trial_params) { |
| 381 return base::LowerCaseEqualsASCII( |
| 382 GetVariationParam(quic_trial_params, |
| 383 "migrate_sessions_on_network_change"), |
| 384 "true"); |
| 385 } |
| 386 |
| 387 bool ShouldQuicMigrateSessionsEarly( |
| 388 const VariationParameters& quic_trial_params) { |
| 389 return base::LowerCaseEqualsASCII( |
| 390 GetVariationParam(quic_trial_params, "migrate_sessions_early"), "true"); |
| 391 } |
| 392 |
| 393 size_t GetQuicMaxPacketLength(const base::CommandLine& command_line, |
| 394 const VariationParameters& quic_trial_params) { |
| 395 if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) { |
| 396 unsigned value; |
| 397 if (!base::StringToUint( |
| 398 command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength), |
| 399 &value)) { |
| 400 return 0; |
| 401 } |
| 402 return value; |
| 403 } |
| 404 |
| 405 unsigned value; |
| 406 if (base::StringToUint( |
| 407 GetVariationParam(quic_trial_params, "max_packet_length"), &value)) { |
| 408 return value; |
| 409 } |
| 410 return 0; |
| 411 } |
| 412 |
| 413 net::QuicVersion ParseQuicVersion(const std::string& quic_version) { |
| 414 net::QuicVersionVector supported_versions = net::QuicSupportedVersions(); |
| 415 for (size_t i = 0; i < supported_versions.size(); ++i) { |
| 416 net::QuicVersion version = supported_versions[i]; |
| 417 if (net::QuicVersionToString(version) == quic_version) { |
| 418 return version; |
| 419 } |
| 420 } |
| 421 |
| 422 return net::QUIC_VERSION_UNSUPPORTED; |
| 423 } |
| 424 |
| 425 net::QuicVersion GetQuicVersion(const base::CommandLine& command_line, |
| 426 const VariationParameters& quic_trial_params) { |
| 427 if (command_line.HasSwitch(switches::kQuicVersion)) { |
| 428 return ParseQuicVersion( |
| 429 command_line.GetSwitchValueASCII(switches::kQuicVersion)); |
| 430 } |
| 431 |
| 432 return ParseQuicVersion(GetVariationParam(quic_trial_params, "quic_version")); |
| 433 } |
| 434 |
| 435 void ConfigureQuicParams(const base::CommandLine& command_line, |
| 436 base::StringPiece quic_trial_group, |
| 437 const VariationParameters& quic_trial_params, |
| 438 bool is_quic_allowed_by_policy, |
| 439 const std::string& quic_user_agent_id, |
| 440 net::HttpNetworkSession::Params* params) { |
| 441 params->enable_quic = ShouldEnableQuic(command_line, quic_trial_group, |
| 442 is_quic_allowed_by_policy); |
| 443 params->disable_quic_on_timeout_with_open_streams = |
| 444 ShouldDisableQuicWhenConnectionTimesOutWithOpenStreams(quic_trial_params); |
| 445 |
| 446 if (ShouldQuicEnableAlternativeServicesForDifferentHost(command_line, |
| 447 quic_trial_params)) { |
| 448 params->enable_alternative_service_with_different_host = true; |
| 449 params->parse_alternative_services = true; |
| 450 } else { |
| 451 params->enable_alternative_service_with_different_host = false; |
| 452 } |
| 453 |
| 454 if (params->enable_quic) { |
| 455 params->quic_always_require_handshake_confirmation = |
| 456 ShouldQuicAlwaysRequireHandshakeConfirmation(quic_trial_params); |
| 457 params->quic_disable_connection_pooling = |
| 458 ShouldQuicDisableConnectionPooling(quic_trial_params); |
| 459 int receive_buffer_size = GetQuicSocketReceiveBufferSize(quic_trial_params); |
| 460 if (receive_buffer_size != 0) { |
| 461 params->quic_socket_receive_buffer_size = receive_buffer_size; |
| 462 } |
| 463 float load_server_info_timeout_srtt_multiplier = |
| 464 GetQuicLoadServerInfoTimeoutSrttMultiplier(quic_trial_params); |
| 465 if (load_server_info_timeout_srtt_multiplier != 0) { |
| 466 params->quic_load_server_info_timeout_srtt_multiplier = |
| 467 load_server_info_timeout_srtt_multiplier; |
| 468 } |
| 469 params->quic_enable_connection_racing = |
| 470 ShouldQuicEnableConnectionRacing(quic_trial_params); |
| 471 params->quic_enable_non_blocking_io = |
| 472 ShouldQuicEnableNonBlockingIO(quic_trial_params); |
| 473 params->quic_disable_disk_cache = |
| 474 ShouldQuicDisableDiskCache(quic_trial_params); |
| 475 params->quic_prefer_aes = ShouldQuicPreferAes(quic_trial_params); |
| 476 int max_number_of_lossy_connections = |
| 477 GetQuicMaxNumberOfLossyConnections(quic_trial_params); |
| 478 if (max_number_of_lossy_connections != 0) { |
| 479 params->quic_max_number_of_lossy_connections = |
| 480 max_number_of_lossy_connections; |
| 481 } |
| 482 float packet_loss_threshold = GetQuicPacketLossThreshold(quic_trial_params); |
| 483 if (packet_loss_threshold != 0) |
| 484 params->quic_packet_loss_threshold = packet_loss_threshold; |
| 485 params->enable_quic_port_selection = |
| 486 ShouldEnableQuicPortSelection(command_line); |
| 487 params->quic_connection_options = |
| 488 GetQuicConnectionOptions(command_line, quic_trial_params); |
| 489 params->quic_close_sessions_on_ip_change = |
| 490 ShouldQuicCloseSessionsOnIpChange(quic_trial_params); |
| 491 int idle_connection_timeout_seconds = |
| 492 GetQuicIdleConnectionTimeoutSeconds(quic_trial_params); |
| 493 if (idle_connection_timeout_seconds != 0) { |
| 494 params->quic_idle_connection_timeout_seconds = |
| 495 idle_connection_timeout_seconds; |
| 496 } |
| 497 params->quic_disable_preconnect_if_0rtt = |
| 498 ShouldQuicDisablePreConnectIfZeroRtt(quic_trial_params); |
| 499 params->quic_host_whitelist = |
| 500 GetQuicHostWhitelist(command_line, quic_trial_params); |
| 501 params->quic_migrate_sessions_on_network_change = |
| 502 ShouldQuicMigrateSessionsOnNetworkChange(quic_trial_params); |
| 503 params->quic_migrate_sessions_early = |
| 504 ShouldQuicMigrateSessionsEarly(quic_trial_params); |
| 505 } |
| 506 |
| 507 size_t max_packet_length = |
| 508 GetQuicMaxPacketLength(command_line, quic_trial_params); |
| 509 if (max_packet_length != 0) { |
| 510 params->quic_max_packet_length = max_packet_length; |
| 511 } |
| 512 |
| 513 params->quic_user_agent_id = quic_user_agent_id; |
| 514 |
| 515 net::QuicVersion version = GetQuicVersion(command_line, quic_trial_params); |
| 516 if (version != net::QUIC_VERSION_UNSUPPORTED) { |
| 517 net::QuicVersionVector supported_versions; |
| 518 supported_versions.push_back(version); |
| 519 params->quic_supported_versions = supported_versions; |
| 520 } |
| 521 |
| 522 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) { |
| 523 std::string origins = |
| 524 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn); |
| 525 for (const std::string& host_port : base::SplitString( |
| 526 origins, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 527 net::HostPortPair quic_origin = net::HostPortPair::FromString(host_port); |
| 528 if (!quic_origin.IsEmpty()) |
| 529 params->origins_to_force_quic_on.insert(quic_origin); |
| 530 } |
| 531 } |
| 532 } |
| 533 |
| 534 void ParseFieldTrialsAndCommandLineInternal( |
| 535 const base::CommandLine& command_line, |
| 536 bool is_spdy_allowed_by_policy, |
| 537 bool is_quic_allowed_by_policy, |
| 538 const std::string& quic_user_agent_id, |
| 539 net::HttpNetworkSession::Params* params) { |
| 540 // Parameters only controlled by command line. |
| 541 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) |
| 542 params->ignore_certificate_errors = true; |
| 543 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { |
| 544 params->testing_fixed_http_port = |
| 545 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort); |
| 546 } |
| 547 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { |
| 548 params->testing_fixed_https_port = |
| 549 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort); |
| 550 } |
| 551 |
| 552 // Always fetch the field trial groups to ensure they are reported correctly. |
| 553 // The command line flags will be associated with a group that is reported so |
| 554 // long as trial is actually queried. |
| 555 |
| 556 std::string altsvc_trial_group = |
| 557 base::FieldTrialList::FindFullName(kAltSvcFieldTrialName); |
| 558 ConfigureAltSvcParams(command_line, altsvc_trial_group, params); |
| 559 |
| 560 std::string quic_trial_group = |
| 561 base::FieldTrialList::FindFullName(kQuicFieldTrialName); |
| 562 VariationParameters quic_trial_params; |
| 563 if (!variations::GetVariationParams(kQuicFieldTrialName, &quic_trial_params)) |
| 564 quic_trial_params.clear(); |
| 565 ConfigureQuicParams(command_line, quic_trial_group, quic_trial_params, |
| 566 is_quic_allowed_by_policy, quic_user_agent_id, params); |
| 567 |
| 568 if (!is_spdy_allowed_by_policy) { |
| 569 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName); |
| 570 if (trial) |
| 571 trial->Disable(); |
| 572 } |
| 573 std::string spdy_trial_group = |
| 574 base::FieldTrialList::FindFullName(kSpdyFieldTrialName); |
| 575 VariationParameters spdy_trial_params; |
| 576 if (!variations::GetVariationParams(kSpdyFieldTrialName, &spdy_trial_params)) |
| 577 spdy_trial_params.clear(); |
| 578 ConfigureSpdyParams(command_line, spdy_trial_group, spdy_trial_params, |
| 579 is_spdy_allowed_by_policy, params); |
| 580 |
| 581 const std::string tfo_trial_group = |
| 582 base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName); |
| 583 ConfigureTCPFastOpenParams(tfo_trial_group, params); |
| 584 |
| 585 std::string npn_trial_group = |
| 586 base::FieldTrialList::FindFullName(kNpnTrialName); |
| 587 ConfigureNPNParams(command_line, npn_trial_group, params); |
| 588 |
| 589 std::string priority_dependencies_trial_group = |
| 590 base::FieldTrialList::FindFullName(kSpdyDependenciesFieldTrial); |
| 591 ConfigurePriorityDependencies(priority_dependencies_trial_group, params); |
| 592 } |
| 593 |
| 594 } // anonymous namespace |
| 595 |
| 596 namespace network_session_configurator { |
| 597 |
| 598 void ParseFieldTrials(bool is_spdy_allowed_by_policy, |
| 599 bool is_quic_allowed_by_policy, |
| 600 const std::string& quic_user_agent_id, |
| 601 net::HttpNetworkSession::Params* params) { |
| 602 const base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 603 ParseFieldTrialsAndCommandLineInternal( |
| 604 command_line, is_spdy_allowed_by_policy, is_quic_allowed_by_policy, |
| 605 quic_user_agent_id, params); |
| 606 } |
| 607 |
| 608 void ParseFieldTrialsAndCommandLine(bool is_spdy_allowed_by_policy, |
| 609 bool is_quic_allowed_by_policy, |
| 610 const std::string& quic_user_agent_id, |
| 611 net::HttpNetworkSession::Params* params) { |
| 612 const base::CommandLine& command_line = |
| 613 *base::CommandLine::ForCurrentProcess(); |
| 614 ParseFieldTrialsAndCommandLineInternal( |
| 615 command_line, is_spdy_allowed_by_policy, is_quic_allowed_by_policy, |
| 616 quic_user_agent_id, params); |
| 617 } |
| 618 |
| 619 } // namespace network_session_configurator |
OLD | NEW |