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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. @@ -2134,6 +2134,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. @@ -19,10 +19,12 @@
  50. #include "base/debug/leak_annotations.h"
  51. #include "base/files/file_path.h"
  52. #include "base/location.h"
  53. +#include "base/logging.h"
  54. #include "base/memory/ptr_util.h"
  55. #include "base/metrics/histogram_macros.h"
  56. #include "base/path_service.h"
  57. #include "base/run_loop.h"
  58. +#include "base/strings/string_number_conversions.h"
  59. #include "base/synchronization/waitable_event.h"
  60. #include "base/task/single_thread_task_runner.h"
  61. #include "base/task/task_traits.h"
  62. @@ -103,6 +105,7 @@
  63. #include "components/metrics/metrics_service.h"
  64. #include "components/metrics_services_manager/metrics_services_manager.h"
  65. #include "components/metrics_services_manager/metrics_services_manager_client.h"
  66. +#include "components/network_session_configurator/common/network_switches.h"
  67. #include "components/network_time/network_time_tracker.h"
  68. #include "components/permissions/permissions_client.h"
  69. #include "components/policy/core/common/policy_service.h"
  70. @@ -135,6 +138,7 @@
  71. #include "media/media_buildflags.h"
  72. #include "mojo/public/cpp/bindings/pending_receiver.h"
  73. #include "net/log/net_log.h"
  74. +#include "net/socket/client_socket_pool_manager.h"
  75. #include "ppapi/buildflags/buildflags.h"
  76. #include "printing/buildflags/buildflags.h"
  77. #include "services/network/public/cpp/features.h"
  78. @@ -345,6 +349,18 @@ void BrowserProcessImpl::Init() {
  79. base::BindRepeating(&ApplyMetricsReportingPolicy));
  80. #endif
  81. + int max_connections_per_host = 0;
  82. + auto switch_value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
  83. + switches::kMaxConnectionsPerHost);
  84. + if (!switch_value.empty() && !base::StringToInt(switch_value, &max_connections_per_host)) {
  85. + LOG(DFATAL) << "--" << switches::kMaxConnectionsPerHost
  86. + << " expected integer; got (\"" << switch_value << "\" instead)";
  87. + }
  88. + if (max_connections_per_host != 0) {
  89. + net::ClientSocketPoolManager::set_max_sockets_per_group(
  90. + net::HttpNetworkSession::NORMAL_SOCKET_POOL, max_connections_per_host);
  91. + }
  92. +
  93. DCHECK(!webrtc_event_log_manager_);
  94. webrtc_event_log_manager_ = WebRtcEventLogManager::CreateSingletonInstance();
  95. --- a/chrome/browser/flag_descriptions.cc
  96. +++ b/chrome/browser/flag_descriptions.cc
  97. @@ -1583,6 +1583,10 @@ const char kLogJsConsoleMessagesDescript
  98. "Enable logging JS console messages in system logs, please note that they "
  99. "may contain PII.";
  100. +const char kMaxConnectionsPerHostName[] = "Maximum connections per host";
  101. +const char kMaxConnectionsPerHostDescription[] =
  102. + "Customize maximum allowed connections per host. ungoogled-chromium flag, Bromite feature.";
  103. +
  104. const char kMediaRouterCastAllowAllIPsName[] =
  105. "Connect to Cast devices on all IP addresses";
  106. const char kMediaRouterCastAllowAllIPsDescription[] =
  107. --- a/chrome/browser/flag_descriptions.h
  108. +++ b/chrome/browser/flag_descriptions.h
  109. @@ -916,6 +916,9 @@ extern const char kLensCameraAssistedSea
  110. extern const char kLogJsConsoleMessagesName[];
  111. extern const char kLogJsConsoleMessagesDescription[];
  112. +extern const char kMaxConnectionsPerHostName[];
  113. +extern const char kMaxConnectionsPerHostDescription[];
  114. +
  115. extern const char kMediaRouterCastAllowAllIPsName[];
  116. extern const char kMediaRouterCastAllowAllIPsDescription[];
  117. --- a/components/network_session_configurator/common/network_features.cc
  118. +++ b/components/network_session_configurator/common/network_features.cc
  119. @@ -8,4 +8,7 @@
  120. namespace features {
  121. +const char kMaxConnectionsPerHostChoiceDefault[] = "6",
  122. + kMaxConnectionsPerHostChoice15[] = "15";
  123. +
  124. } // namespace features
  125. --- a/components/network_session_configurator/common/network_features.h
  126. +++ b/components/network_session_configurator/common/network_features.h
  127. @@ -10,6 +10,10 @@
  128. namespace features {
  129. +NETWORK_SESSION_CONFIGURATOR_EXPORT extern const char kMaxConnectionsPerHostChoiceDefault[],
  130. + kMaxConnectionsPerHostChoice6[],
  131. + kMaxConnectionsPerHostChoice15[];
  132. +
  133. } // namespace features
  134. #endif // COMPONENTS_NETWORK_SESSION_CONFIGURATOR_COMMON_NETWORK_FEATURES_H_
  135. --- a/components/network_session_configurator/common/network_switch_list.h
  136. +++ b/components/network_session_configurator/common/network_switch_list.h
  137. @@ -19,6 +19,10 @@ NETWORK_SWITCH(kEnableUserAlternateProto
  138. // Enables the QUIC protocol. This is a temporary testing flag.
  139. NETWORK_SWITCH(kEnableQuic, "enable-quic")
  140. +// Allows specifying a higher number of maximum connections per host
  141. +// (15 instead of 6, mirroring the value Mozilla uses).
  142. +NETWORK_SWITCH(kMaxConnectionsPerHost, "max-connections-per-host")
  143. +
  144. // Ignores certificate-related errors.
  145. NETWORK_SWITCH(kIgnoreCertificateErrors, "ignore-certificate-errors")