| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/linux_util.h" | 12 #include "base/env_var.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
| 15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 16 #include "net/proxy/proxy_config.h" | 16 #include "net/proxy/proxy_config.h" |
| 17 #include "net/proxy/proxy_config_service.h" | 17 #include "net/proxy/proxy_config_service.h" |
| 18 #include "net/proxy/proxy_server.h" | 18 #include "net/proxy/proxy_server.h" |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| 22 // Implementation of ProxyConfigService that retrieves the system proxy | 22 // Implementation of ProxyConfigService that retrieves the system proxy |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // The substance of the ProxyConfigServiceLinux implementation is | 98 // The substance of the ProxyConfigServiceLinux implementation is |
| 99 // wrapped in the Delegate ref counted class. On deleting the | 99 // wrapped in the Delegate ref counted class. On deleting the |
| 100 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to the | 100 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to the |
| 101 // UI thread where gconf notifications will be safely stopped before | 101 // UI thread where gconf notifications will be safely stopped before |
| 102 // releasing Delegate. | 102 // releasing Delegate. |
| 103 | 103 |
| 104 class Delegate : public base::RefCountedThreadSafe<Delegate> { | 104 class Delegate : public base::RefCountedThreadSafe<Delegate> { |
| 105 public: | 105 public: |
| 106 // Constructor receives env var getter implementation to use, and | 106 // Constructor receives env var getter implementation to use, and |
| 107 // takes ownership of it. This is the normal constructor. | 107 // takes ownership of it. This is the normal constructor. |
| 108 explicit Delegate(base::EnvironmentVariableGetter* env_var_getter); | 108 explicit Delegate(base::EnvVarGetter* env_var_getter); |
| 109 // Constructor receives gconf and env var getter implementations | 109 // Constructor receives gconf and env var getter implementations |
| 110 // to use, and takes ownership of them. Used for testing. | 110 // to use, and takes ownership of them. Used for testing. |
| 111 Delegate(base::EnvironmentVariableGetter* env_var_getter, | 111 Delegate(base::EnvVarGetter* env_var_getter, |
| 112 GConfSettingGetter* gconf_getter); | 112 GConfSettingGetter* gconf_getter); |
| 113 // Synchronously obtains the proxy configuration. If gconf is | 113 // Synchronously obtains the proxy configuration. If gconf is |
| 114 // used, also enables gconf notification for setting | 114 // used, also enables gconf notification for setting |
| 115 // changes. gconf must only be accessed from the thread running | 115 // changes. gconf must only be accessed from the thread running |
| 116 // the default glib main loop, and so this method must be called | 116 // the default glib main loop, and so this method must be called |
| 117 // from the UI thread. The message loop for the IO thread is | 117 // from the UI thread. The message loop for the IO thread is |
| 118 // specified so that notifications can post tasks to it (and for | 118 // specified so that notifications can post tasks to it (and for |
| 119 // assertions). The message loop for the file thread is used to | 119 // assertions). The message loop for the file thread is used to |
| 120 // read any files needed to determine proxy settings. | 120 // read any files needed to determine proxy settings. |
| 121 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, | 121 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 bool GetProxyFromGConf(const char* key_prefix, bool is_socks, | 161 bool GetProxyFromGConf(const char* key_prefix, bool is_socks, |
| 162 ProxyServer* result_server); | 162 ProxyServer* result_server); |
| 163 // Fills proxy config from gconf. Returns true if settings were found | 163 // Fills proxy config from gconf. Returns true if settings were found |
| 164 // and the configuration is valid. | 164 // and the configuration is valid. |
| 165 bool GetConfigFromGConf(ProxyConfig* config); | 165 bool GetConfigFromGConf(ProxyConfig* config); |
| 166 | 166 |
| 167 // This method is posted from the UI thread to the IO thread to | 167 // This method is posted from the UI thread to the IO thread to |
| 168 // carry the new config information. | 168 // carry the new config information. |
| 169 void SetNewProxyConfig(const ProxyConfig& new_config); | 169 void SetNewProxyConfig(const ProxyConfig& new_config); |
| 170 | 170 |
| 171 scoped_ptr<base::EnvironmentVariableGetter> env_var_getter_; | 171 scoped_ptr<base::EnvVarGetter> env_var_getter_; |
| 172 scoped_ptr<GConfSettingGetter> gconf_getter_; | 172 scoped_ptr<GConfSettingGetter> gconf_getter_; |
| 173 | 173 |
| 174 // Cached proxy configuration, to be returned by | 174 // Cached proxy configuration, to be returned by |
| 175 // GetProxyConfig. Initially populated from the UI thread, but | 175 // GetProxyConfig. Initially populated from the UI thread, but |
| 176 // afterwards only accessed from the IO thread. | 176 // afterwards only accessed from the IO thread. |
| 177 ProxyConfig cached_config_; | 177 ProxyConfig cached_config_; |
| 178 | 178 |
| 179 // A copy kept on the UI thread of the last seen proxy config, so as | 179 // A copy kept on the UI thread of the last seen proxy config, so as |
| 180 // to avoid posting a call to SetNewProxyConfig when we get a | 180 // to avoid posting a call to SetNewProxyConfig when we get a |
| 181 // notification but the config has not actually changed. | 181 // notification but the config has not actually changed. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 196 MessageLoop* io_loop_; | 196 MessageLoop* io_loop_; |
| 197 | 197 |
| 198 DISALLOW_COPY_AND_ASSIGN(Delegate); | 198 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 // Thin wrapper shell around Delegate. | 201 // Thin wrapper shell around Delegate. |
| 202 | 202 |
| 203 // Usual constructor | 203 // Usual constructor |
| 204 ProxyConfigServiceLinux(); | 204 ProxyConfigServiceLinux(); |
| 205 // For testing: take alternate gconf and env var getter implementations. | 205 // For testing: take alternate gconf and env var getter implementations. |
| 206 explicit ProxyConfigServiceLinux( | 206 explicit ProxyConfigServiceLinux(base::EnvVarGetter* env_var_getter); |
| 207 base::EnvironmentVariableGetter* env_var_getter); | 207 ProxyConfigServiceLinux(base::EnvVarGetter* env_var_getter, |
| 208 ProxyConfigServiceLinux(base::EnvironmentVariableGetter* env_var_getter, | |
| 209 GConfSettingGetter* gconf_getter); | 208 GConfSettingGetter* gconf_getter); |
| 210 | 209 |
| 211 virtual ~ProxyConfigServiceLinux() { | 210 virtual ~ProxyConfigServiceLinux() { |
| 212 delegate_->PostDestroyTask(); | 211 delegate_->PostDestroyTask(); |
| 213 } | 212 } |
| 214 | 213 |
| 215 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, | 214 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, |
| 216 MessageLoop* io_loop, | 215 MessageLoop* io_loop, |
| 217 MessageLoopForIO* file_loop) { | 216 MessageLoopForIO* file_loop) { |
| 218 delegate_->SetupAndFetchInitialConfig(glib_default_loop, io_loop, | 217 delegate_->SetupAndFetchInitialConfig(glib_default_loop, io_loop, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 230 | 229 |
| 231 private: | 230 private: |
| 232 scoped_refptr<Delegate> delegate_; | 231 scoped_refptr<Delegate> delegate_; |
| 233 | 232 |
| 234 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); | 233 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); |
| 235 }; | 234 }; |
| 236 | 235 |
| 237 } // namespace net | 236 } // namespace net |
| 238 | 237 |
| 239 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ | 238 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ |
| OLD | NEW |