OLD | NEW |
1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/env_var.h" | 13 #include "base/environment.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/ref_counted.h" | 16 #include "base/ref_counted.h" |
17 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
18 #include "net/proxy/proxy_config.h" | 18 #include "net/proxy/proxy_config.h" |
19 #include "net/proxy/proxy_config_service.h" | 19 #include "net/proxy/proxy_config_service.h" |
20 #include "net/proxy/proxy_server.h" | 20 #include "net/proxy/proxy_server.h" |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 | 23 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // The substance of the ProxyConfigServiceLinux implementation is | 110 // The substance of the ProxyConfigServiceLinux implementation is |
111 // wrapped in the Delegate ref counted class. On deleting the | 111 // wrapped in the Delegate ref counted class. On deleting the |
112 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to the | 112 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to the |
113 // UI thread where gconf notifications will be safely stopped before | 113 // UI thread where gconf notifications will be safely stopped before |
114 // releasing Delegate. | 114 // releasing Delegate. |
115 | 115 |
116 class Delegate : public base::RefCountedThreadSafe<Delegate> { | 116 class Delegate : public base::RefCountedThreadSafe<Delegate> { |
117 public: | 117 public: |
118 // Constructor receives env var getter implementation to use, and | 118 // Constructor receives env var getter implementation to use, and |
119 // takes ownership of it. This is the normal constructor. | 119 // takes ownership of it. This is the normal constructor. |
120 explicit Delegate(base::EnvVarGetter* env_var_getter); | 120 explicit Delegate(base::Environment* env_var_getter); |
121 // Constructor receives gconf and env var getter implementations | 121 // Constructor receives gconf and env var getter implementations |
122 // to use, and takes ownership of them. Used for testing. | 122 // to use, and takes ownership of them. Used for testing. |
123 Delegate(base::EnvVarGetter* env_var_getter, | 123 Delegate(base::Environment* env_var_getter, |
124 GConfSettingGetter* gconf_getter); | 124 GConfSettingGetter* gconf_getter); |
125 // Synchronously obtains the proxy configuration. If gconf is | 125 // Synchronously obtains the proxy configuration. If gconf is |
126 // used, also enables gconf notification for setting | 126 // used, also enables gconf notification for setting |
127 // changes. gconf must only be accessed from the thread running | 127 // changes. gconf must only be accessed from the thread running |
128 // the default glib main loop, and so this method must be called | 128 // the default glib main loop, and so this method must be called |
129 // from the UI thread. The message loop for the IO thread is | 129 // from the UI thread. The message loop for the IO thread is |
130 // specified so that notifications can post tasks to it (and for | 130 // specified so that notifications can post tasks to it (and for |
131 // assertions). The message loop for the file thread is used to | 131 // assertions). The message loop for the file thread is used to |
132 // read any files needed to determine proxy settings. | 132 // read any files needed to determine proxy settings. |
133 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, | 133 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 bool GetProxyFromGConf(const char* key_prefix, bool is_socks, | 175 bool GetProxyFromGConf(const char* key_prefix, bool is_socks, |
176 ProxyServer* result_server); | 176 ProxyServer* result_server); |
177 // Fills proxy config from gconf. Returns true if settings were found | 177 // Fills proxy config from gconf. Returns true if settings were found |
178 // and the configuration is valid. | 178 // and the configuration is valid. |
179 bool GetConfigFromGConf(ProxyConfig* config); | 179 bool GetConfigFromGConf(ProxyConfig* config); |
180 | 180 |
181 // This method is posted from the UI thread to the IO thread to | 181 // This method is posted from the UI thread to the IO thread to |
182 // carry the new config information. | 182 // carry the new config information. |
183 void SetNewProxyConfig(const ProxyConfig& new_config); | 183 void SetNewProxyConfig(const ProxyConfig& new_config); |
184 | 184 |
185 scoped_ptr<base::EnvVarGetter> env_var_getter_; | 185 scoped_ptr<base::Environment> env_var_getter_; |
186 scoped_ptr<GConfSettingGetter> gconf_getter_; | 186 scoped_ptr<GConfSettingGetter> gconf_getter_; |
187 | 187 |
188 // Cached proxy configuration, to be returned by | 188 // Cached proxy configuration, to be returned by |
189 // GetLatestProxyConfig. Initially populated from the UI thread, but | 189 // GetLatestProxyConfig. Initially populated from the UI thread, but |
190 // afterwards only accessed from the IO thread. | 190 // afterwards only accessed from the IO thread. |
191 ProxyConfig cached_config_; | 191 ProxyConfig cached_config_; |
192 | 192 |
193 // A copy kept on the UI thread of the last seen proxy config, so as | 193 // A copy kept on the UI thread of the last seen proxy config, so as |
194 // to avoid posting a call to SetNewProxyConfig when we get a | 194 // to avoid posting a call to SetNewProxyConfig when we get a |
195 // notification but the config has not actually changed. | 195 // notification but the config has not actually changed. |
(...skipping 16 matching lines...) Expand all Loading... |
212 ObserverList<Observer> observers_; | 212 ObserverList<Observer> observers_; |
213 | 213 |
214 DISALLOW_COPY_AND_ASSIGN(Delegate); | 214 DISALLOW_COPY_AND_ASSIGN(Delegate); |
215 }; | 215 }; |
216 | 216 |
217 // Thin wrapper shell around Delegate. | 217 // Thin wrapper shell around Delegate. |
218 | 218 |
219 // Usual constructor | 219 // Usual constructor |
220 ProxyConfigServiceLinux(); | 220 ProxyConfigServiceLinux(); |
221 // For testing: take alternate gconf and env var getter implementations. | 221 // For testing: take alternate gconf and env var getter implementations. |
222 explicit ProxyConfigServiceLinux(base::EnvVarGetter* env_var_getter); | 222 explicit ProxyConfigServiceLinux(base::Environment* env_var_getter); |
223 ProxyConfigServiceLinux(base::EnvVarGetter* env_var_getter, | 223 ProxyConfigServiceLinux(base::Environment* env_var_getter, |
224 GConfSettingGetter* gconf_getter); | 224 GConfSettingGetter* gconf_getter); |
225 | 225 |
226 virtual ~ProxyConfigServiceLinux() { | 226 virtual ~ProxyConfigServiceLinux() { |
227 delegate_->PostDestroyTask(); | 227 delegate_->PostDestroyTask(); |
228 } | 228 } |
229 | 229 |
230 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, | 230 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, |
231 MessageLoop* io_loop, | 231 MessageLoop* io_loop, |
232 MessageLoopForIO* file_loop) { | 232 MessageLoopForIO* file_loop) { |
233 delegate_->SetupAndFetchInitialConfig(glib_default_loop, io_loop, | 233 delegate_->SetupAndFetchInitialConfig(glib_default_loop, io_loop, |
(...skipping 20 matching lines...) Expand all Loading... |
254 | 254 |
255 private: | 255 private: |
256 scoped_refptr<Delegate> delegate_; | 256 scoped_refptr<Delegate> delegate_; |
257 | 257 |
258 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); | 258 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); |
259 }; | 259 }; |
260 | 260 |
261 } // namespace net | 261 } // namespace net |
262 | 262 |
263 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ | 263 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ |
OLD | NEW |