Add-flag-to-configure-maximum-connections-per-host.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. .../spoof_checks/top_domains/BUILD.gn | 1 +
  15. net/socket/client_socket_pool_manager.cc | 17 +++++++++++++++++
  16. 8 files changed, 44 insertions(+)
  17. diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
  18. --- a/chrome/browser/about_flags.cc
  19. +++ b/chrome/browser/about_flags.cc
  20. @@ -849,6 +849,11 @@ const FeatureEntry::Choice kForceEffectiveConnectionTypeChoices[] = {
  21. net::kEffectiveConnectionType4G},
  22. };
  23. +const FeatureEntry::Choice kMaxConnectionsPerHostChoices[] = {
  24. + {features::kMaxConnectionsPerHostChoiceDefault, "", ""},
  25. + {features::kMaxConnectionsPerHostChoice15, switches::kMaxConnectionsPerHost, "15"},
  26. +};
  27. +
  28. // Ensure that all effective connection types returned by Network Quality
  29. // Estimator (NQE) are also exposed via flags.
  30. static_assert(net::EFFECTIVE_CONNECTION_TYPE_LAST + 2 ==
  31. @@ -3918,6 +3923,9 @@ const FeatureEntry kFeatureEntries[] = {
  32. flag_descriptions::kAndroidPictureInPictureAPIName,
  33. flag_descriptions::kAndroidPictureInPictureAPIDescription, kOsAndroid,
  34. FEATURE_VALUE_TYPE(media::kPictureInPictureAPI)},
  35. + {"max-connections-per-host", flag_descriptions::kMaxConnectionsPerHostName,
  36. + flag_descriptions::kMaxConnectionsPerHostDescription, kOsAll,
  37. + MULTI_VALUE_TYPE(kMaxConnectionsPerHostChoices)},
  38. {"reengagement-notification",
  39. flag_descriptions::kReengagementNotificationName,
  40. flag_descriptions::kReengagementNotificationDescription, kOsAndroid,
  41. diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
  42. --- a/chrome/browser/flag_descriptions.cc
  43. +++ b/chrome/browser/flag_descriptions.cc
  44. @@ -1626,6 +1626,10 @@ const char kMediaHistoryDescription[] =
  45. "Enables Media History which records data around media playbacks on "
  46. "websites.";
  47. +const char kMaxConnectionsPerHostName[] = "Maximum connections per host";
  48. +const char kMaxConnectionsPerHostDescription[] =
  49. + "Customize maximum allowed connections per host.";
  50. +
  51. const char kMediaRouterCastAllowAllIPsName[] =
  52. "Connect to Cast devices on all IP addresses";
  53. const char kMediaRouterCastAllowAllIPsDescription[] =
  54. diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
  55. --- a/chrome/browser/flag_descriptions.h
  56. +++ b/chrome/browser/flag_descriptions.h
  57. @@ -933,6 +933,9 @@ extern const char kLogJsConsoleMessagesDescription[];
  58. extern const char kMediaHistoryName[];
  59. extern const char kMediaHistoryDescription[];
  60. +extern const char kMaxConnectionsPerHostName[];
  61. +extern const char kMaxConnectionsPerHostDescription[];
  62. +
  63. extern const char kMediaRouterCastAllowAllIPsName[];
  64. extern const char kMediaRouterCastAllowAllIPsDescription[];
  65. diff --git a/components/network_session_configurator/common/network_features.cc b/components/network_session_configurator/common/network_features.cc
  66. --- a/components/network_session_configurator/common/network_features.cc
  67. +++ b/components/network_session_configurator/common/network_features.cc
  68. @@ -8,4 +8,7 @@
  69. namespace features {
  70. +const char kMaxConnectionsPerHostChoiceDefault[] = "6",
  71. + kMaxConnectionsPerHostChoice15[] = "15";
  72. +
  73. } // namespace features
  74. diff --git a/components/network_session_configurator/common/network_features.h b/components/network_session_configurator/common/network_features.h
  75. --- a/components/network_session_configurator/common/network_features.h
  76. +++ b/components/network_session_configurator/common/network_features.h
  77. @@ -10,6 +10,10 @@
  78. namespace features {
  79. +NETWORK_SESSION_CONFIGURATOR_EXPORT extern const char kMaxConnectionsPerHostChoiceDefault[],
  80. + kMaxConnectionsPerHostChoice6[],
  81. + kMaxConnectionsPerHostChoice15[];
  82. +
  83. } // namespace features
  84. #endif // COMPONENTS_NETWORK_SESSION_CONFIGURATOR_COMMON_NETWORK_FEATURES_H_
  85. diff --git a/components/network_session_configurator/common/network_switch_list.h b/components/network_session_configurator/common/network_switch_list.h
  86. --- a/components/network_session_configurator/common/network_switch_list.h
  87. +++ b/components/network_session_configurator/common/network_switch_list.h
  88. @@ -19,6 +19,10 @@ NETWORK_SWITCH(kEnableUserAlternateProtocolPorts,
  89. // Enables the QUIC protocol. This is a temporary testing flag.
  90. NETWORK_SWITCH(kEnableQuic, "enable-quic")
  91. +// Allows specifying a higher number of maximum connections per host
  92. +// (15 instead of 6, mirroring the value Mozilla uses).
  93. +NETWORK_SWITCH(kMaxConnectionsPerHost, "max-connections-per-host")
  94. +
  95. // Ignores certificate-related errors.
  96. NETWORK_SWITCH(kIgnoreCertificateErrors, "ignore-certificate-errors")
  97. diff --git a/components/url_formatter/spoof_checks/top_domains/BUILD.gn b/components/url_formatter/spoof_checks/top_domains/BUILD.gn
  98. --- a/components/url_formatter/spoof_checks/top_domains/BUILD.gn
  99. +++ b/components/url_formatter/spoof_checks/top_domains/BUILD.gn
  100. @@ -73,6 +73,7 @@ executable("make_top_domain_list_variables") {
  101. "//base:i18n",
  102. "//components/url_formatter/spoof_checks/common_words:common",
  103. "//third_party/icu",
  104. + "//components/network_session_configurator/common"
  105. ]
  106. if (is_ios) {
  107. frameworks = [ "UIKit.framework" ]
  108. diff --git a/net/socket/client_socket_pool_manager.cc b/net/socket/client_socket_pool_manager.cc
  109. --- a/net/socket/client_socket_pool_manager.cc
  110. +++ b/net/socket/client_socket_pool_manager.cc
  111. @@ -20,6 +20,10 @@
  112. #include "net/socket/client_socket_handle.h"
  113. #include "net/socket/client_socket_pool.h"
  114. #include "net/socket/connect_job.h"
  115. +#include "components/network_session_configurator/common/network_switches.h"
  116. +
  117. +#include "base/command_line.h"
  118. +#include "base/strings/string_number_conversions.h"
  119. #include "net/ssl/ssl_config.h"
  120. #include "third_party/abseil-cpp/absl/types/optional.h"
  121. #include "url/gurl.h"
  122. @@ -173,6 +177,19 @@ void ClientSocketPoolManager::set_max_sockets_per_pool(
  123. int ClientSocketPoolManager::max_sockets_per_group(
  124. HttpNetworkSession::SocketPoolType pool_type) {
  125. DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES);
  126. +
  127. + if (pool_type == HttpNetworkSession::NORMAL_SOCKET_POOL) {
  128. + int maxConnectionsPerHost = 0;
  129. + auto value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kMaxConnectionsPerHost);
  130. + if (!value.empty() && !base::StringToInt(value, &maxConnectionsPerHost)) {
  131. + LOG(DFATAL) << "--" << switches::kMaxConnectionsPerHost << " only accepts integers as arguments (\"" << value << "\" is invalid)";
  132. + }
  133. + if (maxConnectionsPerHost != 0) {
  134. + return maxConnectionsPerHost;
  135. + }
  136. + // fallthrough for default value
  137. + }
  138. +
  139. return g_max_sockets_per_group[pool_type];
  140. }
  141. --
  142. 2.20.1