Files
cromite/build/patches/Add-flag-to-configure-maximum-connections-per-host.patch
2024-03-15 16:24:42 +01:00

127 lines
5.7 KiB
Diff

From: csagan5 <32685696+csagan5@users.noreply.github.com>
Date: Sun, 8 Jul 2018 22:42:04 +0200
Subject: Add flag to configure maximum connections per host
With the introduction of this flag it is possible to increase the maximum
allowed connections per host; this can however be detrimental to devices
with limited CPU/memory resources and it is disabled by default.
License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
.../common/network_features.cc | 3 +++
.../common/network_features.h | 4 ++++
.../common/network_switch_list.h | 4 ++++
.../spoof_checks/top_domains/BUILD.gn | 1 +
...o-configure-maximum-connections-per-host.inc | 17 +++++++++++++++++
net/socket/client_socket_pool_manager.cc | 17 +++++++++++++++++
6 files changed, 46 insertions(+)
create mode 100644 cromite_flags/chrome/browser/about_flags_cc/add-flag-to-configure-maximum-connections-per-host.inc
diff --git a/components/network_session_configurator/common/network_features.cc b/components/network_session_configurator/common/network_features.cc
--- a/components/network_session_configurator/common/network_features.cc
+++ b/components/network_session_configurator/common/network_features.cc
@@ -8,4 +8,7 @@
namespace features {
+const char kMaxConnectionsPerHostChoiceDefault[] = "6",
+ kMaxConnectionsPerHostChoice15[] = "15";
+
} // namespace features
diff --git a/components/network_session_configurator/common/network_features.h b/components/network_session_configurator/common/network_features.h
--- a/components/network_session_configurator/common/network_features.h
+++ b/components/network_session_configurator/common/network_features.h
@@ -10,6 +10,10 @@
namespace features {
+NETWORK_SESSION_CONFIGURATOR_EXPORT extern const char kMaxConnectionsPerHostChoiceDefault[],
+ kMaxConnectionsPerHostChoice6[],
+ kMaxConnectionsPerHostChoice15[];
+
} // namespace features
#endif // COMPONENTS_NETWORK_SESSION_CONFIGURATOR_COMMON_NETWORK_FEATURES_H_
diff --git a/components/network_session_configurator/common/network_switch_list.h b/components/network_session_configurator/common/network_switch_list.h
--- a/components/network_session_configurator/common/network_switch_list.h
+++ b/components/network_session_configurator/common/network_switch_list.h
@@ -19,6 +19,10 @@ NETWORK_SWITCH(kEnableUserAlternateProtocolPorts,
// Enables the QUIC protocol. This is a temporary testing flag.
NETWORK_SWITCH(kEnableQuic, "enable-quic")
+// Allows specifying a higher number of maximum connections per host
+// (15 instead of 6, mirroring the value Mozilla uses).
+NETWORK_SWITCH(kMaxConnectionsPerHost, "max-connections-per-host")
+
// Ignores certificate-related errors.
NETWORK_SWITCH(kIgnoreCertificateErrors, "ignore-certificate-errors")
diff --git a/components/url_formatter/spoof_checks/top_domains/BUILD.gn b/components/url_formatter/spoof_checks/top_domains/BUILD.gn
--- a/components/url_formatter/spoof_checks/top_domains/BUILD.gn
+++ b/components/url_formatter/spoof_checks/top_domains/BUILD.gn
@@ -89,6 +89,7 @@ executable("make_top_domain_list_variables") {
"//base:i18n",
"//components/url_formatter/spoof_checks/common_words:common",
"//third_party/icu",
+ "//components/network_session_configurator/common"
]
if (is_ios) {
frameworks = [ "UIKit.framework" ]
diff --git a/cromite_flags/chrome/browser/about_flags_cc/add-flag-to-configure-maximum-connections-per-host.inc b/cromite_flags/chrome/browser/about_flags_cc/add-flag-to-configure-maximum-connections-per-host.inc
new file mode 100644
--- /dev/null
+++ b/cromite_flags/chrome/browser/about_flags_cc/add-flag-to-configure-maximum-connections-per-host.inc
@@ -0,0 +1,17 @@
+#ifdef FEATURE_PARAM_SECTION
+
+const FeatureEntry::Choice kMaxConnectionsPerHostChoices[] = {
+ {features::kMaxConnectionsPerHostChoiceDefault, "", ""},
+ {features::kMaxConnectionsPerHostChoice15, switches::kMaxConnectionsPerHost, "15"},
+};
+
+#endif
+
+#ifdef FLAG_SECTION
+
+ {"max-connections-per-host",
+ "Maximum connections per host",
+ "Customize maximum allowed connections per host.", kOsAll,
+ MULTI_VALUE_TYPE(kMaxConnectionsPerHostChoices)},
+
+#endif
diff --git a/net/socket/client_socket_pool_manager.cc b/net/socket/client_socket_pool_manager.cc
--- a/net/socket/client_socket_pool_manager.cc
+++ b/net/socket/client_socket_pool_manager.cc
@@ -22,6 +22,10 @@
#include "net/socket/client_socket_handle.h"
#include "net/socket/client_socket_pool.h"
#include "net/socket/connect_job.h"
+#include "components/network_session_configurator/common/network_switches.h"
+
+#include "base/command_line.h"
+#include "base/strings/string_number_conversions.h"
#include "net/ssl/ssl_config.h"
#include "url/gurl.h"
#include "url/scheme_host_port.h"
@@ -168,6 +172,19 @@ void ClientSocketPoolManager::set_max_sockets_per_pool(
int ClientSocketPoolManager::max_sockets_per_group(
HttpNetworkSession::SocketPoolType pool_type) {
DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES);
+
+ if (pool_type == HttpNetworkSession::NORMAL_SOCKET_POOL) {
+ int maxConnectionsPerHost = 0;
+ auto value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kMaxConnectionsPerHost);
+ if (!value.empty() && !base::StringToInt(value, &maxConnectionsPerHost)) {
+ LOG(DFATAL) << "--" << switches::kMaxConnectionsPerHost << " only accepts integers as arguments (\"" << value << "\" is invalid)";
+ }
+ if (maxConnectionsPerHost != 0) {
+ return maxConnectionsPerHost;
+ }
+ // fallthrough for default value
+ }
+
return g_max_sockets_per_group[pool_type];
}
--