#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/proxy_resolution/proxy_config_service_linux.h"
#include <errno.h>
#include <limits.h>
#include <sys/inotify.h>
#include <unistd.h>
#include <map>
#include <memory>
#include <utility>
#include "base/files/file_descriptor_watcher_posix.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/nix/xdg_util.h"
#include "base/observer_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/threading/thread_restrictions.h"
#include "base/timer/timer.h"
#include "net/base/proxy_server.h"
#include "net/base/proxy_string_util.h"
#if defined(USE_GIO)
#include <gio/gio.h>
#endif
namespace net {
class ScopedAllowBlockingForSettingGetter : public base::ScopedAllowBlocking { … };
namespace {
void RewriteRulesForSuffixMatching(ProxyBypassRules* out) { … }
std::string FixupProxyHostScheme(ProxyServer::Scheme scheme,
std::string host) { … }
ProxyConfigWithAnnotation GetConfigOrDirect(
const std::optional<ProxyConfigWithAnnotation>& optional_config) { … }
}
ProxyConfigServiceLinux::Delegate::~Delegate() = default;
bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme(
std::string_view variable,
ProxyServer::Scheme scheme,
ProxyChain* result_chain) { … }
bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVar(
std::string_view variable,
ProxyChain* result_chain) { … }
std::optional<ProxyConfigWithAnnotation>
ProxyConfigServiceLinux::Delegate::GetConfigFromEnv() { … }
namespace {
const int kDebounceTimeoutMilliseconds = …;
#if defined(USE_GIO)
const char kProxyGSettingsSchema[] = …;
class SettingGetterImplGSettings
: public ProxyConfigServiceLinux::SettingGetter { … };
bool SettingGetterImplGSettings::CheckVersion(
base::Environment* env) { … }
#endif
int StringToIntOrDefault(std::string_view value, int default_value) { … }
class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter { … };
}
bool ProxyConfigServiceLinux::Delegate::GetProxyFromSettings(
SettingGetter::StringSetting host_key,
ProxyServer* result_server) { … }
std::optional<ProxyConfigWithAnnotation>
ProxyConfigServiceLinux::Delegate::GetConfigFromSettings() { … }
ProxyConfigServiceLinux::Delegate::Delegate(
std::unique_ptr<base::Environment> env_var_getter,
std::optional<std::unique_ptr<SettingGetter>> setting_getter,
std::optional<NetworkTrafficAnnotationTag> traffic_annotation)
: … { … }
void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig(
const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
const scoped_refptr<base::SequencedTaskRunner>& main_task_runner,
const NetworkTrafficAnnotationTag& traffic_annotation) { … }
void ProxyConfigServiceLinux::Delegate::SetUpNotifications() { … }
void ProxyConfigServiceLinux::Delegate::AddObserver(Observer* observer) { … }
void ProxyConfigServiceLinux::Delegate::RemoveObserver(Observer* observer) { … }
ProxyConfigService::ConfigAvailability
ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig(
ProxyConfigWithAnnotation* config) { … }
void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() { … }
void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig(
const std::optional<ProxyConfigWithAnnotation>& new_config) { … }
void ProxyConfigServiceLinux::Delegate::PostDestroyTask() { … }
void ProxyConfigServiceLinux::Delegate::OnDestroy() { … }
ProxyConfigServiceLinux::ProxyConfigServiceLinux()
: … { … }
ProxyConfigServiceLinux::~ProxyConfigServiceLinux() { … }
ProxyConfigServiceLinux::ProxyConfigServiceLinux(
std::unique_ptr<base::Environment> env_var_getter,
const NetworkTrafficAnnotationTag& traffic_annotation)
: … { … }
ProxyConfigServiceLinux::ProxyConfigServiceLinux(
std::unique_ptr<base::Environment> env_var_getter,
std::unique_ptr<SettingGetter> setting_getter,
const NetworkTrafficAnnotationTag& traffic_annotation)
: … { … }
void ProxyConfigServiceLinux::AddObserver(Observer* observer) { … }
void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { … }
ProxyConfigService::ConfigAvailability
ProxyConfigServiceLinux::GetLatestProxyConfig(
ProxyConfigWithAnnotation* config) { … }
}