blob: c7e77f8a94975e8183e643618cb7a09cc58ddca0 [file] [log] [blame]
[email protected]d2e6d592012-02-03 21:49:041// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]861c6c62009-04-20 16:50:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Lily Houghton582d4622018-01-22 22:43:405#include "net/proxy_resolution/proxy_config_service_linux.h"
[email protected]861c6c62009-04-20 16:50:566
[email protected]d7395e732009-08-28 23:13:437#include <errno.h>
[email protected]d7395e732009-08-28 23:13:438#include <limits.h>
[email protected]d7395e732009-08-28 23:13:439#include <sys/inotify.h>
10#include <unistd.h>
[email protected]861c6c62009-04-20 16:50:5611
[email protected]9bc8cff2010-04-03 01:05:3912#include <map>
Peter Boström08e7ed82021-04-19 17:49:5913#include <memory>
thestig0c412e852016-06-30 08:04:4014#include <utility>
[email protected]9bc8cff2010-04-03 01:05:3915
[email protected]6af889c2011-10-06 23:11:4116#include "base/bind.h"
gabf4f904e2017-05-10 20:55:0217#include "base/files/file_descriptor_watcher_posix.h"
[email protected]57999812013-02-24 05:40:5218#include "base/files/file_path.h"
thestigd8df0332014-09-04 06:33:2919#include "base/files/file_util.h"
[email protected]b9b4a572014-03-17 23:11:1220#include "base/files/scoped_file.h"
[email protected]861c6c62009-04-20 16:50:5621#include "base/logging.h"
Eric Romancd032fb62018-05-18 21:40:1322#include "base/memory/ptr_util.h"
Keishi Hattorif28f4f82022-06-21 11:32:1523#include "base/memory/raw_ptr.h"
[email protected]3a29593d2011-04-11 10:07:5224#include "base/nix/xdg_util.h"
David Sandersde5fee542022-03-23 02:47:4425#include "base/observer_list.h"
[email protected]fc9be5802013-06-11 10:56:5126#include "base/strings/string_number_conversions.h"
Slava Aseev9ffd8a62022-05-25 07:09:0927#include "base/strings/string_split.h"
[email protected]f4ebe772013-02-02 00:21:3928#include "base/strings/string_tokenizer.h"
[email protected]66e96c42013-06-28 15:20:3129#include "base/strings/string_util.h"
Patrick Monette643cdf62021-10-15 19:13:4230#include "base/task/sequenced_task_runner.h"
31#include "base/task/single_thread_task_runner.h"
Gabriel Charette44db1422018-08-06 11:19:3332#include "base/task/task_traits.h"
Gabriel Charette99f5df32021-03-19 19:55:5533#include "base/task/thread_pool.h"
[email protected]9a8c4022011-01-25 14:25:3334#include "base/threading/thread_restrictions.h"
[email protected]66e96c42013-06-28 15:20:3135#include "base/timer/timer.h"
Lily Houghton582d4622018-01-22 22:43:4036#include "net/base/proxy_server.h"
Eric Orth5ccc3f02021-09-23 00:01:5737#include "net/base/proxy_string_util.h"
[email protected]861c6c62009-04-20 16:50:5638
[email protected]3fc24f52012-11-30 21:22:3439#if defined(USE_GIO)
Tim Brown1c307cc2017-12-08 02:40:3840#include <gio/gio.h>
[email protected]3fc24f52012-11-30 21:22:3441#endif // defined(USE_GIO)
42
[email protected]861c6c62009-04-20 16:50:5643namespace net {
44
45namespace {
46
Shimi Zhang13eace252020-01-31 01:49:1947// This turns all rules with a hostname into wildcard matches, which will
48// match not just the indicated hostname but also any hostname that ends with
49// it.
50void RewriteRulesForSuffixMatching(ProxyBypassRules* out) {
51 // Prepend a wildcard (*) to any hostname based rules, provided it isn't an IP
52 // address.
53 for (size_t i = 0; i < out->rules().size(); ++i) {
54 if (!out->rules()[i]->IsHostnamePatternRule())
55 continue;
56
57 const SchemeHostPortMatcherHostnamePatternRule* prev_rule =
58 static_cast<const SchemeHostPortMatcherHostnamePatternRule*>(
59 out->rules()[i].get());
60 out->ReplaceRule(i, prev_rule->GenerateSuffixMatchingRule());
61 }
62}
63
[email protected]861c6c62009-04-20 16:50:5664// Given a proxy hostname from a setting, returns that hostname with
65// an appropriate proxy server scheme prefix.
66// scheme indicates the desired proxy scheme: usually http, with
67// socks 4 or 5 as special cases.
[email protected]87a102b2009-07-14 05:23:3068// TODO(arindam): Remove URI string manipulation by using MapUrlSchemeToProxy.
[email protected]861c6c62009-04-20 16:50:5669std::string FixupProxyHostScheme(ProxyServer::Scheme scheme,
70 std::string host) {
[email protected]e8c50812010-09-28 00:16:1771 if (scheme == ProxyServer::SCHEME_SOCKS5 &&
brettw3a2c6902015-07-06 19:43:2972 base::StartsWith(host, "socks4://",
73 base::CompareCase::INSENSITIVE_ASCII)) {
[email protected]e8c50812010-09-28 00:16:1774 // We default to socks 5, but if the user specifically set it to
75 // socks4://, then use that.
76 scheme = ProxyServer::SCHEME_SOCKS4;
[email protected]861c6c62009-04-20 16:50:5677 }
78 // Strip the scheme if any.
79 std::string::size_type colon = host.find("://");
80 if (colon != std::string::npos)
81 host = host.substr(colon + 3);
82 // If a username and perhaps password are specified, give a warning.
83 std::string::size_type at_sign = host.find("@");
84 // Should this be supported?
85 if (at_sign != std::string::npos) {
[email protected]62749f182009-07-15 13:16:5486 // ProxyConfig does not support authentication parameters, but Chrome
87 // will prompt for the password later. Disregard the
88 // authentication parameters and continue with this hostname.
89 LOG(WARNING) << "Proxy authentication parameters ignored, see bug 16709";
[email protected]861c6c62009-04-20 16:50:5690 host = host.substr(at_sign + 1);
91 }
92 // If this is a socks proxy, prepend a scheme so as to tell
93 // ProxyServer. This also allows ProxyServer to choose the right
94 // default port.
95 if (scheme == ProxyServer::SCHEME_SOCKS4)
96 host = "socks4://" + host;
97 else if (scheme == ProxyServer::SCHEME_SOCKS5)
98 host = "socks5://" + host;
[email protected]d7395e732009-08-28 23:13:4399 // If there is a trailing slash, remove it so |host| will parse correctly
100 // even if it includes a port number (since the slash is not numeric).
pkasting9022cb42016-02-05 00:08:56101 if (!host.empty() && host.back() == '/')
[email protected]d7395e732009-08-28 23:13:43102 host.resize(host.length() - 1);
[email protected]861c6c62009-04-20 16:50:56103 return host;
104}
105
Ramin Halavatica8d5252018-03-12 05:33:49106ProxyConfigWithAnnotation GetConfigOrDirect(
Anton Bikineev068d2912021-05-15 20:43:52107 const absl::optional<ProxyConfigWithAnnotation>& optional_config) {
Eric Roman750af4b12018-02-22 22:38:53108 if (optional_config)
109 return optional_config.value();
110
Ramin Halavatica8d5252018-03-12 05:33:49111 ProxyConfigWithAnnotation config = ProxyConfigWithAnnotation::CreateDirect();
Eric Roman750af4b12018-02-22 22:38:53112 return config;
113}
114
[email protected]861c6c62009-04-20 16:50:56115} // namespace
116
Chris Watkins3a13f632017-12-04 00:41:15117ProxyConfigServiceLinux::Delegate::~Delegate() = default;
[email protected]8e1845e12010-09-15 19:22:24118
[email protected]3e44697f2009-05-22 14:37:39119bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme(
thestig0c412e852016-06-30 08:04:40120 base::StringPiece variable,
121 ProxyServer::Scheme scheme,
[email protected]861c6c62009-04-20 16:50:56122 ProxyServer* result_server) {
123 std::string env_value;
thestig0c412e852016-06-30 08:04:40124 if (!env_var_getter_->GetVar(variable, &env_value))
125 return false;
126
127 if (env_value.empty())
128 return false;
129
130 env_value = FixupProxyHostScheme(scheme, env_value);
131 ProxyServer proxy_server =
Eric Orth5ccc3f02021-09-23 00:01:57132 ProxyUriToProxyServer(env_value, ProxyServer::SCHEME_HTTP);
thestig0c412e852016-06-30 08:04:40133 if (proxy_server.is_valid() && !proxy_server.is_direct()) {
134 *result_server = proxy_server;
135 return true;
[email protected]861c6c62009-04-20 16:50:56136 }
thestig0c412e852016-06-30 08:04:40137 LOG(ERROR) << "Failed to parse environment variable " << variable;
[email protected]861c6c62009-04-20 16:50:56138 return false;
139}
140
[email protected]3e44697f2009-05-22 14:37:39141bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVar(
thestig0c412e852016-06-30 08:04:40142 base::StringPiece variable,
143 ProxyServer* result_server) {
[email protected]861c6c62009-04-20 16:50:56144 return GetProxyFromEnvVarForScheme(variable, ProxyServer::SCHEME_HTTP,
145 result_server);
146}
147
Anton Bikineev068d2912021-05-15 20:43:52148absl::optional<ProxyConfigWithAnnotation>
Eric Roman750af4b12018-02-22 22:38:53149ProxyConfigServiceLinux::Delegate::GetConfigFromEnv() {
Ramin Halavatica8d5252018-03-12 05:33:49150 ProxyConfig config;
Eric Roman750af4b12018-02-22 22:38:53151
[email protected]861c6c62009-04-20 16:50:56152 // Check for automatic configuration first, in
153 // "auto_proxy". Possibly only the "environment_proxy" firefox
154 // extension has ever used this, but it still sounds like a good
155 // idea.
156 std::string auto_proxy;
[email protected]3ba7e082010-08-07 02:57:59157 if (env_var_getter_->GetVar("auto_proxy", &auto_proxy)) {
[email protected]861c6c62009-04-20 16:50:56158 if (auto_proxy.empty()) {
159 // Defined and empty => autodetect
Ramin Halavatica8d5252018-03-12 05:33:49160 config.set_auto_detect(true);
[email protected]861c6c62009-04-20 16:50:56161 } else {
162 // specified autoconfig URL
Ramin Halavatica8d5252018-03-12 05:33:49163 config.set_pac_url(GURL(auto_proxy));
[email protected]861c6c62009-04-20 16:50:56164 }
Ramin Halavatica8d5252018-03-12 05:33:49165 return ProxyConfigWithAnnotation(
166 config, NetworkTrafficAnnotationTag(traffic_annotation_));
[email protected]861c6c62009-04-20 16:50:56167 }
168 // "all_proxy" is a shortcut to avoid defining {http,https,ftp}_proxy.
169 ProxyServer proxy_server;
170 if (GetProxyFromEnvVar("all_proxy", &proxy_server)) {
Ramin Halavatica8d5252018-03-12 05:33:49171 config.proxy_rules().type = ProxyConfig::ProxyRules::Type::PROXY_LIST;
172 config.proxy_rules().single_proxies.SetSingleProxyServer(proxy_server);
[email protected]861c6c62009-04-20 16:50:56173 } else {
174 bool have_http = GetProxyFromEnvVar("http_proxy", &proxy_server);
175 if (have_http)
Ramin Halavatica8d5252018-03-12 05:33:49176 config.proxy_rules().proxies_for_http.SetSingleProxyServer(proxy_server);
[email protected]861c6c62009-04-20 16:50:56177 // It would be tempting to let http_proxy apply for all protocols
178 // if https_proxy and ftp_proxy are not defined. Googling turns up
179 // several documents that mention only http_proxy. But then the
180 // user really might not want to proxy https. And it doesn't seem
181 // like other apps do this. So we will refrain.
182 bool have_https = GetProxyFromEnvVar("https_proxy", &proxy_server);
183 if (have_https)
Ramin Halavatica8d5252018-03-12 05:33:49184 config.proxy_rules().proxies_for_https.SetSingleProxyServer(proxy_server);
[email protected]861c6c62009-04-20 16:50:56185 bool have_ftp = GetProxyFromEnvVar("ftp_proxy", &proxy_server);
186 if (have_ftp)
Ramin Halavatica8d5252018-03-12 05:33:49187 config.proxy_rules().proxies_for_ftp.SetSingleProxyServer(proxy_server);
[email protected]861c6c62009-04-20 16:50:56188 if (have_http || have_https || have_ftp) {
189 // mustn't change type unless some rules are actually set.
Ramin Halavatica8d5252018-03-12 05:33:49190 config.proxy_rules().type =
Lily Houghtone6b617e2018-01-19 20:13:07191 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME;
[email protected]861c6c62009-04-20 16:50:56192 }
193 }
Ramin Halavatica8d5252018-03-12 05:33:49194 if (config.proxy_rules().empty()) {
[email protected]861c6c62009-04-20 16:50:56195 // If the above were not defined, try for socks.
[email protected]e8c50812010-09-28 00:16:17196 // For environment variables, we default to version 5, per the gnome
197 // documentation: http://library.gnome.org/devel/gnet/stable/gnet-socks.html
198 ProxyServer::Scheme scheme = ProxyServer::SCHEME_SOCKS5;
[email protected]861c6c62009-04-20 16:50:56199 std::string env_version;
[email protected]3ba7e082010-08-07 02:57:59200 if (env_var_getter_->GetVar("SOCKS_VERSION", &env_version)
[email protected]e8c50812010-09-28 00:16:17201 && env_version == "4")
202 scheme = ProxyServer::SCHEME_SOCKS4;
[email protected]861c6c62009-04-20 16:50:56203 if (GetProxyFromEnvVarForScheme("SOCKS_SERVER", scheme, &proxy_server)) {
Ramin Halavatica8d5252018-03-12 05:33:49204 config.proxy_rules().type = ProxyConfig::ProxyRules::Type::PROXY_LIST;
205 config.proxy_rules().single_proxies.SetSingleProxyServer(proxy_server);
[email protected]861c6c62009-04-20 16:50:56206 }
207 }
208 // Look for the proxy bypass list.
209 std::string no_proxy;
[email protected]3ba7e082010-08-07 02:57:59210 env_var_getter_->GetVar("no_proxy", &no_proxy);
Ramin Halavatica8d5252018-03-12 05:33:49211 if (config.proxy_rules().empty()) {
[email protected]861c6c62009-04-20 16:50:56212 // Having only "no_proxy" set, presumably to "*", makes it
213 // explicit that env vars do specify a configuration: having no
214 // rules specified only means the user explicitly asks for direct
215 // connections.
Ramin Halavatica8d5252018-03-12 05:33:49216 return !no_proxy.empty()
217 ? ProxyConfigWithAnnotation(
218 config, NetworkTrafficAnnotationTag(traffic_annotation_))
Anton Bikineev068d2912021-05-15 20:43:52219 : absl::optional<ProxyConfigWithAnnotation>();
[email protected]861c6c62009-04-20 16:50:56220 }
[email protected]7541206c2010-02-19 20:24:06221 // Note that this uses "suffix" matching. So a bypass of "google.com"
222 // is understood to mean a bypass of "*google.com".
Shimi Zhang13eace252020-01-31 01:49:19223 config.proxy_rules().bypass_rules.ParseFromString(no_proxy);
224 RewriteRulesForSuffixMatching(&config.proxy_rules().bypass_rules);
225
Ramin Halavatica8d5252018-03-12 05:33:49226 return ProxyConfigWithAnnotation(
227 config, NetworkTrafficAnnotationTag(traffic_annotation_));
[email protected]861c6c62009-04-20 16:50:56228}
229
230namespace {
231
[email protected]d7395e732009-08-28 23:13:43232const int kDebounceTimeoutMilliseconds = 250;
[email protected]3e44697f2009-05-22 14:37:39233
[email protected]8c20e3d2011-05-19 21:03:57234#if defined(USE_GIO)
Tim Brown1c307cc2017-12-08 02:40:38235const char kProxyGSettingsSchema[] = "org.gnome.system.proxy";
[email protected]2297bb22014-06-19 06:30:14236
[email protected]8c20e3d2011-05-19 21:03:57237// This setting getter uses gsettings, as used in most GNOME 3 desktops.
238class SettingGetterImplGSettings
239 : public ProxyConfigServiceLinux::SettingGetter {
240 public:
Tsuyoshi Horof8861cb2022-07-05 23:50:20241 SettingGetterImplGSettings()
242 : debounce_timer_(std::make_unique<base::OneShotTimer>()) {}
[email protected]8c20e3d2011-05-19 21:03:57243
Peter Boström293b1342021-09-22 17:31:43244 SettingGetterImplGSettings(const SettingGetterImplGSettings&) = delete;
245 SettingGetterImplGSettings& operator=(const SettingGetterImplGSettings&) =
246 delete;
247
dcheng67be2b1f2014-10-27 21:47:29248 ~SettingGetterImplGSettings() override {
[email protected]8c20e3d2011-05-19 21:03:57249 // client_ should have been released before now, from
250 // Delegate::OnDestroy(), while running on the UI thread. However
251 // on exiting the process, it may happen that
252 // Delegate::OnDestroy() task is left pending on the glib loop
253 // after the loop was quit, and pending tasks may then be deleted
254 // without being run.
255 if (client_) {
Tim Brown2a19f3b2017-12-12 01:08:40256 // gsettings client was not cleaned up.
eroman0070d412017-06-22 22:18:24257 if (task_runner_->RunsTasksInCurrentSequence()) {
Mostyn Bramley-Moore699c5312018-05-01 10:48:09258 // We are on the UI thread so we can clean it safely.
[email protected]8c20e3d2011-05-19 21:03:57259 VLOG(1) << "~SettingGetterImplGSettings: releasing gsettings client";
260 ShutDown();
261 } else {
262 LOG(WARNING) << "~SettingGetterImplGSettings: leaking gsettings client";
thestig0c412e852016-06-30 08:04:40263 client_ = nullptr;
[email protected]8c20e3d2011-05-19 21:03:57264 }
265 }
266 DCHECK(!client_);
[email protected]8c20e3d2011-05-19 21:03:57267 }
268
Tim Brown1c307cc2017-12-08 02:40:38269 // CheckVersion() must be called *before* Init()!
270 bool CheckVersion(base::Environment* env);
[email protected]8c20e3d2011-05-19 21:03:57271
eroman0070d412017-06-22 22:18:24272 bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner)
mostynbba063d6032014-10-09 11:01:13273 override {
eroman0070d412017-06-22 22:18:24274 DCHECK(glib_task_runner->RunsTasksInCurrentSequence());
[email protected]8c20e3d2011-05-19 21:03:57275 DCHECK(!client_);
[email protected]90499482013-06-01 00:39:50276 DCHECK(!task_runner_.get());
[email protected]4cf80f0b2011-05-20 20:30:26277
Tim Brown1c307cc2017-12-08 02:40:38278 if (!g_settings_schema_source_lookup(g_settings_schema_source_get_default(),
279 kProxyGSettingsSchema, FALSE) ||
280 !(client_ = g_settings_new(kProxyGSettingsSchema))) {
[email protected]8c20e3d2011-05-19 21:03:57281 // It's not clear whether/when this can return NULL.
282 LOG(ERROR) << "Unable to create a gsettings client";
283 return false;
284 }
sergeyu3f923062014-09-05 01:39:40285 task_runner_ = glib_task_runner;
[email protected]8c20e3d2011-05-19 21:03:57286 // We assume these all work if the above call worked.
Tim Brown1c307cc2017-12-08 02:40:38287 http_client_ = g_settings_get_child(client_, "http");
288 https_client_ = g_settings_get_child(client_, "https");
289 ftp_client_ = g_settings_get_child(client_, "ftp");
290 socks_client_ = g_settings_get_child(client_, "socks");
[email protected]8c20e3d2011-05-19 21:03:57291 DCHECK(http_client_ && https_client_ && ftp_client_ && socks_client_);
292 return true;
293 }
294
dcheng67be2b1f2014-10-27 21:47:29295 void ShutDown() override {
[email protected]8c20e3d2011-05-19 21:03:57296 if (client_) {
eroman0070d412017-06-22 22:18:24297 DCHECK(task_runner_->RunsTasksInCurrentSequence());
[email protected]8c20e3d2011-05-19 21:03:57298 // This also disables gsettings notifications.
299 g_object_unref(socks_client_);
300 g_object_unref(ftp_client_);
301 g_object_unref(https_client_);
302 g_object_unref(http_client_);
303 g_object_unref(client_);
304 // We only need to null client_ because it's the only one that we check.
thestig0c412e852016-06-30 08:04:40305 client_ = nullptr;
306 task_runner_ = nullptr;
[email protected]8c20e3d2011-05-19 21:03:57307 }
marshall8e5fe942015-03-06 19:22:40308 debounce_timer_.reset();
[email protected]8c20e3d2011-05-19 21:03:57309 }
310
dcheng67be2b1f2014-10-27 21:47:29311 bool SetUpNotifications(
mostynbba063d6032014-10-09 11:01:13312 ProxyConfigServiceLinux::Delegate* delegate) override {
[email protected]8c20e3d2011-05-19 21:03:57313 DCHECK(client_);
eroman0070d412017-06-22 22:18:24314 DCHECK(task_runner_->RunsTasksInCurrentSequence());
[email protected]8c20e3d2011-05-19 21:03:57315 notify_delegate_ = delegate;
316 // We could watch for the change-event signal instead of changed, but
317 // since we have to watch more than one object, we'd still have to
318 // debounce change notifications. This is conceptually simpler.
Keishi Hattorif28f4f82022-06-21 11:32:15319 g_signal_connect(G_OBJECT(client_.get()), "changed",
[email protected]8c20e3d2011-05-19 21:03:57320 G_CALLBACK(OnGSettingsChangeNotification), this);
Keishi Hattorif28f4f82022-06-21 11:32:15321 g_signal_connect(G_OBJECT(http_client_.get()), "changed",
[email protected]8c20e3d2011-05-19 21:03:57322 G_CALLBACK(OnGSettingsChangeNotification), this);
Keishi Hattorif28f4f82022-06-21 11:32:15323 g_signal_connect(G_OBJECT(https_client_.get()), "changed",
[email protected]8c20e3d2011-05-19 21:03:57324 G_CALLBACK(OnGSettingsChangeNotification), this);
Keishi Hattorif28f4f82022-06-21 11:32:15325 g_signal_connect(G_OBJECT(ftp_client_.get()), "changed",
[email protected]8c20e3d2011-05-19 21:03:57326 G_CALLBACK(OnGSettingsChangeNotification), this);
Keishi Hattorif28f4f82022-06-21 11:32:15327 g_signal_connect(G_OBJECT(socks_client_.get()), "changed",
[email protected]8c20e3d2011-05-19 21:03:57328 G_CALLBACK(OnGSettingsChangeNotification), this);
329 // Simulate a change to avoid possibly losing updates before this point.
330 OnChangeNotification();
331 return true;
332 }
333
eroman0070d412017-06-22 22:18:24334 const scoped_refptr<base::SequencedTaskRunner>& GetNotificationTaskRunner()
dcheng67be2b1f2014-10-27 21:47:29335 override {
sergeyu3f923062014-09-05 01:39:40336 return task_runner_;
[email protected]8c20e3d2011-05-19 21:03:57337 }
338
dcheng67be2b1f2014-10-27 21:47:29339 bool GetString(StringSetting key, std::string* result) override {
[email protected]8c20e3d2011-05-19 21:03:57340 DCHECK(client_);
341 switch (key) {
342 case PROXY_MODE:
343 return GetStringByPath(client_, "mode", result);
344 case PROXY_AUTOCONF_URL:
345 return GetStringByPath(client_, "autoconfig-url", result);
346 case PROXY_HTTP_HOST:
347 return GetStringByPath(http_client_, "host", result);
348 case PROXY_HTTPS_HOST:
349 return GetStringByPath(https_client_, "host", result);
350 case PROXY_FTP_HOST:
351 return GetStringByPath(ftp_client_, "host", result);
352 case PROXY_SOCKS_HOST:
353 return GetStringByPath(socks_client_, "host", result);
[email protected]8c20e3d2011-05-19 21:03:57354 }
[email protected]6b5fe742011-05-20 21:46:48355 return false; // Placate compiler.
[email protected]8c20e3d2011-05-19 21:03:57356 }
dcheng67be2b1f2014-10-27 21:47:29357 bool GetBool(BoolSetting key, bool* result) override {
[email protected]8c20e3d2011-05-19 21:03:57358 DCHECK(client_);
359 switch (key) {
360 case PROXY_USE_HTTP_PROXY:
361 // Although there is an "enabled" boolean in http_client_, it is not set
362 // to true by the proxy config utility. We ignore it and return false.
363 return false;
364 case PROXY_USE_SAME_PROXY:
365 // Similarly, although there is a "use-same-proxy" boolean in client_,
366 // it is never set to false by the proxy config utility. We ignore it.
367 return false;
368 case PROXY_USE_AUTHENTICATION:
369 // There is also no way to set this in the proxy config utility, but it
370 // doesn't hurt us to get the actual setting (unlike the two above).
371 return GetBoolByPath(http_client_, "use-authentication", result);
[email protected]8c20e3d2011-05-19 21:03:57372 }
[email protected]6b5fe742011-05-20 21:46:48373 return false; // Placate compiler.
[email protected]8c20e3d2011-05-19 21:03:57374 }
dcheng67be2b1f2014-10-27 21:47:29375 bool GetInt(IntSetting key, int* result) override {
[email protected]8c20e3d2011-05-19 21:03:57376 DCHECK(client_);
377 switch (key) {
378 case PROXY_HTTP_PORT:
379 return GetIntByPath(http_client_, "port", result);
380 case PROXY_HTTPS_PORT:
381 return GetIntByPath(https_client_, "port", result);
382 case PROXY_FTP_PORT:
383 return GetIntByPath(ftp_client_, "port", result);
384 case PROXY_SOCKS_PORT:
385 return GetIntByPath(socks_client_, "port", result);
[email protected]8c20e3d2011-05-19 21:03:57386 }
[email protected]6b5fe742011-05-20 21:46:48387 return false; // Placate compiler.
[email protected]8c20e3d2011-05-19 21:03:57388 }
dcheng67be2b1f2014-10-27 21:47:29389 bool GetStringList(StringListSetting key,
390 std::vector<std::string>* result) override {
[email protected]8c20e3d2011-05-19 21:03:57391 DCHECK(client_);
392 switch (key) {
393 case PROXY_IGNORE_HOSTS:
394 return GetStringListByPath(client_, "ignore-hosts", result);
[email protected]8c20e3d2011-05-19 21:03:57395 }
[email protected]6b5fe742011-05-20 21:46:48396 return false; // Placate compiler.
[email protected]8c20e3d2011-05-19 21:03:57397 }
398
dcheng67be2b1f2014-10-27 21:47:29399 bool BypassListIsReversed() override {
[email protected]8c20e3d2011-05-19 21:03:57400 // This is a KDE-specific setting.
401 return false;
402 }
403
Shimi Zhang13eace252020-01-31 01:49:19404 bool UseSuffixMatching() override { return false; }
[email protected]8c20e3d2011-05-19 21:03:57405
406 private:
thestig0c412e852016-06-30 08:04:40407 bool GetStringByPath(GSettings* client,
408 base::StringPiece key,
[email protected]8c20e3d2011-05-19 21:03:57409 std::string* result) {
eroman0070d412017-06-22 22:18:24410 DCHECK(task_runner_->RunsTasksInCurrentSequence());
Tim Brown1c307cc2017-12-08 02:40:38411 gchar* value = g_settings_get_string(client, key.data());
[email protected]8c20e3d2011-05-19 21:03:57412 if (!value)
413 return false;
414 *result = value;
415 g_free(value);
416 return true;
417 }
thestig0c412e852016-06-30 08:04:40418 bool GetBoolByPath(GSettings* client, base::StringPiece key, bool* result) {
eroman0070d412017-06-22 22:18:24419 DCHECK(task_runner_->RunsTasksInCurrentSequence());
Tim Brown1c307cc2017-12-08 02:40:38420 *result = static_cast<bool>(g_settings_get_boolean(client, key.data()));
[email protected]8c20e3d2011-05-19 21:03:57421 return true;
422 }
thestig0c412e852016-06-30 08:04:40423 bool GetIntByPath(GSettings* client, base::StringPiece key, int* result) {
eroman0070d412017-06-22 22:18:24424 DCHECK(task_runner_->RunsTasksInCurrentSequence());
Tim Brown1c307cc2017-12-08 02:40:38425 *result = g_settings_get_int(client, key.data());
[email protected]8c20e3d2011-05-19 21:03:57426 return true;
427 }
thestig0c412e852016-06-30 08:04:40428 bool GetStringListByPath(GSettings* client,
429 base::StringPiece key,
[email protected]8c20e3d2011-05-19 21:03:57430 std::vector<std::string>* result) {
eroman0070d412017-06-22 22:18:24431 DCHECK(task_runner_->RunsTasksInCurrentSequence());
Tim Brown1c307cc2017-12-08 02:40:38432 gchar** list = g_settings_get_strv(client, key.data());
[email protected]8c20e3d2011-05-19 21:03:57433 if (!list)
434 return false;
435 for (size_t i = 0; list[i]; ++i) {
436 result->push_back(static_cast<char*>(list[i]));
437 g_free(list[i]);
438 }
439 g_free(list);
440 return true;
441 }
442
443 // This is the callback from the debounce timer.
444 void OnDebouncedNotification() {
eroman0070d412017-06-22 22:18:24445 DCHECK(task_runner_->RunsTasksInCurrentSequence());
[email protected]8c20e3d2011-05-19 21:03:57446 CHECK(notify_delegate_);
447 // Forward to a method on the proxy config service delegate object.
448 notify_delegate_->OnCheckProxyConfigSettings();
449 }
450
451 void OnChangeNotification() {
452 // We don't use Reset() because the timer may not yet be running.
453 // (In that case Stop() is a no-op.)
marshall8e5fe942015-03-06 19:22:40454 debounce_timer_->Stop();
Peter Kastinge5a38ed2021-10-02 03:06:35455 debounce_timer_->Start(
456 FROM_HERE, base::Milliseconds(kDebounceTimeoutMilliseconds), this,
457 &SettingGetterImplGSettings::OnDebouncedNotification);
[email protected]8c20e3d2011-05-19 21:03:57458 }
459
460 // gsettings notification callback, dispatched on the default glib main loop.
461 static void OnGSettingsChangeNotification(GSettings* client, gchar* key,
462 gpointer user_data) {
463 VLOG(1) << "gsettings change notification for key " << key;
464 // We don't track which key has changed, just that something did change.
465 SettingGetterImplGSettings* setting_getter =
466 reinterpret_cast<SettingGetterImplGSettings*>(user_data);
467 setting_getter->OnChangeNotification();
468 }
469
Keishi Hattorif28f4f82022-06-21 11:32:15470 raw_ptr<GSettings> client_ = nullptr;
471 raw_ptr<GSettings> http_client_ = nullptr;
472 raw_ptr<GSettings> https_client_ = nullptr;
473 raw_ptr<GSettings> ftp_client_ = nullptr;
474 raw_ptr<GSettings> socks_client_ = nullptr;
475 raw_ptr<ProxyConfigServiceLinux::Delegate> notify_delegate_ = nullptr;
danakj8a98ca22016-04-16 02:47:36476 std::unique_ptr<base::OneShotTimer> debounce_timer_;
[email protected]8c20e3d2011-05-19 21:03:57477
[email protected]76722472012-05-24 08:26:46478 // Task runner for the thread that we make gsettings calls on. It should
[email protected]8c20e3d2011-05-19 21:03:57479 // be the UI thread and all our methods should be called on this
480 // thread. Only for assertions.
eroman0070d412017-06-22 22:18:24481 scoped_refptr<base::SequencedTaskRunner> task_runner_;
[email protected]8c20e3d2011-05-19 21:03:57482};
483
Tim Brown1c307cc2017-12-08 02:40:38484bool SettingGetterImplGSettings::CheckVersion(
[email protected]8c20e3d2011-05-19 21:03:57485 base::Environment* env) {
Tim Brown1c307cc2017-12-08 02:40:38486 // CheckVersion() must be called *before* Init()!
[email protected]8c20e3d2011-05-19 21:03:57487 DCHECK(!client_);
488
thestig0c412e852016-06-30 08:04:40489 GSettings* client = nullptr;
Tim Brown1c307cc2017-12-08 02:40:38490 if (g_settings_schema_source_lookup(g_settings_schema_source_get_default(),
491 kProxyGSettingsSchema, FALSE)) {
492 client = g_settings_new(kProxyGSettingsSchema);
[email protected]4bbb72d2014-06-06 18:05:51493 }
494 if (!client) {
Tim Brown2a19f3b2017-12-12 01:08:40495 VLOG(1) << "Cannot create gsettings client.";
[email protected]8c20e3d2011-05-19 21:03:57496 return false;
497 }
498 g_object_unref(client);
499
[email protected]8c20e3d2011-05-19 21:03:57500 VLOG(1) << "All gsettings tests OK. Will get proxy config from gsettings.";
501 return true;
502}
503#endif // defined(USE_GIO)
504
eromane44498c2017-06-30 00:02:37505// Converts |value| from a decimal string to an int. If there was a failure
506// parsing, returns |default_value|.
507int StringToIntOrDefault(base::StringPiece value, int default_value) {
508 int result;
509 if (base::StringToInt(value, &result))
510 return result;
511 return default_value;
512}
513
Tim Brown2a19f3b2017-12-12 01:08:40514// This is the KDE version that reads kioslaverc and simulates gsettings.
[email protected]d7395e732009-08-28 23:13:43515// Doing this allows the main Delegate code, as well as the unit tests
516// for it, to stay the same - and the settings map fairly well besides.
gabf4f904e2017-05-10 20:55:02517class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter {
[email protected]d7395e732009-08-28 23:13:43518 public:
[email protected]573c0502011-05-17 22:19:50519 explicit SettingGetterImplKDE(base::Environment* env_var_getter)
Tsuyoshi Horof8861cb2022-07-05 23:50:20520 : debounce_timer_(std::make_unique<base::OneShotTimer>()),
Tsuyoshi Horo432981d52022-06-09 09:50:13521 env_var_getter_(env_var_getter) {
[email protected]9a8c4022011-01-25 14:25:33522 // This has to be called on the UI thread (http://crbug.com/69057).
523 base::ThreadRestrictions::ScopedAllowIO allow_io;
524
Slava Aseev9ffd8a62022-05-25 07:09:09525 // Derive the location(s) of the kde config dir from the environment.
[email protected]92d2dc82010-04-08 17:49:59526 std::string home;
[email protected]3ba7e082010-08-07 02:57:59527 if (env_var_getter->GetVar("KDEHOME", &home) && !home.empty()) {
[email protected]2e8cfe22010-06-12 00:26:24528 // $KDEHOME is set. Use it unconditionally.
Slava Aseev9ffd8a62022-05-25 07:09:09529 kde_config_dirs_.emplace_back(KDEHomeToConfigPath(base::FilePath(home)));
[email protected]92d2dc82010-04-08 17:49:59530 } else {
[email protected]2e8cfe22010-06-12 00:26:24531 // $KDEHOME is unset. Try to figure out what to use. This seems to be
[email protected]92d2dc82010-04-08 17:49:59532 // the common case on most distributions.
[email protected]3ba7e082010-08-07 02:57:59533 if (!env_var_getter->GetVar(base::env_vars::kHome, &home))
[email protected]d7395e732009-08-28 23:13:43534 // User has no $HOME? Give up. Later we'll report the failure.
535 return;
[email protected]6b0349ef2010-10-16 04:56:06536 if (base::nix::GetDesktopEnvironment(env_var_getter) ==
537 base::nix::DESKTOP_ENVIRONMENT_KDE3) {
[email protected]92d2dc82010-04-08 17:49:59538 // KDE3 always uses .kde for its configuration.
[email protected]6cdfd7f2013-02-08 20:40:15539 base::FilePath kde_path = base::FilePath(home).Append(".kde");
Slava Aseev9ffd8a62022-05-25 07:09:09540 kde_config_dirs_.emplace_back(KDEHomeToConfigPath(kde_path));
edward.baker53bec302015-10-02 16:57:49541 } else if (base::nix::GetDesktopEnvironment(env_var_getter) ==
542 base::nix::DESKTOP_ENVIRONMENT_KDE4) {
[email protected]92d2dc82010-04-08 17:49:59543 // Some distributions patch KDE4 to use .kde4 instead of .kde, so that
[email protected]fad9c8a52010-06-10 22:30:53544 // both can be installed side-by-side. Sadly they don't all do this, and
545 // they don't always do this: some distributions have started switching
546 // back as well. So if there is a .kde4 directory, check the timestamps
547 // of the config directories within and use the newest one.
[email protected]92d2dc82010-04-08 17:49:59548 // Note that we should currently be running in the UI thread, because in
Tim Brown2a19f3b2017-12-12 01:08:40549 // the gsettings version, that is the only thread that can access the
550 // proxy settings (a gsettings restriction). As noted below, the initial
551 // read of the proxy settings will be done in this thread anyway, so we
552 // check for .kde4 here in this thread as well.
[email protected]6cdfd7f2013-02-08 20:40:15553 base::FilePath kde3_path = base::FilePath(home).Append(".kde");
554 base::FilePath kde3_config = KDEHomeToConfigPath(kde3_path);
555 base::FilePath kde4_path = base::FilePath(home).Append(".kde4");
556 base::FilePath kde4_config = KDEHomeToConfigPath(kde4_path);
[email protected]fad9c8a52010-06-10 22:30:53557 bool use_kde4 = false;
[email protected]dcd16612013-07-15 20:18:09558 if (base::DirectoryExists(kde4_path)) {
[email protected]54124ed02014-01-07 10:06:58559 base::File::Info kde3_info;
560 base::File::Info kde4_info;
[email protected]9eae4e62013-12-04 20:56:49561 if (base::GetFileInfo(kde4_config, &kde4_info)) {
562 if (base::GetFileInfo(kde3_config, &kde3_info)) {
[email protected]fad9c8a52010-06-10 22:30:53563 use_kde4 = kde4_info.last_modified >= kde3_info.last_modified;
564 } else {
565 use_kde4 = true;
566 }
567 }
568 }
569 if (use_kde4) {
Slava Aseev9ffd8a62022-05-25 07:09:09570 kde_config_dirs_.emplace_back(KDEHomeToConfigPath(kde4_path));
[email protected]92d2dc82010-04-08 17:49:59571 } else {
Slava Aseev9ffd8a62022-05-25 07:09:09572 kde_config_dirs_.emplace_back(KDEHomeToConfigPath(kde3_path));
[email protected]92d2dc82010-04-08 17:49:59573 }
edward.baker53bec302015-10-02 16:57:49574 } else {
575 // KDE 5 migrated to ~/.config for storing kioslaverc.
Slava Aseev9ffd8a62022-05-25 07:09:09576 kde_config_dirs_.emplace_back(base::FilePath(home).Append(".config"));
577
578 // kioslaverc also can be stored in any of XDG_CONFIG_DIRS
579 std::string config_dirs;
580 if (env_var_getter_->GetVar("XDG_CONFIG_DIRS", &config_dirs)) {
581 auto dirs = base::SplitString(config_dirs, ":", base::KEEP_WHITESPACE,
582 base::SPLIT_WANT_NONEMPTY);
583 for (const auto& dir : dirs) {
584 kde_config_dirs_.emplace_back(dir);
585 }
586 }
587
588 // Reverses the order of paths to store them in ascending order of
589 // priority
590 std::reverse(kde_config_dirs_.begin(), kde_config_dirs_.end());
[email protected]92d2dc82010-04-08 17:49:59591 }
[email protected]d7395e732009-08-28 23:13:43592 }
[email protected]d7395e732009-08-28 23:13:43593 }
594
Peter Boström293b1342021-09-22 17:31:43595 SettingGetterImplKDE(const SettingGetterImplKDE&) = delete;
596 SettingGetterImplKDE& operator=(const SettingGetterImplKDE&) = delete;
597
dcheng67be2b1f2014-10-27 21:47:29598 ~SettingGetterImplKDE() override {
[email protected]d7395e732009-08-28 23:13:43599 // inotify_fd_ should have been closed before now, from
600 // Delegate::OnDestroy(), while running on the file thread. However
601 // on exiting the process, it may happen that Delegate::OnDestroy()
602 // task is left pending on the file loop after the loop was quit,
603 // and pending tasks may then be deleted without being run.
604 // Here in the KDE version, we can safely close the file descriptor
605 // anyway. (Not that it really matters; the process is exiting.)
606 if (inotify_fd_ >= 0)
[email protected]d3066142011-05-10 02:36:20607 ShutDown();
thestig0c412e852016-06-30 08:04:40608 DCHECK_LT(inotify_fd_, 0);
[email protected]d7395e732009-08-28 23:13:43609 }
610
eroman0070d412017-06-22 22:18:24611 bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner)
mostynbba063d6032014-10-09 11:01:13612 override {
[email protected]9a8c4022011-01-25 14:25:33613 // This has to be called on the UI thread (http://crbug.com/69057).
614 base::ThreadRestrictions::ScopedAllowIO allow_io;
thestig0c412e852016-06-30 08:04:40615 DCHECK_LT(inotify_fd_, 0);
[email protected]d7395e732009-08-28 23:13:43616 inotify_fd_ = inotify_init();
617 if (inotify_fd_ < 0) {
[email protected]57b765672009-10-13 18:27:40618 PLOG(ERROR) << "inotify_init failed";
[email protected]d7395e732009-08-28 23:13:43619 return false;
620 }
tfarina89b4ae1c2015-12-16 18:59:18621 if (!base::SetNonBlocking(inotify_fd_)) {
622 PLOG(ERROR) << "base::SetNonBlocking failed";
[email protected]d7395e732009-08-28 23:13:43623 close(inotify_fd_);
624 inotify_fd_ = -1;
625 return false;
626 }
eroman0070d412017-06-22 22:18:24627
Gabriel Charette4049d422020-02-29 00:43:27628 constexpr base::TaskTraits kTraits = {base::TaskPriority::USER_VISIBLE,
629 base::MayBlock()};
630 file_task_runner_ = base::ThreadPool::CreateSequencedTaskRunner(kTraits);
eroman0070d412017-06-22 22:18:24631
sergeyu3f923062014-09-05 01:39:40632 // The initial read is done on the current thread, not
633 // |file_task_runner_|, since we will need to have it for
634 // SetUpAndFetchInitialConfig().
[email protected]d7395e732009-08-28 23:13:43635 UpdateCachedSettings();
636 return true;
637 }
638
dcheng67be2b1f2014-10-27 21:47:29639 void ShutDown() override {
[email protected]d7395e732009-08-28 23:13:43640 if (inotify_fd_ >= 0) {
641 ResetCachedSettings();
gabf4f904e2017-05-10 20:55:02642 inotify_watcher_.reset();
[email protected]d7395e732009-08-28 23:13:43643 close(inotify_fd_);
644 inotify_fd_ = -1;
645 }
marshall8e5fe942015-03-06 19:22:40646 debounce_timer_.reset();
[email protected]d7395e732009-08-28 23:13:43647 }
648
dcheng67be2b1f2014-10-27 21:47:29649 bool SetUpNotifications(
mostynbba063d6032014-10-09 11:01:13650 ProxyConfigServiceLinux::Delegate* delegate) override {
thestig0c412e852016-06-30 08:04:40651 DCHECK_GE(inotify_fd_, 0);
eroman0070d412017-06-22 22:18:24652 DCHECK(file_task_runner_->RunsTasksInCurrentSequence());
[email protected]d7395e732009-08-28 23:13:43653 // We can't just watch the kioslaverc file directly, since KDE will write
654 // a new copy of it and then rename it whenever settings are changed and
655 // inotify watches inodes (so we'll be watching the old deleted file after
656 // the first change, and it will never change again). So, we watch the
657 // directory instead. We then act only on changes to the kioslaverc entry.
eroman6b0ca662017-06-22 00:16:36658 // TODO(eroman): What if the file is deleted? (handle with IN_DELETE).
Slava Aseev9ffd8a62022-05-25 07:09:09659 size_t failed_dirs = 0;
660 for (const auto& kde_config_dir : kde_config_dirs_) {
661 if (inotify_add_watch(inotify_fd_, kde_config_dir.value().c_str(),
662 IN_MODIFY | IN_MOVED_TO) < 0) {
663 ++failed_dirs;
664 }
665 }
666 // Fail if inotify_add_watch failed with every directory
667 if (failed_dirs == kde_config_dirs_.size()) {
[email protected]d7395e732009-08-28 23:13:43668 return false;
sergeyu3f923062014-09-05 01:39:40669 }
[email protected]d7395e732009-08-28 23:13:43670 notify_delegate_ = delegate;
gabf4f904e2017-05-10 20:55:02671 inotify_watcher_ = base::FileDescriptorWatcher::WatchReadable(
Anna Malovaae7007aa2020-03-09 16:48:48672 inotify_fd_,
673 base::BindRepeating(&SettingGetterImplKDE::OnChangeNotification,
674 base::Unretained(this)));
[email protected]d3066142011-05-10 02:36:20675 // Simulate a change to avoid possibly losing updates before this point.
676 OnChangeNotification();
677 return true;
[email protected]d7395e732009-08-28 23:13:43678 }
679
eroman0070d412017-06-22 22:18:24680 const scoped_refptr<base::SequencedTaskRunner>& GetNotificationTaskRunner()
dcheng67be2b1f2014-10-27 21:47:29681 override {
sergeyu3f923062014-09-05 01:39:40682 return file_task_runner_;
[email protected]d7395e732009-08-28 23:13:43683 }
684
dcheng67be2b1f2014-10-27 21:47:29685 bool GetString(StringSetting key, std::string* result) override {
jdoerrie22a91d8b92018-10-05 08:43:26686 auto it = string_table_.find(key);
[email protected]d7395e732009-08-28 23:13:43687 if (it == string_table_.end())
688 return false;
689 *result = it->second;
690 return true;
691 }
dcheng67be2b1f2014-10-27 21:47:29692 bool GetBool(BoolSetting key, bool* result) override {
[email protected]d7395e732009-08-28 23:13:43693 // We don't ever have any booleans.
694 return false;
695 }
dcheng67be2b1f2014-10-27 21:47:29696 bool GetInt(IntSetting key, int* result) override {
[email protected]d7395e732009-08-28 23:13:43697 // We don't ever have any integers. (See AddProxy() below about ports.)
698 return false;
699 }
dcheng67be2b1f2014-10-27 21:47:29700 bool GetStringList(StringListSetting key,
701 std::vector<std::string>* result) override {
jdoerrie22a91d8b92018-10-05 08:43:26702 auto it = strings_table_.find(key);
[email protected]d7395e732009-08-28 23:13:43703 if (it == strings_table_.end())
704 return false;
705 *result = it->second;
706 return true;
707 }
708
dcheng67be2b1f2014-10-27 21:47:29709 bool BypassListIsReversed() override { return reversed_bypass_list_; }
[email protected]a48bf4a2010-06-14 18:24:53710
Shimi Zhang13eace252020-01-31 01:49:19711 bool UseSuffixMatching() override { return true; }
[email protected]1a597192010-07-09 16:58:38712
[email protected]d7395e732009-08-28 23:13:43713 private:
714 void ResetCachedSettings() {
715 string_table_.clear();
716 strings_table_.clear();
717 indirect_manual_ = false;
718 auto_no_pac_ = false;
[email protected]a48bf4a2010-06-14 18:24:53719 reversed_bypass_list_ = false;
[email protected]d7395e732009-08-28 23:13:43720 }
721
[email protected]6cdfd7f2013-02-08 20:40:15722 base::FilePath KDEHomeToConfigPath(const base::FilePath& kde_home) {
[email protected]92d2dc82010-04-08 17:49:59723 return kde_home.Append("share").Append("config");
724 }
725
[email protected]6b5fe742011-05-20 21:46:48726 void AddProxy(StringSetting host_key, const std::string& value) {
[email protected]d7395e732009-08-28 23:13:43727 if (value.empty() || value.substr(0, 3) == "//:")
728 // No proxy.
729 return;
[email protected]4b90c202012-04-24 23:27:55730 size_t space = value.find(' ');
731 if (space != std::string::npos) {
732 // Newer versions of KDE use a space rather than a colon to separate the
733 // port number from the hostname. If we find this, we need to convert it.
734 std::string fixed = value;
735 fixed[space] = ':';
736 string_table_[host_key] = fixed;
737 } else {
738 // We don't need to parse the port number out; GetProxyFromSettings()
739 // would only append it right back again. So we just leave the port
740 // number right in the host string.
741 string_table_[host_key] = value;
742 }
[email protected]d7395e732009-08-28 23:13:43743 }
744
[email protected]6b5fe742011-05-20 21:46:48745 void AddHostList(StringListSetting key, const std::string& value) {
[email protected]f18fde22010-05-18 23:49:54746 std::vector<std::string> tokens;
[email protected]f4ebe772013-02-02 00:21:39747 base::StringTokenizer tk(value, ", ");
[email protected]f18fde22010-05-18 23:49:54748 while (tk.GetNext()) {
749 std::string token = tk.token();
750 if (!token.empty())
751 tokens.push_back(token);
752 }
753 strings_table_[key] = tokens;
754 }
755
[email protected]9a3d8d42009-09-03 17:01:46756 void AddKDESetting(const std::string& key, const std::string& value) {
[email protected]d7395e732009-08-28 23:13:43757 if (key == "ProxyType") {
758 const char* mode = "none";
759 indirect_manual_ = false;
760 auto_no_pac_ = false;
eromane44498c2017-06-30 00:02:37761 int int_value = StringToIntOrDefault(value, 0);
[email protected]e83326f2010-07-31 17:29:25762 switch (int_value) {
[email protected]d7395e732009-08-28 23:13:43763 case 1: // Manual configuration.
764 mode = "manual";
765 break;
766 case 2: // PAC URL.
767 mode = "auto";
768 break;
769 case 3: // WPAD.
770 mode = "auto";
771 auto_no_pac_ = true;
772 break;
773 case 4: // Indirect manual via environment variables.
774 mode = "manual";
775 indirect_manual_ = true;
776 break;
eromane44498c2017-06-30 00:02:37777 default: // No proxy, or maybe kioslaverc syntax error.
778 break;
[email protected]d7395e732009-08-28 23:13:43779 }
[email protected]573c0502011-05-17 22:19:50780 string_table_[PROXY_MODE] = mode;
[email protected]d7395e732009-08-28 23:13:43781 } else if (key == "Proxy Config Script") {
[email protected]573c0502011-05-17 22:19:50782 string_table_[PROXY_AUTOCONF_URL] = value;
[email protected]d7395e732009-08-28 23:13:43783 } else if (key == "httpProxy") {
[email protected]573c0502011-05-17 22:19:50784 AddProxy(PROXY_HTTP_HOST, value);
[email protected]d7395e732009-08-28 23:13:43785 } else if (key == "httpsProxy") {
[email protected]573c0502011-05-17 22:19:50786 AddProxy(PROXY_HTTPS_HOST, value);
[email protected]d7395e732009-08-28 23:13:43787 } else if (key == "ftpProxy") {
[email protected]573c0502011-05-17 22:19:50788 AddProxy(PROXY_FTP_HOST, value);
[email protected]bfeb7232012-06-08 00:58:37789 } else if (key == "socksProxy") {
790 // Older versions of KDE configure SOCKS in a weird way involving
791 // LD_PRELOAD and a library that intercepts network calls to SOCKSify
792 // them. We don't support it. KDE 4.8 added a proper SOCKS setting.
793 AddProxy(PROXY_SOCKS_HOST, value);
[email protected]d7395e732009-08-28 23:13:43794 } else if (key == "ReversedException") {
795 // We count "true" or any nonzero number as true, otherwise false.
eromane44498c2017-06-30 00:02:37796 // A failure parsing the integer will also mean false.
797 reversed_bypass_list_ =
798 (value == "true" || StringToIntOrDefault(value, 0) != 0);
[email protected]d7395e732009-08-28 23:13:43799 } else if (key == "NoProxyFor") {
[email protected]573c0502011-05-17 22:19:50800 AddHostList(PROXY_IGNORE_HOSTS, value);
[email protected]d7395e732009-08-28 23:13:43801 } else if (key == "AuthMode") {
802 // Check for authentication, just so we can warn.
eromane44498c2017-06-30 00:02:37803 int mode = StringToIntOrDefault(value, 0);
[email protected]d7395e732009-08-28 23:13:43804 if (mode) {
805 // ProxyConfig does not support authentication parameters, but
806 // Chrome will prompt for the password later. So we ignore this.
807 LOG(WARNING) <<
808 "Proxy authentication parameters ignored, see bug 16709";
809 }
810 }
811 }
812
[email protected]6b5fe742011-05-20 21:46:48813 void ResolveIndirect(StringSetting key) {
jdoerrie22a91d8b92018-10-05 08:43:26814 auto it = string_table_.find(key);
[email protected]d7395e732009-08-28 23:13:43815 if (it != string_table_.end()) {
[email protected]f18fde22010-05-18 23:49:54816 std::string value;
[email protected]3ba7e082010-08-07 02:57:59817 if (env_var_getter_->GetVar(it->second.c_str(), &value))
[email protected]d7395e732009-08-28 23:13:43818 it->second = value;
[email protected]8425adc02010-04-18 17:45:31819 else
820 string_table_.erase(it);
[email protected]d7395e732009-08-28 23:13:43821 }
822 }
823
[email protected]6b5fe742011-05-20 21:46:48824 void ResolveIndirectList(StringListSetting key) {
jdoerrie22a91d8b92018-10-05 08:43:26825 auto it = strings_table_.find(key);
[email protected]f18fde22010-05-18 23:49:54826 if (it != strings_table_.end()) {
827 std::string value;
828 if (!it->second.empty() &&
[email protected]3ba7e082010-08-07 02:57:59829 env_var_getter_->GetVar(it->second[0].c_str(), &value))
[email protected]f18fde22010-05-18 23:49:54830 AddHostList(key, value);
831 else
832 strings_table_.erase(it);
833 }
834 }
835
[email protected]d7395e732009-08-28 23:13:43836 // The settings in kioslaverc could occur in any order, but some affect
837 // others. Rather than read the whole file in and then query them in an
838 // order that allows us to handle that, we read the settings in whatever
839 // order they occur and do any necessary tweaking after we finish.
840 void ResolveModeEffects() {
841 if (indirect_manual_) {
[email protected]573c0502011-05-17 22:19:50842 ResolveIndirect(PROXY_HTTP_HOST);
843 ResolveIndirect(PROXY_HTTPS_HOST);
844 ResolveIndirect(PROXY_FTP_HOST);
Maks Orlovichfee43b12021-06-17 21:10:08845 ResolveIndirect(PROXY_SOCKS_HOST);
[email protected]573c0502011-05-17 22:19:50846 ResolveIndirectList(PROXY_IGNORE_HOSTS);
[email protected]d7395e732009-08-28 23:13:43847 }
848 if (auto_no_pac_) {
849 // Remove the PAC URL; we're not supposed to use it.
[email protected]573c0502011-05-17 22:19:50850 string_table_.erase(PROXY_AUTOCONF_URL);
[email protected]d7395e732009-08-28 23:13:43851 }
[email protected]d7395e732009-08-28 23:13:43852 }
853
Slava Aseev9ffd8a62022-05-25 07:09:09854 // Reads kioslaverc from all paths one line at a time and calls
855 // AddKDESetting() to add each relevant name-value pair to the appropriate
856 // value table. Each value can be overwritten by values from configs from
857 // the following paths.
[email protected]d7395e732009-08-28 23:13:43858 void UpdateCachedSettings() {
Slava Aseev9ffd8a62022-05-25 07:09:09859 bool at_least_one_kioslaverc_opened = false;
860 for (const auto& kde_config_dir : kde_config_dirs_) {
861 base::FilePath kioslaverc = kde_config_dir.Append("kioslaverc");
862 base::ScopedFILE input(base::OpenFile(kioslaverc, "r"));
863 if (!input.get())
[email protected]d7395e732009-08-28 23:13:43864 continue;
Slava Aseev9ffd8a62022-05-25 07:09:09865
866 // Reset cached settings once only if some config was successfully opened
867 if (!at_least_one_kioslaverc_opened) {
868 ResetCachedSettings();
[email protected]d7395e732009-08-28 23:13:43869 }
Slava Aseev9ffd8a62022-05-25 07:09:09870 at_least_one_kioslaverc_opened = true;
871 bool in_proxy_settings = false;
872 bool line_too_long = false;
873 char line[BUFFER_SIZE];
874 // fgets() will return NULL on EOF or error.
875 while (fgets(line, sizeof(line), input.get())) {
876 // fgets() guarantees the line will be properly terminated.
877 size_t length = strlen(line);
878 if (!length)
879 continue;
880 // This should be true even with CRLF endings.
881 if (line[length - 1] != '\n') {
882 line_too_long = true;
883 continue;
884 }
885 if (line_too_long) {
886 // The previous line had no line ending, but this one does. This is
887 // the end of the line that was too long, so warn here and skip it.
888 LOG(WARNING) << "skipped very long line in " << kioslaverc.value();
889 line_too_long = false;
890 continue;
891 }
892 // Remove the LF at the end, and the CR if there is one.
[email protected]d7395e732009-08-28 23:13:43893 line[--length] = '\0';
Slava Aseev9ffd8a62022-05-25 07:09:09894 if (length && line[length - 1] == '\r')
895 line[--length] = '\0';
896 // Now parse the line.
897 if (line[0] == '[') {
898 // Switching sections. All we care about is whether this is
899 // the (a?) proxy settings section, for both KDE3 and KDE4.
900 in_proxy_settings = !strncmp(line, "[Proxy Settings]", 16);
901 } else if (in_proxy_settings) {
902 // A regular line, in the (a?) proxy settings section.
903 char* split = strchr(line, '=');
904 // Skip this line if it does not contain an = sign.
905 if (!split)
[email protected]d7395e732009-08-28 23:13:43906 continue;
Slava Aseev9ffd8a62022-05-25 07:09:09907 // Split the line on the = and advance |split|.
908 *(split++) = 0;
909 std::string key = line;
910 std::string value = split;
911 base::TrimWhitespaceASCII(key, base::TRIM_ALL, &key);
912 base::TrimWhitespaceASCII(value, base::TRIM_ALL, &value);
913 // Skip this line if the key name is empty.
[email protected]9a3d8d42009-09-03 17:01:46914 if (key.empty())
915 continue;
Slava Aseev9ffd8a62022-05-25 07:09:09916 // Is the value name localized?
917 if (key[key.length() - 1] == ']') {
918 // Find the matching bracket.
919 length = key.rfind('[');
920 // Skip this line if the localization indicator is malformed.
921 if (length == std::string::npos)
922 continue;
923 // Trim the localization indicator off.
924 key.resize(length);
925 // Remove any resulting trailing whitespace.
926 base::TrimWhitespaceASCII(key, base::TRIM_TRAILING, &key);
927 // Skip this line if the key name is now empty.
928 if (key.empty())
929 continue;
930 }
931 // Now fill in the tables.
932 AddKDESetting(key, value);
[email protected]d7395e732009-08-28 23:13:43933 }
[email protected]d7395e732009-08-28 23:13:43934 }
Slava Aseev9ffd8a62022-05-25 07:09:09935 if (ferror(input.get()))
936 LOG(ERROR) << "error reading " << kioslaverc.value();
[email protected]d7395e732009-08-28 23:13:43937 }
Slava Aseev9ffd8a62022-05-25 07:09:09938 if (at_least_one_kioslaverc_opened) {
939 ResolveModeEffects();
940 }
[email protected]d7395e732009-08-28 23:13:43941 }
942
943 // This is the callback from the debounce timer.
944 void OnDebouncedNotification() {
eroman0070d412017-06-22 22:18:24945 DCHECK(file_task_runner_->RunsTasksInCurrentSequence());
[email protected]b30a3f52010-10-16 01:05:46946 VLOG(1) << "inotify change notification for kioslaverc";
[email protected]d7395e732009-08-28 23:13:43947 UpdateCachedSettings();
[email protected]961ac942011-04-28 18:18:14948 CHECK(notify_delegate_);
[email protected]d7395e732009-08-28 23:13:43949 // Forward to a method on the proxy config service delegate object.
950 notify_delegate_->OnCheckProxyConfigSettings();
951 }
952
953 // Called by OnFileCanReadWithoutBlocking() on the file thread. Reads
954 // from the inotify file descriptor and starts up a debounce timer if
955 // an event for kioslaverc is seen.
956 void OnChangeNotification() {
[email protected]d2e6d592012-02-03 21:49:04957 DCHECK_GE(inotify_fd_, 0);
eroman0070d412017-06-22 22:18:24958 DCHECK(file_task_runner_->RunsTasksInCurrentSequence());
[email protected]d7395e732009-08-28 23:13:43959 char event_buf[(sizeof(inotify_event) + NAME_MAX + 1) * 4];
960 bool kioslaverc_touched = false;
961 ssize_t r;
962 while ((r = read(inotify_fd_, event_buf, sizeof(event_buf))) > 0) {
963 // inotify returns variable-length structures, which is why we have
964 // this strange-looking loop instead of iterating through an array.
965 char* event_ptr = event_buf;
966 while (event_ptr < event_buf + r) {
967 inotify_event* event = reinterpret_cast<inotify_event*>(event_ptr);
968 // The kernel always feeds us whole events.
[email protected]b1f031dd2010-03-02 23:19:33969 CHECK_LE(event_ptr + sizeof(inotify_event), event_buf + r);
970 CHECK_LE(event->name + event->len, event_buf + r);
[email protected]d7395e732009-08-28 23:13:43971 if (!strcmp(event->name, "kioslaverc"))
972 kioslaverc_touched = true;
973 // Advance the pointer just past the end of the filename.
974 event_ptr = event->name + event->len;
975 }
976 // We keep reading even if |kioslaverc_touched| is true to drain the
977 // inotify event queue.
978 }
979 if (!r)
980 // Instead of returning -1 and setting errno to EINVAL if there is not
981 // enough buffer space, older kernels (< 2.6.21) return 0. Simulate the
982 // new behavior (EINVAL) so we can reuse the code below.
983 errno = EINVAL;
984 if (errno != EAGAIN) {
[email protected]57b765672009-10-13 18:27:40985 PLOG(WARNING) << "error reading inotify file descriptor";
[email protected]d7395e732009-08-28 23:13:43986 if (errno == EINVAL) {
987 // Our buffer is not large enough to read the next event. This should
988 // not happen (because its size is calculated to always be sufficiently
989 // large), but if it does we'd warn continuously since |inotify_fd_|
990 // would be forever ready to read. Close it and stop watching instead.
991 LOG(ERROR) << "inotify failure; no longer watching kioslaverc!";
gabf4f904e2017-05-10 20:55:02992 inotify_watcher_.reset();
[email protected]d7395e732009-08-28 23:13:43993 close(inotify_fd_);
994 inotify_fd_ = -1;
995 }
996 }
997 if (kioslaverc_touched) {
eroman6b0ca662017-06-22 00:16:36998 LOG(ERROR) << "kioslaverc_touched";
[email protected]d7395e732009-08-28 23:13:43999 // We don't use Reset() because the timer may not yet be running.
1000 // (In that case Stop() is a no-op.)
marshall8e5fe942015-03-06 19:22:401001 debounce_timer_->Stop();
Peter Kastinge5a38ed2021-10-02 03:06:351002 debounce_timer_->Start(
1003 FROM_HERE, base::Milliseconds(kDebounceTimeoutMilliseconds), this,
[email protected]573c0502011-05-17 22:19:501004 &SettingGetterImplKDE::OnDebouncedNotification);
[email protected]d7395e732009-08-28 23:13:431005 }
1006 }
1007
[email protected]6b5fe742011-05-20 21:46:481008 typedef std::map<StringSetting, std::string> string_map_type;
1009 typedef std::map<StringListSetting,
1010 std::vector<std::string> > strings_map_type;
[email protected]d7395e732009-08-28 23:13:431011
Tsuyoshi Horo4478fd32022-06-09 01:41:251012 int inotify_fd_ = -1;
gabf4f904e2017-05-10 20:55:021013 std::unique_ptr<base::FileDescriptorWatcher::Controller> inotify_watcher_;
Keishi Hattorif28f4f82022-06-21 11:32:151014 raw_ptr<ProxyConfigServiceLinux::Delegate> notify_delegate_ = nullptr;
danakj8a98ca22016-04-16 02:47:361015 std::unique_ptr<base::OneShotTimer> debounce_timer_;
Slava Aseev9ffd8a62022-05-25 07:09:091016 std::vector<base::FilePath> kde_config_dirs_;
Tsuyoshi Horo4478fd32022-06-09 01:41:251017 bool indirect_manual_ = false;
1018 bool auto_no_pac_ = false;
1019 bool reversed_bypass_list_ = false;
[email protected]f18fde22010-05-18 23:49:541020 // We don't own |env_var_getter_|. It's safe to hold a pointer to it, since
1021 // both it and us are owned by ProxyConfigServiceLinux::Delegate, and have the
1022 // same lifetime.
Keishi Hattorif28f4f82022-06-21 11:32:151023 raw_ptr<base::Environment> env_var_getter_;
[email protected]d7395e732009-08-28 23:13:431024
1025 // We cache these settings whenever we re-read the kioslaverc file.
1026 string_map_type string_table_;
1027 strings_map_type strings_table_;
1028
eroman0070d412017-06-22 22:18:241029 // Task runner for doing blocking file IO on, as well as handling inotify
1030 // events on.
1031 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
[email protected]861c6c62009-04-20 16:50:561032};
1033
1034} // namespace
1035
[email protected]573c0502011-05-17 22:19:501036bool ProxyConfigServiceLinux::Delegate::GetProxyFromSettings(
[email protected]6b5fe742011-05-20 21:46:481037 SettingGetter::StringSetting host_key,
[email protected]573c0502011-05-17 22:19:501038 ProxyServer* result_server) {
[email protected]861c6c62009-04-20 16:50:561039 std::string host;
[email protected]573c0502011-05-17 22:19:501040 if (!setting_getter_->GetString(host_key, &host) || host.empty()) {
[email protected]861c6c62009-04-20 16:50:561041 // Unset or empty.
1042 return false;
1043 }
1044 // Check for an optional port.
[email protected]d7395e732009-08-28 23:13:431045 int port = 0;
[email protected]6b5fe742011-05-20 21:46:481046 SettingGetter::IntSetting port_key =
[email protected]573c0502011-05-17 22:19:501047 SettingGetter::HostSettingToPortSetting(host_key);
1048 setting_getter_->GetInt(port_key, &port);
[email protected]861c6c62009-04-20 16:50:561049 if (port != 0) {
1050 // If a port is set and non-zero:
Raul Tambre8c1981d2019-02-08 02:22:261051 host += ":" + base::NumberToString(port);
[email protected]861c6c62009-04-20 16:50:561052 }
[email protected]76960f3d2011-04-30 02:15:231053
Tim Brown2a19f3b2017-12-12 01:08:401054 // gsettings settings do not appear to distinguish between SOCKS version. We
[email protected]573c0502011-05-17 22:19:501055 // default to version 5. For more information on this policy decision, see:
[email protected]76960f3d2011-04-30 02:15:231056 // http://code.google.com/p/chromium/issues/detail?id=55912#c2
[email protected]573c0502011-05-17 22:19:501057 ProxyServer::Scheme scheme = (host_key == SettingGetter::PROXY_SOCKS_HOST) ?
1058 ProxyServer::SCHEME_SOCKS5 : ProxyServer::SCHEME_HTTP;
1059 host = FixupProxyHostScheme(scheme, host);
Eric Orth5ccc3f02021-09-23 00:01:571060 ProxyServer proxy_server =
1061 ProxyUriToProxyServer(host, ProxyServer::SCHEME_HTTP);
[email protected]861c6c62009-04-20 16:50:561062 if (proxy_server.is_valid()) {
1063 *result_server = proxy_server;
1064 return true;
1065 }
1066 return false;
1067}
1068
Anton Bikineev068d2912021-05-15 20:43:521069absl::optional<ProxyConfigWithAnnotation>
Eric Roman750af4b12018-02-22 22:38:531070ProxyConfigServiceLinux::Delegate::GetConfigFromSettings() {
Ramin Halavatica8d5252018-03-12 05:33:491071 ProxyConfig config;
Shubham Aggarwal1f6a5a12021-09-29 21:48:161072 config.set_from_system(true);
Eric Roman750af4b12018-02-22 22:38:531073
[email protected]861c6c62009-04-20 16:50:561074 std::string mode;
[email protected]573c0502011-05-17 22:19:501075 if (!setting_getter_->GetString(SettingGetter::PROXY_MODE, &mode)) {
Tim Brown2a19f3b2017-12-12 01:08:401076 // We expect this to always be set, so if we don't see it then we probably
1077 // have a gsettings problem, and so we don't have a valid proxy config.
Anton Bikineev068d2912021-05-15 20:43:521078 return absl::nullopt;
[email protected]861c6c62009-04-20 16:50:561079 }
[email protected]3e44697f2009-05-22 14:37:391080 if (mode == "none") {
[email protected]861c6c62009-04-20 16:50:561081 // Specifically specifies no proxy.
Ramin Halavatica8d5252018-03-12 05:33:491082 return ProxyConfigWithAnnotation(
1083 config, NetworkTrafficAnnotationTag(traffic_annotation_));
[email protected]3e44697f2009-05-22 14:37:391084 }
[email protected]861c6c62009-04-20 16:50:561085
[email protected]3e44697f2009-05-22 14:37:391086 if (mode == "auto") {
[email protected]aa3ac2cc2012-06-19 00:28:041087 // Automatic proxy config.
[email protected]861c6c62009-04-20 16:50:561088 std::string pac_url_str;
[email protected]573c0502011-05-17 22:19:501089 if (setting_getter_->GetString(SettingGetter::PROXY_AUTOCONF_URL,
1090 &pac_url_str)) {
[email protected]861c6c62009-04-20 16:50:561091 if (!pac_url_str.empty()) {
[email protected]aa3ac2cc2012-06-19 00:28:041092 // If the PAC URL is actually a file path, then put file:// in front.
1093 if (pac_url_str[0] == '/')
1094 pac_url_str = "file://" + pac_url_str;
[email protected]861c6c62009-04-20 16:50:561095 GURL pac_url(pac_url_str);
1096 if (!pac_url.is_valid())
Anton Bikineev068d2912021-05-15 20:43:521097 return absl::nullopt;
Ramin Halavatica8d5252018-03-12 05:33:491098 config.set_pac_url(pac_url);
1099 return ProxyConfigWithAnnotation(
1100 config, NetworkTrafficAnnotationTag(traffic_annotation_));
[email protected]861c6c62009-04-20 16:50:561101 }
1102 }
Ramin Halavatica8d5252018-03-12 05:33:491103 config.set_auto_detect(true);
1104 return ProxyConfigWithAnnotation(
1105 config, NetworkTrafficAnnotationTag(traffic_annotation_));
[email protected]861c6c62009-04-20 16:50:561106 }
1107
[email protected]3e44697f2009-05-22 14:37:391108 if (mode != "manual") {
[email protected]861c6c62009-04-20 16:50:561109 // Mode is unrecognized.
Anton Bikineev068d2912021-05-15 20:43:521110 return absl::nullopt;
[email protected]861c6c62009-04-20 16:50:561111 }
1112 bool use_http_proxy;
[email protected]573c0502011-05-17 22:19:501113 if (setting_getter_->GetBool(SettingGetter::PROXY_USE_HTTP_PROXY,
1114 &use_http_proxy)
[email protected]861c6c62009-04-20 16:50:561115 && !use_http_proxy) {
1116 // Another master switch for some reason. If set to false, then no
1117 // proxy. But we don't panic if the key doesn't exist.
Ramin Halavatica8d5252018-03-12 05:33:491118 return ProxyConfigWithAnnotation(
1119 config, NetworkTrafficAnnotationTag(traffic_annotation_));
[email protected]861c6c62009-04-20 16:50:561120 }
1121
1122 bool same_proxy = false;
1123 // Indicates to use the http proxy for all protocols. This one may
[email protected]573c0502011-05-17 22:19:501124 // not exist (presumably on older versions); we assume false in that
[email protected]861c6c62009-04-20 16:50:561125 // case.
[email protected]573c0502011-05-17 22:19:501126 setting_getter_->GetBool(SettingGetter::PROXY_USE_SAME_PROXY,
1127 &same_proxy);
[email protected]861c6c62009-04-20 16:50:561128
[email protected]76960f3d2011-04-30 02:15:231129 ProxyServer proxy_for_http;
1130 ProxyServer proxy_for_https;
1131 ProxyServer proxy_for_ftp;
1132 ProxyServer socks_proxy; // (socks)
1133
1134 // This counts how many of the above ProxyServers were defined and valid.
1135 size_t num_proxies_specified = 0;
1136
1137 // Extract the per-scheme proxies. If we failed to parse it, or no proxy was
1138 // specified for the scheme, then the resulting ProxyServer will be invalid.
[email protected]573c0502011-05-17 22:19:501139 if (GetProxyFromSettings(SettingGetter::PROXY_HTTP_HOST, &proxy_for_http))
[email protected]76960f3d2011-04-30 02:15:231140 num_proxies_specified++;
[email protected]573c0502011-05-17 22:19:501141 if (GetProxyFromSettings(SettingGetter::PROXY_HTTPS_HOST, &proxy_for_https))
[email protected]76960f3d2011-04-30 02:15:231142 num_proxies_specified++;
[email protected]573c0502011-05-17 22:19:501143 if (GetProxyFromSettings(SettingGetter::PROXY_FTP_HOST, &proxy_for_ftp))
[email protected]76960f3d2011-04-30 02:15:231144 num_proxies_specified++;
[email protected]573c0502011-05-17 22:19:501145 if (GetProxyFromSettings(SettingGetter::PROXY_SOCKS_HOST, &socks_proxy))
[email protected]76960f3d2011-04-30 02:15:231146 num_proxies_specified++;
1147
1148 if (same_proxy) {
1149 if (proxy_for_http.is_valid()) {
1150 // Use the http proxy for all schemes.
Ramin Halavatica8d5252018-03-12 05:33:491151 config.proxy_rules().type = ProxyConfig::ProxyRules::Type::PROXY_LIST;
1152 config.proxy_rules().single_proxies.SetSingleProxyServer(proxy_for_http);
[email protected]861c6c62009-04-20 16:50:561153 }
[email protected]76960f3d2011-04-30 02:15:231154 } else if (num_proxies_specified > 0) {
1155 if (socks_proxy.is_valid() && num_proxies_specified == 1) {
1156 // If the only proxy specified was for SOCKS, use it for all schemes.
Ramin Halavatica8d5252018-03-12 05:33:491157 config.proxy_rules().type = ProxyConfig::ProxyRules::Type::PROXY_LIST;
1158 config.proxy_rules().single_proxies.SetSingleProxyServer(socks_proxy);
[email protected]861c6c62009-04-20 16:50:561159 } else {
[email protected]2189e092013-03-16 18:02:021160 // Otherwise use the indicated proxies per-scheme.
Ramin Halavatica8d5252018-03-12 05:33:491161 config.proxy_rules().type =
Lily Houghtone6b617e2018-01-19 20:13:071162 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME;
Ramin Halavatica8d5252018-03-12 05:33:491163 config.proxy_rules().proxies_for_http.SetSingleProxyServer(
1164 proxy_for_http);
1165 config.proxy_rules().proxies_for_https.SetSingleProxyServer(
1166 proxy_for_https);
1167 config.proxy_rules().proxies_for_ftp.SetSingleProxyServer(proxy_for_ftp);
1168 config.proxy_rules().fallback_proxies.SetSingleProxyServer(socks_proxy);
[email protected]861c6c62009-04-20 16:50:561169 }
1170 }
1171
Ramin Halavatica8d5252018-03-12 05:33:491172 if (config.proxy_rules().empty()) {
[email protected]861c6c62009-04-20 16:50:561173 // Manual mode but we couldn't parse any rules.
Anton Bikineev068d2912021-05-15 20:43:521174 return absl::nullopt;
[email protected]861c6c62009-04-20 16:50:561175 }
1176
1177 // Check for authentication, just so we can warn.
[email protected]d7395e732009-08-28 23:13:431178 bool use_auth = false;
[email protected]573c0502011-05-17 22:19:501179 setting_getter_->GetBool(SettingGetter::PROXY_USE_AUTHENTICATION,
1180 &use_auth);
[email protected]62749f182009-07-15 13:16:541181 if (use_auth) {
1182 // ProxyConfig does not support authentication parameters, but
1183 // Chrome will prompt for the password later. So we ignore
1184 // /system/http_proxy/*auth* settings.
1185 LOG(WARNING) << "Proxy authentication parameters ignored, see bug 16709";
1186 }
[email protected]861c6c62009-04-20 16:50:561187
1188 // Now the bypass list.
[email protected]7541206c2010-02-19 20:24:061189 std::vector<std::string> ignore_hosts_list;
Ramin Halavatica8d5252018-03-12 05:33:491190 config.proxy_rules().bypass_rules.Clear();
[email protected]573c0502011-05-17 22:19:501191 if (setting_getter_->GetStringList(SettingGetter::PROXY_IGNORE_HOSTS,
1192 &ignore_hosts_list)) {
Eric Romanda790f92018-11-07 19:17:151193 for (const auto& rule : ignore_hosts_list) {
Shimi Zhang13eace252020-01-31 01:49:191194 config.proxy_rules().bypass_rules.AddRuleFromString(rule);
[email protected]1a597192010-07-09 16:58:381195 }
[email protected]a8185d02010-06-11 00:19:501196 }
Shimi Zhang13eace252020-01-31 01:49:191197
1198 if (setting_getter_->UseSuffixMatching()) {
1199 RewriteRulesForSuffixMatching(&config.proxy_rules().bypass_rules);
1200 }
1201
[email protected]861c6c62009-04-20 16:50:561202 // Note that there are no settings with semantics corresponding to
[email protected]1a597192010-07-09 16:58:381203 // bypass of local names in GNOME. In KDE, "<local>" is supported
1204 // as a hostname rule.
[email protected]861c6c62009-04-20 16:50:561205
[email protected]a48bf4a2010-06-14 18:24:531206 // KDE allows one to reverse the bypass rules.
Ramin Halavatica8d5252018-03-12 05:33:491207 config.proxy_rules().reverse_bypass = setting_getter_->BypassListIsReversed();
[email protected]a48bf4a2010-06-14 18:24:531208
Ramin Halavatica8d5252018-03-12 05:33:491209 return ProxyConfigWithAnnotation(
1210 config, NetworkTrafficAnnotationTag(traffic_annotation_));
[email protected]861c6c62009-04-20 16:50:561211}
1212
thestig0c412e852016-06-30 08:04:401213ProxyConfigServiceLinux::Delegate::Delegate(
Ramin Halavatica8d5252018-03-12 05:33:491214 std::unique_ptr<base::Environment> env_var_getter,
Anton Bikineev068d2912021-05-15 20:43:521215 absl::optional<std::unique_ptr<SettingGetter>> setting_getter,
1216 absl::optional<NetworkTrafficAnnotationTag> traffic_annotation)
Eric Romancd032fb62018-05-18 21:40:131217 : env_var_getter_(std::move(env_var_getter)) {
1218 if (traffic_annotation) {
1219 traffic_annotation_ =
1220 MutableNetworkTrafficAnnotationTag(traffic_annotation.value());
1221 }
1222
1223 if (setting_getter) {
1224 setting_getter_ = std::move(setting_getter.value());
1225 return;
1226 }
1227
[email protected]573c0502011-05-17 22:19:501228 // Figure out which SettingGetterImpl to use, if any.
thestig0c412e852016-06-30 08:04:401229 switch (base::nix::GetDesktopEnvironment(env_var_getter_.get())) {
Tim Brownd9bd4752017-12-14 20:26:341230 case base::nix::DESKTOP_ENVIRONMENT_CINNAMON:
Xinchao Tianf952aa12022-06-09 21:14:531231 case base::nix::DESKTOP_ENVIRONMENT_DEEPIN:
[email protected]6b0349ef2010-10-16 04:56:061232 case base::nix::DESKTOP_ENVIRONMENT_GNOME:
Tom Andersonac4d6f42017-10-13 20:14:201233 case base::nix::DESKTOP_ENVIRONMENT_PANTHEON:
Xinchao Tianb3ecbfa2022-03-24 04:14:481234 case base::nix::DESKTOP_ENVIRONMENT_UKUI:
[email protected]9e6c9bde2012-07-17 23:40:171235 case base::nix::DESKTOP_ENVIRONMENT_UNITY:
[email protected]8c20e3d2011-05-19 21:03:571236#if defined(USE_GIO)
1237 {
Tsuyoshi Horof8861cb2022-07-05 23:50:201238 auto gs_getter = std::make_unique<SettingGetterImplGSettings>();
danakj8a98ca22016-04-16 02:47:361239 // We have to load symbols and check the GNOME version in use to decide
Tim Brown1c307cc2017-12-08 02:40:381240 // if we should use the gsettings getter. See CheckVersion().
1241 if (gs_getter->CheckVersion(env_var_getter_.get()))
inlinechan894515af2016-12-09 02:40:101242 setting_getter_ = std::move(gs_getter);
[email protected]8c20e3d2011-05-19 21:03:571243 }
1244#endif
[email protected]d7395e732009-08-28 23:13:431245 break;
[email protected]6b0349ef2010-10-16 04:56:061246 case base::nix::DESKTOP_ENVIRONMENT_KDE3:
1247 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
edward.baker53bec302015-10-02 16:57:491248 case base::nix::DESKTOP_ENVIRONMENT_KDE5:
Peter Boström08e7ed82021-04-19 17:49:591249 setting_getter_ =
1250 std::make_unique<SettingGetterImplKDE>(env_var_getter_.get());
[email protected]d7395e732009-08-28 23:13:431251 break;
[email protected]6b0349ef2010-10-16 04:56:061252 case base::nix::DESKTOP_ENVIRONMENT_XFCE:
Tom Andersoncee33d42022-09-08 03:45:311253 case base::nix::DESKTOP_ENVIRONMENT_LXQT:
[email protected]6b0349ef2010-10-16 04:56:061254 case base::nix::DESKTOP_ENVIRONMENT_OTHER:
[email protected]d7395e732009-08-28 23:13:431255 break;
1256 }
1257}
1258
[email protected]d3066142011-05-10 02:36:201259void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig(
sergeyu3f923062014-09-05 01:39:401260 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
Ramin Halavatica8d5252018-03-12 05:33:491261 const scoped_refptr<base::SequencedTaskRunner>& main_task_runner,
1262 const NetworkTrafficAnnotationTag& traffic_annotation) {
1263 traffic_annotation_ = MutableNetworkTrafficAnnotationTag(traffic_annotation);
1264
[email protected]3e44697f2009-05-22 14:37:391265 // We should be running on the default glib main loop thread right
Tim Brown2a19f3b2017-12-12 01:08:401266 // now. gsettings can only be accessed from this thread.
eroman0070d412017-06-22 22:18:241267 DCHECK(glib_task_runner->RunsTasksInCurrentSequence());
sergeyu3f923062014-09-05 01:39:401268 glib_task_runner_ = glib_task_runner;
Matt Menke75765062017-11-21 01:21:161269 main_task_runner_ = main_task_runner;
[email protected]3e44697f2009-05-22 14:37:391270
Matt Menke75765062017-11-21 01:21:161271 // If we are passed a NULL |main_task_runner|, then don't set up proxy
eroman0070d412017-06-22 22:18:241272 // setting change notifications. This should not be the usual case but is
1273 // intended to/ simplify test setups.
Matt Menke75765062017-11-21 01:21:161274 if (!main_task_runner_.get())
[email protected]b30a3f52010-10-16 01:05:461275 VLOG(1) << "Monitoring of proxy setting changes is disabled";
[email protected]3e44697f2009-05-22 14:37:391276
1277 // Fetch and cache the current proxy config. The config is left in
Matt Menke75765062017-11-21 01:21:161278 // cached_config_, where GetLatestProxyConfig() running on the main TaskRunner
[email protected]3e44697f2009-05-22 14:37:391279 // will expect to find it. This is safe to do because we return
1280 // before this ProxyConfigServiceLinux is passed on to
Nicolas Arciniegad2013f92020-02-07 23:00:561281 // the ConfiguredProxyResolutionService.
[email protected]d6cb85b2009-07-23 22:10:531282
1283 // Note: It would be nice to prioritize environment variables
Tim Brown2a19f3b2017-12-12 01:08:401284 // and only fall back to gsettings if env vars were unset. But
[email protected]d6cb85b2009-07-23 22:10:531285 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it
1286 // does so even if the proxy mode is set to auto, which would
1287 // mislead us.
1288
Anton Bikineev068d2912021-05-15 20:43:521289 cached_config_ = absl::nullopt;
Eric Roman750af4b12018-02-22 22:38:531290 if (setting_getter_ && setting_getter_->Init(glib_task_runner)) {
1291 cached_config_ = GetConfigFromSettings();
1292 }
1293 if (cached_config_) {
Ramin Halavatica8d5252018-03-12 05:33:491294 VLOG(1) << "Obtained proxy settings from annotation hash code "
1295 << cached_config_->traffic_annotation().unique_id_hash_code;
[email protected]d3066142011-05-10 02:36:201296
Tim Brown2a19f3b2017-12-12 01:08:401297 // If gsettings proxy mode is "none", meaning direct, then we take
[email protected]d3066142011-05-10 02:36:201298 // that to be a valid config and will not check environment
1299 // variables. The alternative would have been to look for a proxy
Eric Roman750af4b12018-02-22 22:38:531300 // wherever we can find one.
[email protected]d3066142011-05-10 02:36:201301
1302 // Keep a copy of the config for use from this thread for
1303 // comparison with updated settings when we get notifications.
1304 reference_config_ = cached_config_;
[email protected]d3066142011-05-10 02:36:201305
Matt Menke75765062017-11-21 01:21:161306 // We only set up notifications if we have the main and file loops
1307 // available. We do this after getting the initial configuration so that we
1308 // don't have to worry about cancelling it if the initial fetch above fails.
1309 // Note that setting up notifications has the side effect of simulating a
1310 // change, so that we won't lose any updates that may have happened after
1311 // the initial fetch and before setting up notifications. We'll detect the
1312 // common case of no changes in OnCheckProxyConfigSettings() (or sooner) and
1313 // ignore it.
1314 if (main_task_runner.get()) {
eroman0070d412017-06-22 22:18:241315 scoped_refptr<base::SequencedTaskRunner> required_loop =
[email protected]76722472012-05-24 08:26:461316 setting_getter_->GetNotificationTaskRunner();
eroman0070d412017-06-22 22:18:241317 if (!required_loop.get() || required_loop->RunsTasksInCurrentSequence()) {
[email protected]d3066142011-05-10 02:36:201318 // In this case we are already on an acceptable thread.
1319 SetUpNotifications();
[email protected]d7395e732009-08-28 23:13:431320 } else {
[email protected]d3066142011-05-10 02:36:201321 // Post a task to set up notifications. We don't wait for success.
kylecharf4fe5172019-02-15 18:53:491322 required_loop->PostTask(
1323 FROM_HERE,
1324 base::BindOnce(
1325 &ProxyConfigServiceLinux::Delegate::SetUpNotifications, this));
[email protected]d6cb85b2009-07-23 22:10:531326 }
[email protected]d7395e732009-08-28 23:13:431327 }
[email protected]861c6c62009-04-20 16:50:561328 }
[email protected]d6cb85b2009-07-23 22:10:531329
Eric Roman750af4b12018-02-22 22:38:531330 if (!cached_config_) {
[email protected]d6cb85b2009-07-23 22:10:531331 // We fall back on environment variables.
[email protected]3e44697f2009-05-22 14:37:391332 //
[email protected]d3066142011-05-10 02:36:201333 // Consulting environment variables doesn't need to be done from the
1334 // default glib main loop, but it's a tiny enough amount of work.
Eric Roman750af4b12018-02-22 22:38:531335 cached_config_ = GetConfigFromEnv();
1336 if (cached_config_) {
[email protected]b30a3f52010-10-16 01:05:461337 VLOG(1) << "Obtained proxy settings from environment variables";
[email protected]3e44697f2009-05-22 14:37:391338 }
[email protected]861c6c62009-04-20 16:50:561339 }
[email protected]3e44697f2009-05-22 14:37:391340}
1341
[email protected]573c0502011-05-17 22:19:501342// Depending on the SettingGetter in use, this method will be called
Tim Brown2a19f3b2017-12-12 01:08:401343// on either the UI thread (GSettings) or the file thread (KDE).
[email protected]d3066142011-05-10 02:36:201344void ProxyConfigServiceLinux::Delegate::SetUpNotifications() {
eroman0070d412017-06-22 22:18:241345 scoped_refptr<base::SequencedTaskRunner> required_loop =
[email protected]76722472012-05-24 08:26:461346 setting_getter_->GetNotificationTaskRunner();
eroman0070d412017-06-22 22:18:241347 DCHECK(!required_loop.get() || required_loop->RunsTasksInCurrentSequence());
[email protected]573c0502011-05-17 22:19:501348 if (!setting_getter_->SetUpNotifications(this))
[email protected]d3066142011-05-10 02:36:201349 LOG(ERROR) << "Unable to set up proxy configuration change notifications";
1350}
1351
[email protected]119655002010-07-23 06:02:401352void ProxyConfigServiceLinux::Delegate::AddObserver(Observer* observer) {
1353 observers_.AddObserver(observer);
1354}
1355
1356void ProxyConfigServiceLinux::Delegate::RemoveObserver(Observer* observer) {
1357 observers_.RemoveObserver(observer);
1358}
1359
[email protected]3a29593d2011-04-11 10:07:521360ProxyConfigService::ConfigAvailability
Ramin Halavatica8d5252018-03-12 05:33:491361ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig(
1362 ProxyConfigWithAnnotation* config) {
Matt Menke75765062017-11-21 01:21:161363 // This is called from the main TaskRunner.
1364 DCHECK(!main_task_runner_.get() ||
1365 main_task_runner_->RunsTasksInCurrentSequence());
[email protected]3e44697f2009-05-22 14:37:391366
1367 // Simply return the last proxy configuration that glib_default_loop
1368 // notified us of.
Eric Roman750af4b12018-02-22 22:38:531369 *config = GetConfigOrDirect(cached_config_);
[email protected]119655002010-07-23 06:02:401370
[email protected]3a29593d2011-04-11 10:07:521371 // We return CONFIG_VALID to indicate that *config was filled in. It is always
[email protected]119655002010-07-23 06:02:401372 // going to be available since we initialized eagerly on the UI thread.
1373 // TODO(eroman): do lazy initialization instead, so we no longer need
1374 // to construct ProxyConfigServiceLinux on the UI thread.
1375 // In which case, we may return false here.
[email protected]3a29593d2011-04-11 10:07:521376 return CONFIG_VALID;
[email protected]3e44697f2009-05-22 14:37:391377}
1378
[email protected]573c0502011-05-17 22:19:501379// Depending on the SettingGetter in use, this method will be called
Tim Brown2a19f3b2017-12-12 01:08:401380// on either the UI thread (GSettings) or the file thread (KDE).
[email protected]3e44697f2009-05-22 14:37:391381void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() {
eroman0070d412017-06-22 22:18:241382 scoped_refptr<base::SequencedTaskRunner> required_loop =
[email protected]76722472012-05-24 08:26:461383 setting_getter_->GetNotificationTaskRunner();
eroman0070d412017-06-22 22:18:241384 DCHECK(!required_loop.get() || required_loop->RunsTasksInCurrentSequence());
Anton Bikineev068d2912021-05-15 20:43:521385 absl::optional<ProxyConfigWithAnnotation> new_config =
Ramin Halavatica8d5252018-03-12 05:33:491386 GetConfigFromSettings();
[email protected]3e44697f2009-05-22 14:37:391387
[email protected]119655002010-07-23 06:02:401388 // See if it is different from what we had before.
Eric Roman750af4b12018-02-22 22:38:531389 if (new_config.has_value() != reference_config_.has_value() ||
Eric Roman3e185842018-06-01 18:10:521390 (new_config.has_value() &&
1391 !new_config->value().Equals(reference_config_->value()))) {
Matt Menke75765062017-11-21 01:21:161392 // Post a task to the main TaskRunner with the new configuration, so it can
[email protected]3e44697f2009-05-22 14:37:391393 // update |cached_config_|.
Matt Menke75765062017-11-21 01:21:161394 main_task_runner_->PostTask(
1395 FROM_HERE,
kylecharf4fe5172019-02-15 18:53:491396 base::BindOnce(&ProxyConfigServiceLinux::Delegate::SetNewProxyConfig,
1397 this, new_config));
[email protected]d1f9d472009-08-13 19:59:301398 // Update the thread-private copy in |reference_config_| as well.
1399 reference_config_ = new_config;
[email protected]d3066142011-05-10 02:36:201400 } else {
1401 VLOG(1) << "Detected no-op change to proxy settings. Doing nothing.";
[email protected]3e44697f2009-05-22 14:37:391402 }
1403}
1404
1405void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig(
Anton Bikineev068d2912021-05-15 20:43:521406 const absl::optional<ProxyConfigWithAnnotation>& new_config) {
Matt Menke75765062017-11-21 01:21:161407 DCHECK(main_task_runner_->RunsTasksInCurrentSequence());
[email protected]b30a3f52010-10-16 01:05:461408 VLOG(1) << "Proxy configuration changed";
[email protected]3e44697f2009-05-22 14:37:391409 cached_config_ = new_config;
Eric Roman750af4b12018-02-22 22:38:531410 for (auto& observer : observers_) {
1411 observer.OnProxyConfigChanged(GetConfigOrDirect(new_config),
1412 ProxyConfigService::CONFIG_VALID);
1413 }
[email protected]3e44697f2009-05-22 14:37:391414}
1415
1416void ProxyConfigServiceLinux::Delegate::PostDestroyTask() {
thestig0c412e852016-06-30 08:04:401417 if (!setting_getter_)
[email protected]d7395e732009-08-28 23:13:431418 return;
thestig0c412e852016-06-30 08:04:401419
eroman0070d412017-06-22 22:18:241420 scoped_refptr<base::SequencedTaskRunner> shutdown_loop =
[email protected]76722472012-05-24 08:26:461421 setting_getter_->GetNotificationTaskRunner();
eroman0070d412017-06-22 22:18:241422 if (!shutdown_loop.get() || shutdown_loop->RunsTasksInCurrentSequence()) {
[email protected]3e44697f2009-05-22 14:37:391423 // Already on the right thread, call directly.
1424 // This is the case for the unittests.
1425 OnDestroy();
1426 } else {
[email protected]d7395e732009-08-28 23:13:431427 // Post to shutdown thread. Note that on browser shutdown, we may quit
1428 // this MessageLoop and exit the program before ever running this.
kylecharf4fe5172019-02-15 18:53:491429 shutdown_loop->PostTask(
1430 FROM_HERE,
1431 base::BindOnce(&ProxyConfigServiceLinux::Delegate::OnDestroy, this));
[email protected]3e44697f2009-05-22 14:37:391432 }
1433}
1434void ProxyConfigServiceLinux::Delegate::OnDestroy() {
eroman0070d412017-06-22 22:18:241435 scoped_refptr<base::SequencedTaskRunner> shutdown_loop =
[email protected]76722472012-05-24 08:26:461436 setting_getter_->GetNotificationTaskRunner();
eroman0070d412017-06-22 22:18:241437 DCHECK(!shutdown_loop.get() || shutdown_loop->RunsTasksInCurrentSequence());
[email protected]573c0502011-05-17 22:19:501438 setting_getter_->ShutDown();
[email protected]3e44697f2009-05-22 14:37:391439}
1440
1441ProxyConfigServiceLinux::ProxyConfigServiceLinux()
Tsuyoshi Horo2c0a5042022-07-06 05:53:071442 : delegate_(base::MakeRefCounted<Delegate>(base::Environment::Create(),
1443 absl::nullopt,
1444 absl::nullopt)) {}
[email protected]3e44697f2009-05-22 14:37:391445
[email protected]8e1845e12010-09-15 19:22:241446ProxyConfigServiceLinux::~ProxyConfigServiceLinux() {
1447 delegate_->PostDestroyTask();
1448}
1449
[email protected]3e44697f2009-05-22 14:37:391450ProxyConfigServiceLinux::ProxyConfigServiceLinux(
Ramin Halavatica8d5252018-03-12 05:33:491451 std::unique_ptr<base::Environment> env_var_getter,
1452 const NetworkTrafficAnnotationTag& traffic_annotation)
Tsuyoshi Horo2c0a5042022-07-06 05:53:071453 : delegate_(base::MakeRefCounted<Delegate>(std::move(env_var_getter),
1454 absl::nullopt,
1455 traffic_annotation)) {}
[email protected]9a3d8d42009-09-03 17:01:461456
1457ProxyConfigServiceLinux::ProxyConfigServiceLinux(
thestig0c412e852016-06-30 08:04:401458 std::unique_ptr<base::Environment> env_var_getter,
Tsuyoshi Horo5f63d342022-07-11 02:00:471459 std::unique_ptr<SettingGetter> setting_getter,
Ramin Halavatica8d5252018-03-12 05:33:491460 const NetworkTrafficAnnotationTag& traffic_annotation)
Tsuyoshi Horo2c0a5042022-07-06 05:53:071461 : delegate_(base::MakeRefCounted<Delegate>(std::move(env_var_getter),
Tsuyoshi Horo5f63d342022-07-11 02:00:471462 std::move(setting_getter),
Tsuyoshi Horo2c0a5042022-07-06 05:53:071463 traffic_annotation)) {}
[email protected]861c6c62009-04-20 16:50:561464
[email protected]e4be2dd2010-12-14 00:44:391465void ProxyConfigServiceLinux::AddObserver(Observer* observer) {
1466 delegate_->AddObserver(observer);
1467}
1468
1469void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) {
1470 delegate_->RemoveObserver(observer);
1471}
1472
[email protected]3a29593d2011-04-11 10:07:521473ProxyConfigService::ConfigAvailability
Ramin Halavatica8d5252018-03-12 05:33:491474ProxyConfigServiceLinux::GetLatestProxyConfig(
1475 ProxyConfigWithAnnotation* config) {
[email protected]e4be2dd2010-12-14 00:44:391476 return delegate_->GetLatestProxyConfig(config);
1477}
1478
[email protected]861c6c62009-04-20 16:50:561479} // namespace net