Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: net/proxy/proxy_config_service_linux.h

Issue 155792: Try again: Add proxy config (using gnome-network-preferences) (Closed)
Patch Set: nits fixed Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/message_loop.h" 13 #include "base/message_loop.h"
13 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
14 #include "base/scoped_ptr.h" 15 #include "base/scoped_ptr.h"
15 #include "net/proxy/proxy_config.h" 16 #include "net/proxy/proxy_config.h"
16 #include "net/proxy/proxy_config_service.h" 17 #include "net/proxy/proxy_config_service.h"
17 #include "net/proxy/proxy_server.h" 18 #include "net/proxy/proxy_server.h"
18 19
19 namespace net { 20 namespace net {
20 21
21 // Implementation of ProxyConfigService that retrieves the system proxy 22 // Implementation of ProxyConfigService that retrieves the system proxy
22 // settings from environment variables or gconf. 23 // settings from environment variables or gconf.
23 class ProxyConfigServiceLinux : public ProxyConfigService { 24 class ProxyConfigServiceLinux : public ProxyConfigService {
24 public: 25 public:
25 26
26 // These are used to derive mocks for unittests.
27 class EnvironmentVariableGetter {
28 public:
29 virtual ~EnvironmentVariableGetter() {}
30 // Gets an environment variable's value and stores it in
31 // result. Returns false if the key is unset.
32 virtual bool Getenv(const char* variable_name, std::string* result) = 0;
33 };
34
35 class GConfSettingGetter { 27 class GConfSettingGetter {
36 public: 28 public:
37 virtual ~GConfSettingGetter() {} 29 virtual ~GConfSettingGetter() {}
38 30
39 // Initializes the class: obtains a gconf client, in the concrete 31 // Initializes the class: obtains a gconf client, in the concrete
40 // implementation. Returns true on success. Must be called before 32 // implementation. Returns true on success. Must be called before
41 // using other methods. 33 // using other methods.
42 virtual bool Init() = 0; 34 virtual bool Init() = 0;
43 35
44 // Releases the gconf client, which clears cached directories and 36 // Releases the gconf client, which clears cached directories and
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // The substance of the ProxyConfigServiceLinux implementation is 74 // The substance of the ProxyConfigServiceLinux implementation is
83 // wrapped in the Delegate ref counted class. On deleting the 75 // wrapped in the Delegate ref counted class. On deleting the
84 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to the 76 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to the
85 // UI thread where gconf notifications will be safely stopped before 77 // UI thread where gconf notifications will be safely stopped before
86 // releasing Delegate. 78 // releasing Delegate.
87 79
88 class Delegate : public base::RefCountedThreadSafe<Delegate> { 80 class Delegate : public base::RefCountedThreadSafe<Delegate> {
89 public: 81 public:
90 // Constructor receives gconf and env var getter implementations 82 // Constructor receives gconf and env var getter implementations
91 // to use, and takes ownership of them. 83 // to use, and takes ownership of them.
92 Delegate(EnvironmentVariableGetter* env_var_getter, 84 Delegate(base::EnvironmentVariableGetter* env_var_getter,
93 GConfSettingGetter* gconf_getter); 85 GConfSettingGetter* gconf_getter);
94 // Synchronously obtains the proxy configuration. If gconf is 86 // Synchronously obtains the proxy configuration. If gconf is
95 // used, also enables gconf notification for setting 87 // used, also enables gconf notification for setting
96 // changes. gconf must only be accessed from the thread running 88 // changes. gconf must only be accessed from the thread running
97 // the default glib main loop, and so this method must be called 89 // the default glib main loop, and so this method must be called
98 // from the UI thread. The message loop for the IO thread is 90 // from the UI thread. The message loop for the IO thread is
99 // specified so that notifications can post tasks to it (and for 91 // specified so that notifications can post tasks to it (and for
100 // assertions). 92 // assertions).
101 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, 93 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop,
102 MessageLoop* io_loop); 94 MessageLoop* io_loop);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 bool GetConfigFromGConf(ProxyConfig* config); 136 bool GetConfigFromGConf(ProxyConfig* config);
145 137
146 // Returns true if environment variables indicate that we are 138 // Returns true if environment variables indicate that we are
147 // running GNOME (and therefore we want to use gconf settings). 139 // running GNOME (and therefore we want to use gconf settings).
148 bool ShouldTryGConf(); 140 bool ShouldTryGConf();
149 141
150 // This method is posted from the UI thread to the IO thread to 142 // This method is posted from the UI thread to the IO thread to
151 // carry the new config information. 143 // carry the new config information.
152 void SetNewProxyConfig(const ProxyConfig& new_config); 144 void SetNewProxyConfig(const ProxyConfig& new_config);
153 145
154 scoped_ptr<EnvironmentVariableGetter> env_var_getter_; 146 scoped_ptr<base::EnvironmentVariableGetter> env_var_getter_;
155 scoped_ptr<GConfSettingGetter> gconf_getter_; 147 scoped_ptr<GConfSettingGetter> gconf_getter_;
156 148
157 // Cached proxy configuration, to be returned by 149 // Cached proxy configuration, to be returned by
158 // GetProxyConfig. Initially populated from the UI thread, but 150 // GetProxyConfig. Initially populated from the UI thread, but
159 // afterwards only accessed from the IO thread. 151 // afterwards only accessed from the IO thread.
160 ProxyConfig cached_config_; 152 ProxyConfig cached_config_;
161 153
162 // A copy kept on the UI thread of the last seen proxy config, so as 154 // A copy kept on the UI thread of the last seen proxy config, so as
163 // to avoid posting a call to SetNewProxyConfig when we get a 155 // to avoid posting a call to SetNewProxyConfig when we get a
164 // notification but the config has not actually changed. 156 // notification but the config has not actually changed.
(...skipping 14 matching lines...) Expand all
179 MessageLoop* io_loop_; 171 MessageLoop* io_loop_;
180 172
181 DISALLOW_COPY_AND_ASSIGN(Delegate); 173 DISALLOW_COPY_AND_ASSIGN(Delegate);
182 }; 174 };
183 175
184 // Thin wrapper shell around Delegate. 176 // Thin wrapper shell around Delegate.
185 177
186 // Usual constructor 178 // Usual constructor
187 ProxyConfigServiceLinux(); 179 ProxyConfigServiceLinux();
188 // For testing: takes alternate gconf and env var getter implementations. 180 // For testing: takes alternate gconf and env var getter implementations.
189 ProxyConfigServiceLinux(EnvironmentVariableGetter* env_var_getter, 181 ProxyConfigServiceLinux(base::EnvironmentVariableGetter* env_var_getter,
190 GConfSettingGetter* gconf_getter); 182 GConfSettingGetter* gconf_getter);
191 183
192 virtual ~ProxyConfigServiceLinux() { 184 virtual ~ProxyConfigServiceLinux() {
193 delegate_->PostDestroyTask(); 185 delegate_->PostDestroyTask();
194 } 186 }
195 187
196 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, 188 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop,
197 MessageLoop* io_loop) { 189 MessageLoop* io_loop) {
198 delegate_->SetupAndFetchInitialConfig(glib_default_loop, io_loop); 190 delegate_->SetupAndFetchInitialConfig(glib_default_loop, io_loop);
199 } 191 }
(...skipping 12 matching lines...) Expand all
212 204
213 private: 205 private:
214 scoped_refptr<Delegate> delegate_; 206 scoped_refptr<Delegate> delegate_;
215 207
216 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); 208 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux);
217 }; 209 };
218 210
219 } // namespace net 211 } // namespace net
220 212
221 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ 213 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698