| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ | 5 #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ |
| 6 #define NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ | 6 #define NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace base { | 24 namespace base { |
| 25 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
| 26 } // namespace base | 26 } // namespace base |
| 27 | 27 |
| 28 namespace net { | 28 namespace net { |
| 29 | 29 |
| 30 // Implementation of ProxyConfigService that retrieves the system proxy | 30 // Implementation of ProxyConfigService that retrieves the system proxy |
| 31 // settings from environment variables, gconf, gsettings, or kioslaverc (KDE). | 31 // settings from environment variables, gconf, gsettings, or kioslaverc (KDE). |
| 32 class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { | 32 class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { |
| 33 public: | 33 public: |
| 34 | |
| 35 // Forward declaration of Delegate. | |
| 36 class Delegate; | 34 class Delegate; |
| 37 | 35 |
| 38 class SettingGetter { | 36 class SettingGetter { |
| 39 public: | 37 public: |
| 40 // Buffer size used in some implementations of this class when reading | 38 // Buffer size used in some implementations of this class when reading |
| 41 // files. Defined here so unit tests can construct worst-case inputs. | 39 // files. Defined here so unit tests can construct worst-case inputs. |
| 42 static const size_t BUFFER_SIZE = 512; | 40 static const size_t BUFFER_SIZE = 512; |
| 43 | 41 |
| 44 SettingGetter() {} | 42 SettingGetter() {} |
| 45 virtual ~SettingGetter() {} | 43 virtual ~SettingGetter() {} |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // ProxyConfigServiceLinux is deleted from the IO thread. | 159 // ProxyConfigServiceLinux is deleted from the IO thread. |
| 162 // | 160 // |
| 163 // The substance of the ProxyConfigServiceLinux implementation is | 161 // The substance of the ProxyConfigServiceLinux implementation is |
| 164 // wrapped in the Delegate ref counted class. On deleting the | 162 // wrapped in the Delegate ref counted class. On deleting the |
| 165 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to either | 163 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to either |
| 166 // the UI thread (gconf/gsettings) or the file thread (KDE) where change | 164 // the UI thread (gconf/gsettings) or the file thread (KDE) where change |
| 167 // notifications will be safely stopped before releasing Delegate. | 165 // notifications will be safely stopped before releasing Delegate. |
| 168 | 166 |
| 169 class Delegate : public base::RefCountedThreadSafe<Delegate> { | 167 class Delegate : public base::RefCountedThreadSafe<Delegate> { |
| 170 public: | 168 public: |
| 171 // Constructor receives env var getter implementation to use, and | 169 // Normal constructor. |
| 172 // takes ownership of it. This is the normal constructor. | 170 explicit Delegate(std::unique_ptr<base::Environment> env_var_getter); |
| 173 explicit Delegate(base::Environment* env_var_getter); | 171 |
| 174 // Constructor receives setting and env var getter implementations | 172 // Constructor for testing. |
| 175 // to use, and takes ownership of them. Used for testing. | 173 Delegate(std::unique_ptr<base::Environment> env_var_getter, |
| 176 Delegate(base::Environment* env_var_getter, SettingGetter* setting_getter); | 174 SettingGetter* setting_getter); |
| 177 | 175 |
| 178 // Synchronously obtains the proxy configuration. If gconf, | 176 // Synchronously obtains the proxy configuration. If gconf, |
| 179 // gsettings, or kioslaverc are used, also enables notifications for | 177 // gsettings, or kioslaverc are used, also enables notifications for |
| 180 // setting changes. gconf/gsettings must only be accessed from the | 178 // setting changes. gconf/gsettings must only be accessed from the |
| 181 // thread running the default glib main loop, and so this method | 179 // thread running the default glib main loop, and so this method |
| 182 // must be called from the UI thread. The message loop for the IO | 180 // must be called from the UI thread. The message loop for the IO |
| 183 // thread is specified so that notifications can post tasks to it | 181 // thread is specified so that notifications can post tasks to it |
| 184 // (and for assertions). The message loop for the file thread is | 182 // (and for assertions). The message loop for the file thread is |
| 185 // used to read any files needed to determine proxy settings. | 183 // used to read any files needed to determine proxy settings. |
| 186 void SetUpAndFetchInitialConfig( | 184 void SetUpAndFetchInitialConfig( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 209 void OnDestroy(); | 207 void OnDestroy(); |
| 210 | 208 |
| 211 private: | 209 private: |
| 212 friend class base::RefCountedThreadSafe<Delegate>; | 210 friend class base::RefCountedThreadSafe<Delegate>; |
| 213 | 211 |
| 214 ~Delegate(); | 212 ~Delegate(); |
| 215 | 213 |
| 216 // Obtains an environment variable's value. Parses a proxy server | 214 // Obtains an environment variable's value. Parses a proxy server |
| 217 // specification from it and puts it in result. Returns true if the | 215 // specification from it and puts it in result. Returns true if the |
| 218 // requested variable is defined and the value valid. | 216 // requested variable is defined and the value valid. |
| 219 bool GetProxyFromEnvVarForScheme(const char* variable, | 217 bool GetProxyFromEnvVarForScheme(base::StringPiece variable, |
| 220 ProxyServer::Scheme scheme, | 218 ProxyServer::Scheme scheme, |
| 221 ProxyServer* result_server); | 219 ProxyServer* result_server); |
| 222 // As above but with scheme set to HTTP, for convenience. | 220 // As above but with scheme set to HTTP, for convenience. |
| 223 bool GetProxyFromEnvVar(const char* variable, ProxyServer* result_server); | 221 bool GetProxyFromEnvVar(base::StringPiece variable, |
| 222 ProxyServer* result_server); |
| 224 // Fills proxy config from environment variables. Returns true if | 223 // Fills proxy config from environment variables. Returns true if |
| 225 // variables were found and the configuration is valid. | 224 // variables were found and the configuration is valid. |
| 226 bool GetConfigFromEnv(ProxyConfig* config); | 225 bool GetConfigFromEnv(ProxyConfig* config); |
| 227 | 226 |
| 228 // Obtains host and port config settings and parses a proxy server | 227 // Obtains host and port config settings and parses a proxy server |
| 229 // specification from it and puts it in result. Returns true if the | 228 // specification from it and puts it in result. Returns true if the |
| 230 // requested variable is defined and the value valid. | 229 // requested variable is defined and the value valid. |
| 231 bool GetProxyFromSettings(SettingGetter::StringSetting host_key, | 230 bool GetProxyFromSettings(SettingGetter::StringSetting host_key, |
| 232 ProxyServer* result_server); | 231 ProxyServer* result_server); |
| 233 // Fills proxy config from settings. Returns true if settings were found | 232 // Fills proxy config from settings. Returns true if settings were found |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 269 |
| 271 base::ObserverList<Observer> observers_; | 270 base::ObserverList<Observer> observers_; |
| 272 | 271 |
| 273 DISALLOW_COPY_AND_ASSIGN(Delegate); | 272 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 274 }; | 273 }; |
| 275 | 274 |
| 276 // Thin wrapper shell around Delegate. | 275 // Thin wrapper shell around Delegate. |
| 277 | 276 |
| 278 // Usual constructor | 277 // Usual constructor |
| 279 ProxyConfigServiceLinux(); | 278 ProxyConfigServiceLinux(); |
| 279 |
| 280 // For testing: take alternate setting and env var getter implementations. | 280 // For testing: take alternate setting and env var getter implementations. |
| 281 explicit ProxyConfigServiceLinux(base::Environment* env_var_getter); | 281 explicit ProxyConfigServiceLinux( |
| 282 ProxyConfigServiceLinux(base::Environment* env_var_getter, | 282 std::unique_ptr<base::Environment> env_var_getter); |
| 283 ProxyConfigServiceLinux(std::unique_ptr<base::Environment> env_var_getter, |
| 283 SettingGetter* setting_getter); | 284 SettingGetter* setting_getter); |
| 284 | 285 |
| 285 ~ProxyConfigServiceLinux() override; | 286 ~ProxyConfigServiceLinux() override; |
| 286 | 287 |
| 287 void SetupAndFetchInitialConfig( | 288 void SetupAndFetchInitialConfig( |
| 288 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, | 289 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, |
| 289 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 290 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 290 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { | 291 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { |
| 291 delegate_->SetUpAndFetchInitialConfig(glib_task_runner, | 292 delegate_->SetUpAndFetchInitialConfig(glib_task_runner, |
| 292 io_task_runner, | 293 io_task_runner, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 305 | 306 |
| 306 private: | 307 private: |
| 307 scoped_refptr<Delegate> delegate_; | 308 scoped_refptr<Delegate> delegate_; |
| 308 | 309 |
| 309 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); | 310 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); |
| 310 }; | 311 }; |
| 311 | 312 |
| 312 } // namespace net | 313 } // namespace net |
| 313 | 314 |
| 314 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ | 315 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ |
| OLD | NEW |