OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/environment.h" | 14 #include "base/environment.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop.h" | |
18 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
19 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
20 #include "net/proxy/proxy_config.h" | 19 #include "net/proxy/proxy_config.h" |
21 #include "net/proxy/proxy_config_service.h" | 20 #include "net/proxy/proxy_config_service.h" |
22 #include "net/proxy/proxy_server.h" | 21 #include "net/proxy/proxy_server.h" |
23 | 22 |
| 23 class MessageLoopForIO; |
| 24 |
| 25 namespace base { |
| 26 class MessageLoopProxy; |
| 27 } // namespace base |
| 28 |
24 namespace net { | 29 namespace net { |
25 | 30 |
26 // Implementation of ProxyConfigService that retrieves the system proxy | 31 // Implementation of ProxyConfigService that retrieves the system proxy |
27 // settings from environment variables, gconf, gsettings, or kioslaverc (KDE). | 32 // settings from environment variables, gconf, gsettings, or kioslaverc (KDE). |
28 class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { | 33 class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { |
29 public: | 34 public: |
30 | 35 |
31 // Forward declaration of Delegate. | 36 // Forward declaration of Delegate. |
32 class Delegate; | 37 class Delegate; |
33 | 38 |
34 class SettingGetter { | 39 class SettingGetter { |
35 public: | 40 public: |
36 // Buffer size used in some implementations of this class when reading | 41 // Buffer size used in some implementations of this class when reading |
37 // files. Defined here so unit tests can construct worst-case inputs. | 42 // files. Defined here so unit tests can construct worst-case inputs. |
38 static const size_t BUFFER_SIZE = 512; | 43 static const size_t BUFFER_SIZE = 512; |
39 | 44 |
40 SettingGetter() {} | 45 SettingGetter() {} |
41 virtual ~SettingGetter() {} | 46 virtual ~SettingGetter() {} |
42 | 47 |
43 // Initializes the class: obtains a gconf/gsettings client, or simulates | 48 // Initializes the class: obtains a gconf/gsettings client, or simulates |
44 // one, in the concrete implementations. Returns true on success. Must be | 49 // one, in the concrete implementations. Returns true on success. Must be |
45 // called before using other methods, and should be called on the thread | 50 // called before using other methods, and should be called on the thread |
46 // running the glib main loop. | 51 // running the glib main loop. |
47 // One of |glib_default_loop| and |file_loop| will be used for | 52 // One of |glib_default_loop| and |file_loop| will be used for |
48 // gconf/gsettings calls or reading necessary files, depending on the | 53 // gconf/gsettings calls or reading necessary files, depending on the |
49 // implementation. | 54 // implementation. |
50 virtual bool Init(MessageLoop* glib_default_loop, | 55 virtual bool Init(base::MessageLoopProxy* glib_default_loop, |
51 MessageLoopForIO* file_loop) = 0; | 56 MessageLoopForIO* file_loop) = 0; |
52 | 57 |
53 // Releases the gconf/gsettings client, which clears cached directories and | 58 // Releases the gconf/gsettings client, which clears cached directories and |
54 // stops notifications. | 59 // stops notifications. |
55 virtual void ShutDown() = 0; | 60 virtual void ShutDown() = 0; |
56 | 61 |
57 // Requests notification of gconf/gsettings changes for proxy | 62 // Requests notification of gconf/gsettings changes for proxy |
58 // settings. Returns true on success. | 63 // settings. Returns true on success. |
59 virtual bool SetUpNotifications(Delegate* delegate) = 0; | 64 virtual bool SetUpNotifications(Delegate* delegate) = 0; |
60 | 65 |
61 // Returns the message loop for the thread on which this object | 66 // Returns the message loop for the thread on which this object |
62 // handles notifications, and also on which it must be destroyed. | 67 // handles notifications, and also on which it must be destroyed. |
63 // Returns NULL if it does not matter. | 68 // Returns NULL if it does not matter. |
64 virtual MessageLoop* GetNotificationLoop() = 0; | 69 virtual base::MessageLoopProxy* GetNotificationLoop() = 0; |
65 | 70 |
66 // Returns the data source's name (e.g. "gconf", "gsettings", "KDE", | 71 // Returns the data source's name (e.g. "gconf", "gsettings", "KDE", |
67 // "test"). Used only for diagnostic purposes (e.g. VLOG(1) etc.). | 72 // "test"). Used only for diagnostic purposes (e.g. VLOG(1) etc.). |
68 virtual const char* GetDataSource() = 0; | 73 virtual const char* GetDataSource() = 0; |
69 | 74 |
70 // These are all the values that can be fetched. We used to just use the | 75 // These are all the values that can be fetched. We used to just use the |
71 // corresponding paths in gconf for these, but gconf is now obsolete and | 76 // corresponding paths in gconf for these, but gconf is now obsolete and |
72 // in the future we'll be using mostly gsettings/kioslaverc so we | 77 // in the future we'll be using mostly gsettings/kioslaverc so we |
73 // enumerate them instead to avoid unnecessary string operations. | 78 // enumerate them instead to avoid unnecessary string operations. |
74 enum StringSetting { | 79 enum StringSetting { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 Delegate(base::Environment* env_var_getter, SettingGetter* setting_getter); | 175 Delegate(base::Environment* env_var_getter, SettingGetter* setting_getter); |
171 | 176 |
172 // Synchronously obtains the proxy configuration. If gconf, | 177 // Synchronously obtains the proxy configuration. If gconf, |
173 // gsettings, or kioslaverc are used, also enables notifications for | 178 // gsettings, or kioslaverc are used, also enables notifications for |
174 // setting changes. gconf/gsettings must only be accessed from the | 179 // setting changes. gconf/gsettings must only be accessed from the |
175 // thread running the default glib main loop, and so this method | 180 // thread running the default glib main loop, and so this method |
176 // must be called from the UI thread. The message loop for the IO | 181 // must be called from the UI thread. The message loop for the IO |
177 // thread is specified so that notifications can post tasks to it | 182 // thread is specified so that notifications can post tasks to it |
178 // (and for assertions). The message loop for the file thread is | 183 // (and for assertions). The message loop for the file thread is |
179 // used to read any files needed to determine proxy settings. | 184 // used to read any files needed to determine proxy settings. |
180 void SetUpAndFetchInitialConfig(MessageLoop* glib_default_loop, | 185 void SetUpAndFetchInitialConfig(base::MessageLoopProxy* glib_default_loop, |
181 MessageLoop* io_loop, | 186 base::MessageLoopProxy* io_loop, |
182 MessageLoopForIO* file_loop); | 187 MessageLoopForIO* file_loop); |
183 | 188 |
184 // Handler for setting change notifications: fetches a new proxy | 189 // Handler for setting change notifications: fetches a new proxy |
185 // configuration from settings, and if this config is different | 190 // configuration from settings, and if this config is different |
186 // than what we had before, posts a task to have it stored in | 191 // than what we had before, posts a task to have it stored in |
187 // cached_config_. | 192 // cached_config_. |
188 // Left public for simplicity. | 193 // Left public for simplicity. |
189 void OnCheckProxyConfigSettings(); | 194 void OnCheckProxyConfigSettings(); |
190 | 195 |
191 // Called from IO thread. | 196 // Called from IO thread. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 ProxyConfig reference_config_; | 253 ProxyConfig reference_config_; |
249 | 254 |
250 // The MessageLoop for the UI thread, aka main browser thread. This thread | 255 // The MessageLoop for the UI thread, aka main browser thread. This thread |
251 // is where we run the glib main loop (see base/message_pump_glib.h). It is | 256 // is where we run the glib main loop (see base/message_pump_glib.h). It is |
252 // the glib default loop in the sense that it runs the glib default context: | 257 // the glib default loop in the sense that it runs the glib default context: |
253 // as in the context where sources are added by g_timeout_add and | 258 // as in the context where sources are added by g_timeout_add and |
254 // g_idle_add, and returned by g_main_context_default. gconf uses glib | 259 // g_idle_add, and returned by g_main_context_default. gconf uses glib |
255 // timeouts and idles and possibly other callbacks that will all be | 260 // timeouts and idles and possibly other callbacks that will all be |
256 // dispatched on this thread. Since gconf is not thread safe, any use of | 261 // dispatched on this thread. Since gconf is not thread safe, any use of |
257 // gconf must be done on the thread running this loop. | 262 // gconf must be done on the thread running this loop. |
258 MessageLoop* glib_default_loop_; | 263 scoped_refptr<base::MessageLoopProxy> glib_default_loop_; |
259 // MessageLoop for the IO thread. GetLatestProxyConfig() is called from | 264 // MessageLoop for the IO thread. GetLatestProxyConfig() is called from |
260 // the thread running this loop. | 265 // the thread running this loop. |
261 MessageLoop* io_loop_; | 266 scoped_refptr<base::MessageLoopProxy> io_loop_; |
262 | 267 |
263 ObserverList<Observer> observers_; | 268 ObserverList<Observer> observers_; |
264 | 269 |
265 DISALLOW_COPY_AND_ASSIGN(Delegate); | 270 DISALLOW_COPY_AND_ASSIGN(Delegate); |
266 }; | 271 }; |
267 | 272 |
268 // Thin wrapper shell around Delegate. | 273 // Thin wrapper shell around Delegate. |
269 | 274 |
270 // Usual constructor | 275 // Usual constructor |
271 ProxyConfigServiceLinux(); | 276 ProxyConfigServiceLinux(); |
272 // For testing: take alternate setting and env var getter implementations. | 277 // For testing: take alternate setting and env var getter implementations. |
273 explicit ProxyConfigServiceLinux(base::Environment* env_var_getter); | 278 explicit ProxyConfigServiceLinux(base::Environment* env_var_getter); |
274 ProxyConfigServiceLinux(base::Environment* env_var_getter, | 279 ProxyConfigServiceLinux(base::Environment* env_var_getter, |
275 SettingGetter* setting_getter); | 280 SettingGetter* setting_getter); |
276 | 281 |
277 virtual ~ProxyConfigServiceLinux(); | 282 virtual ~ProxyConfigServiceLinux(); |
278 | 283 |
279 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, | 284 void SetupAndFetchInitialConfig(base::MessageLoopProxy* glib_default_loop, |
280 MessageLoop* io_loop, | 285 base::MessageLoopProxy* io_loop, |
281 MessageLoopForIO* file_loop) { | 286 MessageLoopForIO* file_loop) { |
282 delegate_->SetUpAndFetchInitialConfig(glib_default_loop, io_loop, | 287 delegate_->SetUpAndFetchInitialConfig(glib_default_loop, io_loop, |
283 file_loop); | 288 file_loop); |
284 } | 289 } |
285 void OnCheckProxyConfigSettings() { | 290 void OnCheckProxyConfigSettings() { |
286 delegate_->OnCheckProxyConfigSettings(); | 291 delegate_->OnCheckProxyConfigSettings(); |
287 } | 292 } |
288 | 293 |
289 // ProxyConfigService methods: | 294 // ProxyConfigService methods: |
290 // Called from IO thread. | 295 // Called from IO thread. |
291 virtual void AddObserver(Observer* observer) OVERRIDE; | 296 virtual void AddObserver(Observer* observer) OVERRIDE; |
292 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 297 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
293 virtual ProxyConfigService::ConfigAvailability GetLatestProxyConfig( | 298 virtual ProxyConfigService::ConfigAvailability GetLatestProxyConfig( |
294 ProxyConfig* config) OVERRIDE; | 299 ProxyConfig* config) OVERRIDE; |
295 | 300 |
296 private: | 301 private: |
297 scoped_refptr<Delegate> delegate_; | 302 scoped_refptr<Delegate> delegate_; |
298 | 303 |
299 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); | 304 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); |
300 }; | 305 }; |
301 | 306 |
302 } // namespace net | 307 } // namespace net |
303 | 308 |
304 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ | 309 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ |
OLD | NEW |