flag-max-connections-per-host.patch 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. From: csagan5 <32685696+csagan5@users.noreply.github.com>
  2. Date: Sun, 8 Jul 2018 22:42:04 +0200
  3. Subject: Add flag to configure maximum connections per host
  4. With the introduction of this flag it is possible to increase the maximum
  5. allowed connections per host; this can however be detrimental to devices
  6. with limited CPU/memory resources and it is disabled by default.
  7. ---
  8. chrome/browser/about_flags.cc | 8 ++++++++
  9. chrome/browser/flag_descriptions.cc | 4 ++++
  10. chrome/browser/flag_descriptions.h | 3 +++
  11. .../common/network_features.cc | 3 +++
  12. .../common/network_features.h | 4 ++++
  13. .../common/network_switch_list.h | 4 ++++
  14. net/socket/client_socket_pool_manager.cc | 16 ++++++++++++++++
  15. 7 files changed, 42 insertions(+)
  16. --- a/chrome/browser/about_flags.cc
  17. +++ b/chrome/browser/about_flags.cc
  18. @@ -619,6 +619,11 @@ const FeatureEntry::Choice kForceEffecti
  19. net::kEffectiveConnectionType4G},
  20. };
  21. +const FeatureEntry::Choice kMaxConnectionsPerHostChoices[] = {
  22. + {features::kMaxConnectionsPerHostChoiceDefault, "", ""},
  23. + {features::kMaxConnectionsPerHostChoice15, switches::kMaxConnectionsPerHost, "15"},
  24. +};
  25. +
  26. // Ensure that all effective connection types returned by Network Quality
  27. // Estimator (NQE) are also exposed via flags.
  28. static_assert(net::EFFECTIVE_CONNECTION_TYPE_LAST + 2 ==
  29. @@ -2217,6 +2222,9 @@ const FeatureEntry kFeatureEntries[] = {
  30. flag_descriptions::kAutofillCreditCardUploadDescription, kOsAll,
  31. FEATURE_VALUE_TYPE(autofill::features::kAutofillUpstream)},
  32. #endif // TOOLKIT_VIEWS || OS_ANDROID
  33. + {"max-connections-per-host", flag_descriptions::kMaxConnectionsPerHostName,
  34. + flag_descriptions::kMaxConnectionsPerHostDescription, kOsAll,
  35. + MULTI_VALUE_TYPE(kMaxConnectionsPerHostChoices)},
  36. {"force-ui-direction", flag_descriptions::kForceUiDirectionName,
  37. flag_descriptions::kForceUiDirectionDescription, kOsAll,
  38. MULTI_VALUE_TYPE(kForceUIDirectionChoices)},
  39. --- a/chrome/browser/flag_descriptions.cc
  40. +++ b/chrome/browser/flag_descriptions.cc
  41. @@ -1206,6 +1206,10 @@ const char kLookalikeUrlNavigationSugges
  42. const char kMarkHttpAsName[] = "Mark non-secure origins as non-secure";
  43. const char kMarkHttpAsDescription[] = "Change the UI treatment for HTTP pages";
  44. +const char kMaxConnectionsPerHostName[] = "Maximum connections per host";
  45. +const char kMaxConnectionsPerHostDescription[] =
  46. + "Customize maximum allowed connections per host.";
  47. +
  48. const char kMediaRouterCastAllowAllIPsName[] =
  49. "Connect to Cast devices on all IP addresses";
  50. const char kMediaRouterCastAllowAllIPsDescription[] =
  51. --- a/chrome/browser/flag_descriptions.h
  52. +++ b/chrome/browser/flag_descriptions.h
  53. @@ -733,6 +733,9 @@ extern const char kMarkHttpAsWarning[];
  54. extern const char kMarkHttpAsWarningAndDangerousOnFormEdits[];
  55. extern const char kMarkHttpAsWarningAndDangerousOnPasswordsAndCreditCards[];
  56. +extern const char kMaxConnectionsPerHostName[];
  57. +extern const char kMaxConnectionsPerHostDescription[];
  58. +
  59. extern const char kMediaRouterCastAllowAllIPsName[];
  60. extern const char kMediaRouterCastAllowAllIPsDescription[];
  61. --- a/components/network_session_configurator/common/network_features.cc
  62. +++ b/components/network_session_configurator/common/network_features.cc
  63. @@ -8,6 +8,9 @@
  64. namespace features {
  65. +const char kMaxConnectionsPerHostChoiceDefault[] = "6",
  66. + kMaxConnectionsPerHostChoice15[] = "15";
  67. +
  68. const base::Feature kDnsOverHttps{"dns-over-https",
  69. base::FEATURE_DISABLED_BY_DEFAULT};
  70. --- a/components/network_session_configurator/common/network_features.h
  71. +++ b/components/network_session_configurator/common/network_features.h
  72. @@ -10,6 +10,10 @@
  73. namespace features {
  74. +NETWORK_SESSION_CONFIGURATOR_EXPORT extern const char kMaxConnectionsPerHostChoiceDefault[],
  75. + kMaxConnectionsPerHostChoice6[],
  76. + kMaxConnectionsPerHostChoice15[];
  77. +
  78. // Enabled DNS over HTTPS
  79. // (https://tools.ietf.org/id/draft-ietf-doh-dns-over-https-12.txt).
  80. NETWORK_SESSION_CONFIGURATOR_EXPORT extern const base::Feature kDnsOverHttps;
  81. --- a/components/network_session_configurator/common/network_switch_list.h
  82. +++ b/components/network_session_configurator/common/network_switch_list.h
  83. @@ -22,6 +22,10 @@ NETWORK_SWITCH(kEnableUserAlternateProto
  84. // Enables the QUIC protocol. This is a temporary testing flag.
  85. NETWORK_SWITCH(kEnableQuic, "enable-quic")
  86. +// Allows specifying a higher number of maximum connections per host
  87. +// (15 instead of 6, mirroring the value Mozilla uses).
  88. +NETWORK_SWITCH(kMaxConnectionsPerHost, "max-connections-per-host")
  89. +
  90. // Ignores certificate-related errors.
  91. NETWORK_SWITCH(kIgnoreCertificateErrors, "ignore-certificate-errors")
  92. --- a/chrome/browser/browser_process_impl.cc
  93. +++ b/chrome/browser/browser_process_impl.cc
  94. @@ -18,12 +18,14 @@
  95. #include "base/debug/leak_annotations.h"
  96. #include "base/files/file_path.h"
  97. #include "base/location.h"
  98. +#include "base/logging.h"
  99. #include "base/macros.h"
  100. #include "base/memory/ptr_util.h"
  101. #include "base/metrics/histogram_macros.h"
  102. #include "base/path_service.h"
  103. #include "base/run_loop.h"
  104. #include "base/single_thread_task_runner.h"
  105. +#include "base/strings/string_number_conversions.h"
  106. #include "base/synchronization/waitable_event.h"
  107. #include "base/task/post_task.h"
  108. #include "base/task/task_traits.h"
  109. @@ -95,6 +97,7 @@
  110. #include "components/metrics/metrics_service.h"
  111. #include "components/metrics_services_manager/metrics_services_manager.h"
  112. #include "components/metrics_services_manager/metrics_services_manager_client.h"
  113. +#include "components/network_session_configurator/common/network_switches.h"
  114. #include "components/network_time/network_time_tracker.h"
  115. #include "components/optimization_guide/optimization_guide_features.h"
  116. #include "components/optimization_guide/optimization_guide_service.h"
  117. @@ -130,6 +133,7 @@
  118. #include "extensions/buildflags/buildflags.h"
  119. #include "extensions/common/constants.h"
  120. #include "media/media_buildflags.h"
  121. +#include "net/socket/client_socket_pool_manager.h"
  122. #include "ppapi/buildflags/buildflags.h"
  123. #include "printing/buildflags/buildflags.h"
  124. #include "services/network/public/cpp/features.h"
  125. @@ -315,6 +319,18 @@ void BrowserProcessImpl::Init() {
  126. base::Bind(&ApplyMetricsReportingPolicy));
  127. #endif
  128. + int max_connections_per_host = 0;
  129. + auto switch_value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
  130. + switches::kMaxConnectionsPerHost);
  131. + if (!switch_value.empty() && !base::StringToInt(switch_value, &max_connections_per_host)) {
  132. + LOG(DFATAL) << "--" << switches::kMaxConnectionsPerHost
  133. + << " expected integer; got (\"" << switch_value << "\" instead)";
  134. + }
  135. + if (max_connections_per_host != 0) {
  136. + net::ClientSocketPoolManager::set_max_sockets_per_group(
  137. + net::HttpNetworkSession::NORMAL_SOCKET_POOL, max_connections_per_host);
  138. + }
  139. +
  140. DCHECK(!webrtc_event_log_manager_);
  141. webrtc_event_log_manager_ = WebRtcEventLogManager::CreateSingletonInstance();
  142. --- a/chrome/browser/BUILD.gn
  143. +++ b/chrome/browser/BUILD.gn
  144. @@ -1991,6 +1991,7 @@ jumbo_split_static_library("browser") {
  145. "//components/net_log",
  146. "//components/network_hints/common",
  147. "//components/network_session_configurator/browser",
  148. + "//components/network_session_configurator/common",
  149. "//components/network_time",
  150. "//components/ntp_tiles",
  151. "//components/offline_items_collection/core",