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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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/BUILD.gn
  17. +++ b/chrome/browser/BUILD.gn
  18. @@ -2331,6 +2331,7 @@ static_library("browser") {
  19. "//components/net_log",
  20. "//components/network_hints/common:mojo_bindings",
  21. "//components/network_session_configurator/browser",
  22. + "//components/network_session_configurator/common",
  23. "//components/network_time",
  24. "//components/no_state_prefetch/browser",
  25. "//components/no_state_prefetch/common",
  26. --- a/chrome/browser/bromite_flag_choices.h
  27. +++ b/chrome/browser/bromite_flag_choices.h
  28. @@ -4,4 +4,8 @@
  29. #ifndef CHROME_BROWSER_BROMITE_FLAG_CHOICES_H_
  30. #define CHROME_BROWSER_BROMITE_FLAG_CHOICES_H_
  31. +const FeatureEntry::Choice kMaxConnectionsPerHostChoices[] = {
  32. + {features::kMaxConnectionsPerHostChoiceDefault, "", ""},
  33. + {features::kMaxConnectionsPerHostChoice15, switches::kMaxConnectionsPerHost, "15"},
  34. +};
  35. #endif // CHROME_BROWSER_BROMITE_FLAG_CHOICES_H_
  36. --- a/chrome/browser/bromite_flag_entries.h
  37. +++ b/chrome/browser/bromite_flag_entries.h
  38. @@ -12,4 +12,8 @@
  39. "Enable Canvas::measureText() fingerprint deception",
  40. "Scale the output values of Canvas::measureText() with a randomly selected factor in the range -0.0003% to 0.0003%, which are recomputed on every document initialization. ungoogled-chromium flag, Bromite feature.",
  41. kOsAll, SINGLE_VALUE_TYPE(switches::kFingerprintingCanvasMeasureTextNoise)},
  42. + {"max-connections-per-host",
  43. + flag_descriptions::kMaxConnectionsPerHostName,
  44. + flag_descriptions::kMaxConnectionsPerHostDescription,
  45. + kOsAll, MULTI_VALUE_TYPE(kMaxConnectionsPerHostChoices)},
  46. #endif // CHROME_BROWSER_BROMITE_FLAG_ENTRIES_H_
  47. --- a/chrome/browser/browser_process_impl.cc
  48. +++ b/chrome/browser/browser_process_impl.cc
  49. @@ -21,12 +21,14 @@
  50. #include "base/functional/callback.h"
  51. #include "base/functional/callback_helpers.h"
  52. #include "base/location.h"
  53. +#include "base/logging.h"
  54. #include "base/memory/ptr_util.h"
  55. #include "base/metrics/histogram_functions.h"
  56. #include "base/metrics/histogram_macros.h"
  57. #include "base/notreached.h"
  58. #include "base/path_service.h"
  59. #include "base/run_loop.h"
  60. +#include "base/strings/string_number_conversions.h"
  61. #include "base/synchronization/waitable_event.h"
  62. #include "base/task/sequenced_task_runner.h"
  63. #include "base/task/single_thread_task_runner.h"
  64. @@ -109,6 +111,7 @@
  65. #include "components/metrics/metrics_service.h"
  66. #include "components/metrics_services_manager/metrics_services_manager.h"
  67. #include "components/metrics_services_manager/metrics_services_manager_client.h"
  68. +#include "components/network_session_configurator/common/network_switches.h"
  69. #include "components/network_time/network_time_tracker.h"
  70. #include "components/os_crypt/async/browser/os_crypt_async.h"
  71. #include "components/permissions/permissions_client.h"
  72. @@ -142,6 +145,7 @@
  73. #include "media/media_buildflags.h"
  74. #include "mojo/public/cpp/bindings/pending_receiver.h"
  75. #include "net/log/net_log.h"
  76. +#include "net/socket/client_socket_pool_manager.h"
  77. #include "ppapi/buildflags/buildflags.h"
  78. #include "printing/buildflags/buildflags.h"
  79. #include "services/network/public/cpp/features.h"
  80. @@ -386,6 +390,18 @@ void BrowserProcessImpl::Init() {
  81. pref_change_registrar_.Add(metrics::prefs::kMetricsReportingEnabled,
  82. base::BindRepeating(&ApplyMetricsReportingPolicy));
  83. + int max_connections_per_host = 0;
  84. + auto switch_value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
  85. + switches::kMaxConnectionsPerHost);
  86. + if (!switch_value.empty() && !base::StringToInt(switch_value, &max_connections_per_host)) {
  87. + LOG(DFATAL) << "--" << switches::kMaxConnectionsPerHost
  88. + << " expected integer; got (\"" << switch_value << "\" instead)";
  89. + }
  90. + if (max_connections_per_host != 0) {
  91. + net::ClientSocketPoolManager::set_max_sockets_per_group(
  92. + net::HttpNetworkSession::NORMAL_SOCKET_POOL, max_connections_per_host);
  93. + }
  94. +
  95. DCHECK(!webrtc_event_log_manager_);
  96. webrtc_event_log_manager_ = WebRtcEventLogManager::CreateSingletonInstance();
  97. --- a/chrome/browser/flag_descriptions.cc
  98. +++ b/chrome/browser/flag_descriptions.cc
  99. @@ -2285,6 +2285,10 @@ const char kLogJsConsoleMessagesDescript
  100. "Enable logging JS console messages in system logs, please note that they "
  101. "may contain PII.";
  102. +const char kMaxConnectionsPerHostName[] = "Maximum connections per host";
  103. +const char kMaxConnectionsPerHostDescription[] =
  104. + "Customize maximum allowed connections per host. ungoogled-chromium flag, Bromite feature.";
  105. +
  106. const char kMediaRouterCastAllowAllIPsName[] =
  107. "Connect to Cast devices on all IP addresses";
  108. const char kMediaRouterCastAllowAllIPsDescription[] =
  109. --- a/chrome/browser/flag_descriptions.h
  110. +++ b/chrome/browser/flag_descriptions.h
  111. @@ -1311,6 +1311,9 @@ extern const char kLocationBarModelOptim
  112. extern const char kLogJsConsoleMessagesName[];
  113. extern const char kLogJsConsoleMessagesDescription[];
  114. +extern const char kMaxConnectionsPerHostName[];
  115. +extern const char kMaxConnectionsPerHostDescription[];
  116. +
  117. extern const char kMediaRouterCastAllowAllIPsName[];
  118. extern const char kMediaRouterCastAllowAllIPsDescription[];
  119. --- a/components/network_session_configurator/common/network_features.cc
  120. +++ b/components/network_session_configurator/common/network_features.cc
  121. @@ -8,4 +8,7 @@
  122. namespace features {
  123. +const char kMaxConnectionsPerHostChoiceDefault[] = "6",
  124. + kMaxConnectionsPerHostChoice15[] = "15";
  125. +
  126. } // namespace features
  127. --- a/components/network_session_configurator/common/network_features.h
  128. +++ b/components/network_session_configurator/common/network_features.h
  129. @@ -10,6 +10,10 @@
  130. namespace features {
  131. +NETWORK_SESSION_CONFIGURATOR_EXPORT extern const char kMaxConnectionsPerHostChoiceDefault[],
  132. + kMaxConnectionsPerHostChoice6[],
  133. + kMaxConnectionsPerHostChoice15[];
  134. +
  135. } // namespace features
  136. #endif // COMPONENTS_NETWORK_SESSION_CONFIGURATOR_COMMON_NETWORK_FEATURES_H_
  137. --- a/components/network_session_configurator/common/network_switch_list.h
  138. +++ b/components/network_session_configurator/common/network_switch_list.h
  139. @@ -19,6 +19,10 @@ NETWORK_SWITCH(kEnableUserAlternateProto
  140. // Enables the QUIC protocol. This is a temporary testing flag.
  141. NETWORK_SWITCH(kEnableQuic, "enable-quic")
  142. +// Allows specifying a higher number of maximum connections per host
  143. +// (15 instead of 6, mirroring the value Mozilla uses).
  144. +NETWORK_SWITCH(kMaxConnectionsPerHost, "max-connections-per-host")
  145. +
  146. // Ignores certificate-related errors.
  147. NETWORK_SWITCH(kIgnoreCertificateErrors, "ignore-certificate-errors")