| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "components/network_session_configurator/network_session_configurator.h
" | 5 #include "components/network_session_configurator/network_session_configurator.h
" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // Map from name to value for all parameters associate with a field trial. | 25 // Map from name to value for all parameters associate with a field trial. |
| 26 using VariationParameters = std::map<std::string, std::string>; | 26 using VariationParameters = std::map<std::string, std::string>; |
| 27 | 27 |
| 28 const char kTCPFastOpenFieldTrialName[] = "TCPFastOpen"; | 28 const char kTCPFastOpenFieldTrialName[] = "TCPFastOpen"; |
| 29 const char kTCPFastOpenHttpsEnabledGroupName[] = "HttpsEnabled"; | 29 const char kTCPFastOpenHttpsEnabledGroupName[] = "HttpsEnabled"; |
| 30 | 30 |
| 31 const char kQuicFieldTrialName[] = "QUIC"; | 31 const char kQuicFieldTrialName[] = "QUIC"; |
| 32 const char kQuicFieldTrialEnabledGroupName[] = "Enabled"; | 32 const char kQuicFieldTrialEnabledGroupName[] = "Enabled"; |
| 33 const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled"; | 33 const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled"; |
| 34 | 34 |
| 35 // The SPDY trial composes two different trial plus control groups: | 35 // Field trial for HTTP/2. |
| 36 // * A "holdback" group with SPDY disabled, and corresponding control | 36 const char kHttp2FieldTrialName[] = "HTTP2"; |
| 37 // (SPDY/3.1). The primary purpose of the holdback group is to encourage site | 37 const char kHttp2FieldTrialDisablePrefix[] = "Disable"; |
| 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 | 38 |
| 48 // Field trial for priority dependencies. | 39 // Field trial for priority dependencies. |
| 49 const char kSpdyDependenciesFieldTrial[] = "SpdyEnableDependencies"; | 40 const char kSpdyDependenciesFieldTrial[] = "SpdyEnableDependencies"; |
| 50 const char kSpdyDependenciesFieldTrialEnable[] = "Enable"; | 41 const char kSpdyDependenciesFieldTrialEnable[] = "Enable"; |
| 51 const char kSpdyDepencenciesFieldTrialDisable[] = "Disable"; | 42 const char kSpdyDepencenciesFieldTrialDisable[] = "Disable"; |
| 52 | 43 |
| 53 int GetSwitchValueAsInt(const base::CommandLine& command_line, | 44 int GetSwitchValueAsInt(const base::CommandLine& command_line, |
| 54 const std::string& switch_name) { | 45 const std::string& switch_name) { |
| 55 int value; | 46 int value; |
| 56 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), | 47 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 71 | 62 |
| 72 return it->second; | 63 return it->second; |
| 73 } | 64 } |
| 74 | 65 |
| 75 void ConfigureTCPFastOpenParams(base::StringPiece tfo_trial_group, | 66 void ConfigureTCPFastOpenParams(base::StringPiece tfo_trial_group, |
| 76 net::HttpNetworkSession::Params* params) { | 67 net::HttpNetworkSession::Params* params) { |
| 77 if (tfo_trial_group == kTCPFastOpenHttpsEnabledGroupName) | 68 if (tfo_trial_group == kTCPFastOpenHttpsEnabledGroupName) |
| 78 params->enable_tcp_fast_open_for_ssl = true; | 69 params->enable_tcp_fast_open_for_ssl = true; |
| 79 } | 70 } |
| 80 | 71 |
| 81 void ConfigureSpdyParams(const base::CommandLine& command_line, | 72 void ConfigureHttp2Params(const base::CommandLine& command_line, |
| 82 base::StringPiece spdy_trial_group, | 73 base::StringPiece http2_trial_group, |
| 83 const VariationParameters& spdy_trial_params, | 74 net::HttpNetworkSession::Params* params) { |
| 84 bool is_spdy_allowed_by_policy, | |
| 85 net::HttpNetworkSession::Params* params) { | |
| 86 // Only handle SPDY field trial parameters and command line flags if | |
| 87 // "spdy.disabled" preference is not forced via policy. | |
| 88 if (!is_spdy_allowed_by_policy) { | |
| 89 params->enable_spdy31 = false; | |
| 90 return; | |
| 91 } | |
| 92 | |
| 93 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests)) | 75 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests)) |
| 94 net::URLFetcher::SetIgnoreCertificateRequests(true); | 76 net::URLFetcher::SetIgnoreCertificateRequests(true); |
| 95 | 77 |
| 96 if (command_line.HasSwitch(switches::kDisableHttp2)) { | 78 if (command_line.HasSwitch(switches::kDisableHttp2)) { |
| 97 params->enable_spdy31 = false; | |
| 98 params->enable_http2 = false; | 79 params->enable_http2 = false; |
| 99 return; | 80 return; |
| 100 } | 81 } |
| 101 | 82 |
| 102 if (spdy_trial_group.starts_with(kSpdyFieldTrialHoldbackGroupNamePrefix)) { | 83 if (http2_trial_group.starts_with(kHttp2FieldTrialDisablePrefix)) { |
| 103 net::HttpStreamFactory::set_spdy_enabled(false); | |
| 104 return; | |
| 105 } | |
| 106 if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy31GroupNamePrefix)) { | |
| 107 params->enable_spdy31 = true; | |
| 108 params->enable_http2 = false; | 84 params->enable_http2 = false; |
| 109 return; | |
| 110 } | |
| 111 if (spdy_trial_group.starts_with(kSpdyFieldTrialSpdy4GroupNamePrefix)) { | |
| 112 params->enable_spdy31 = true; | |
| 113 params->enable_http2 = true; | |
| 114 return; | |
| 115 } | |
| 116 if (spdy_trial_group.starts_with(kSpdyFieldTrialParametrizedPrefix)) { | |
| 117 bool spdy_enabled = false; | |
| 118 params->enable_spdy31 = false; | |
| 119 params->enable_http2 = false; | |
| 120 if (base::LowerCaseEqualsASCII( | |
| 121 GetVariationParam(spdy_trial_params, "enable_http2"), "true")) { | |
| 122 spdy_enabled = true; | |
| 123 params->enable_http2 = true; | |
| 124 } | |
| 125 if (base::LowerCaseEqualsASCII( | |
| 126 GetVariationParam(spdy_trial_params, "enable_spdy31"), "true")) { | |
| 127 spdy_enabled = true; | |
| 128 params->enable_spdy31 = true; | |
| 129 } | |
| 130 // TODO(bnc): https://crbug.com/521597 | |
| 131 // HttpStreamFactory::spdy_enabled_ is redundant with params->enable_http2 | |
| 132 // and enable_spdy31, can it be eliminated? | |
| 133 net::HttpStreamFactory::set_spdy_enabled(spdy_enabled); | |
| 134 return; | |
| 135 } | 85 } |
| 136 } | 86 } |
| 137 | 87 |
| 138 void ConfigurePriorityDependencies( | 88 void ConfigurePriorityDependencies( |
| 139 base::StringPiece priority_dependencies_trial_group, | 89 base::StringPiece priority_dependencies_trial_group, |
| 140 net::HttpNetworkSession::Params* params) { | 90 net::HttpNetworkSession::Params* params) { |
| 141 if (priority_dependencies_trial_group.starts_with( | 91 if (priority_dependencies_trial_group.starts_with( |
| 142 kSpdyDependenciesFieldTrialEnable)) { | 92 kSpdyDependenciesFieldTrialEnable)) { |
| 143 params->enable_priority_dependencies = true; | 93 params->enable_priority_dependencies = true; |
| 144 } else if (priority_dependencies_trial_group.starts_with( | 94 } else if (priority_dependencies_trial_group.starts_with( |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 params->origins_to_force_quic_on.insert(net::HostPortPair()); | 431 params->origins_to_force_quic_on.insert(net::HostPortPair()); |
| 482 net::HostPortPair quic_origin = net::HostPortPair::FromString(host_port); | 432 net::HostPortPair quic_origin = net::HostPortPair::FromString(host_port); |
| 483 if (!quic_origin.IsEmpty()) | 433 if (!quic_origin.IsEmpty()) |
| 484 params->origins_to_force_quic_on.insert(quic_origin); | 434 params->origins_to_force_quic_on.insert(quic_origin); |
| 485 } | 435 } |
| 486 } | 436 } |
| 487 } | 437 } |
| 488 | 438 |
| 489 void ParseFieldTrialsAndCommandLineInternal( | 439 void ParseFieldTrialsAndCommandLineInternal( |
| 490 const base::CommandLine& command_line, | 440 const base::CommandLine& command_line, |
| 491 bool is_spdy_allowed_by_policy, | |
| 492 bool is_quic_allowed_by_policy, | 441 bool is_quic_allowed_by_policy, |
| 493 const std::string& quic_user_agent_id, | 442 const std::string& quic_user_agent_id, |
| 494 net::HttpNetworkSession::Params* params) { | 443 net::HttpNetworkSession::Params* params) { |
| 495 // Parameters only controlled by command line. | 444 // Parameters only controlled by command line. |
| 496 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) | 445 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) |
| 497 params->ignore_certificate_errors = true; | 446 params->ignore_certificate_errors = true; |
| 498 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { | 447 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { |
| 499 params->testing_fixed_http_port = | 448 params->testing_fixed_http_port = |
| 500 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort); | 449 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort); |
| 501 } | 450 } |
| 502 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { | 451 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { |
| 503 params->testing_fixed_https_port = | 452 params->testing_fixed_https_port = |
| 504 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort); | 453 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort); |
| 505 } | 454 } |
| 506 | 455 |
| 507 // Always fetch the field trial groups to ensure they are reported correctly. | 456 // Always fetch the field trial groups to ensure they are reported correctly. |
| 508 // The command line flags will be associated with a group that is reported so | 457 // The command line flags will be associated with a group that is reported so |
| 509 // long as trial is actually queried. | 458 // long as trial is actually queried. |
| 510 | 459 |
| 511 std::string quic_trial_group = | 460 std::string quic_trial_group = |
| 512 base::FieldTrialList::FindFullName(kQuicFieldTrialName); | 461 base::FieldTrialList::FindFullName(kQuicFieldTrialName); |
| 513 VariationParameters quic_trial_params; | 462 VariationParameters quic_trial_params; |
| 514 if (!variations::GetVariationParams(kQuicFieldTrialName, &quic_trial_params)) | 463 if (!variations::GetVariationParams(kQuicFieldTrialName, &quic_trial_params)) |
| 515 quic_trial_params.clear(); | 464 quic_trial_params.clear(); |
| 516 ConfigureQuicParams(command_line, quic_trial_group, quic_trial_params, | 465 ConfigureQuicParams(command_line, quic_trial_group, quic_trial_params, |
| 517 is_quic_allowed_by_policy, quic_user_agent_id, params); | 466 is_quic_allowed_by_policy, quic_user_agent_id, params); |
| 518 | 467 |
| 519 if (!is_spdy_allowed_by_policy) { | 468 std::string http2_trial_group = |
| 520 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName); | 469 base::FieldTrialList::FindFullName(kHttp2FieldTrialName); |
| 521 if (trial) | 470 ConfigureHttp2Params(command_line, http2_trial_group, params); |
| 522 trial->Disable(); | |
| 523 } | |
| 524 std::string spdy_trial_group = | |
| 525 base::FieldTrialList::FindFullName(kSpdyFieldTrialName); | |
| 526 VariationParameters spdy_trial_params; | |
| 527 if (!variations::GetVariationParams(kSpdyFieldTrialName, &spdy_trial_params)) | |
| 528 spdy_trial_params.clear(); | |
| 529 ConfigureSpdyParams(command_line, spdy_trial_group, spdy_trial_params, | |
| 530 is_spdy_allowed_by_policy, params); | |
| 531 | 471 |
| 532 const std::string tfo_trial_group = | 472 const std::string tfo_trial_group = |
| 533 base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName); | 473 base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName); |
| 534 ConfigureTCPFastOpenParams(tfo_trial_group, params); | 474 ConfigureTCPFastOpenParams(tfo_trial_group, params); |
| 535 | 475 |
| 536 std::string priority_dependencies_trial_group = | 476 std::string priority_dependencies_trial_group = |
| 537 base::FieldTrialList::FindFullName(kSpdyDependenciesFieldTrial); | 477 base::FieldTrialList::FindFullName(kSpdyDependenciesFieldTrial); |
| 538 ConfigurePriorityDependencies(priority_dependencies_trial_group, params); | 478 ConfigurePriorityDependencies(priority_dependencies_trial_group, params); |
| 539 } | 479 } |
| 540 | 480 |
| 541 } // anonymous namespace | 481 } // anonymous namespace |
| 542 | 482 |
| 543 namespace network_session_configurator { | 483 namespace network_session_configurator { |
| 544 | 484 |
| 545 void ParseFieldTrials(bool is_spdy_allowed_by_policy, | 485 void ParseFieldTrials(bool is_quic_allowed_by_policy, |
| 546 bool is_quic_allowed_by_policy, | |
| 547 const std::string& quic_user_agent_id, | 486 const std::string& quic_user_agent_id, |
| 548 net::HttpNetworkSession::Params* params) { | 487 net::HttpNetworkSession::Params* params) { |
| 549 const base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 488 const base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 550 ParseFieldTrialsAndCommandLineInternal( | 489 ParseFieldTrialsAndCommandLineInternal( |
| 551 command_line, is_spdy_allowed_by_policy, is_quic_allowed_by_policy, | 490 command_line, is_quic_allowed_by_policy, quic_user_agent_id, params); |
| 552 quic_user_agent_id, params); | |
| 553 } | 491 } |
| 554 | 492 |
| 555 void ParseFieldTrialsAndCommandLine(bool is_spdy_allowed_by_policy, | 493 void ParseFieldTrialsAndCommandLine(bool is_quic_allowed_by_policy, |
| 556 bool is_quic_allowed_by_policy, | |
| 557 const std::string& quic_user_agent_id, | 494 const std::string& quic_user_agent_id, |
| 558 net::HttpNetworkSession::Params* params) { | 495 net::HttpNetworkSession::Params* params) { |
| 559 const base::CommandLine& command_line = | 496 const base::CommandLine& command_line = |
| 560 *base::CommandLine::ForCurrentProcess(); | 497 *base::CommandLine::ForCurrentProcess(); |
| 561 ParseFieldTrialsAndCommandLineInternal( | 498 ParseFieldTrialsAndCommandLineInternal( |
| 562 command_line, is_spdy_allowed_by_policy, is_quic_allowed_by_policy, | 499 command_line, is_quic_allowed_by_policy, quic_user_agent_id, params); |
| 563 quic_user_agent_id, params); | |
| 564 } | 500 } |
| 565 | 501 |
| 566 } // namespace network_session_configurator | 502 } // namespace network_session_configurator |
| OLD | NEW |