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

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

Issue 2944313003: Remove the dependence on BrowserThread::FILE for (Closed)
Patch Set: address mmenke's comments Created 3 years, 6 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
« no previous file with comments | « ios/crnet/crnet_environment.mm ('k') | net/proxy/proxy_config_service_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/environment.h" 15 #include "base/environment.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/observer_list.h" 18 #include "base/observer_list.h"
19 #include "net/base/net_export.h" 19 #include "net/base/net_export.h"
20 #include "net/proxy/proxy_config.h" 20 #include "net/proxy/proxy_config.h"
21 #include "net/proxy/proxy_config_service.h" 21 #include "net/proxy/proxy_config_service.h"
22 #include "net/proxy/proxy_server.h" 22 #include "net/proxy/proxy_server.h"
23 23
24 namespace base { 24 namespace base {
25 class SingleThreadTaskRunner; 25 class SingleThreadTaskRunner;
26 class SequencedTaskRunner;
26 } // namespace base 27 } // namespace base
27 28
28 namespace net { 29 namespace net {
29 30
30 // Implementation of ProxyConfigService that retrieves the system proxy 31 // Implementation of ProxyConfigService that retrieves the system proxy
31 // settings from environment variables, gconf, gsettings, or kioslaverc (KDE). 32 // settings from environment variables, gconf, gsettings, or kioslaverc (KDE).
32 class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService { 33 class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService {
33 public: 34 public:
34 class Delegate; 35 class Delegate;
35 36
36 class SettingGetter { 37 class SettingGetter {
37 public: 38 public:
38 // Buffer size used in some implementations of this class when reading 39 // Buffer size used in some implementations of this class when reading
39 // files. Defined here so unit tests can construct worst-case inputs. 40 // files. Defined here so unit tests can construct worst-case inputs.
40 static const size_t BUFFER_SIZE = 512; 41 static const size_t BUFFER_SIZE = 512;
41 42
42 SettingGetter() {} 43 SettingGetter() {}
43 virtual ~SettingGetter() {} 44 virtual ~SettingGetter() {}
44 45
45 // Initializes the class: obtains a gconf/gsettings client, or simulates 46 // Initializes the class: obtains a gconf/gsettings client, or simulates
46 // one, in the concrete implementations. Returns true on success. Must be 47 // one, in the concrete implementations. Returns true on success. Must be
47 // called before using other methods, and should be called on the thread 48 // called before using other methods, and should be called on the thread
48 // running the glib main loop. 49 // running the glib main loop.
49 // One of |glib_task_runner| and |file_task_runner| will be 50 // This interface supports both GNOME and KDE implementations. In the
50 // used for gconf/gsettings calls or reading necessary files, depending on 51 // case of GNOME, the glib_task_runner will be used for interacting with
51 // the implementation. 52 // gconf/gsettings as those APIs have thread affinity. Whereas in the case
52 virtual bool Init( 53 // of KDE, its configuration files will be monitored at well-known locations
53 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, 54 // and glib_task_runner will not be used. Instead, blocking file I/O
54 const scoped_refptr<base::SingleThreadTaskRunner>& 55 // operations will be posted directly using the task scheduler.
55 file_task_runner) = 0; 56 virtual bool Init(const scoped_refptr<base::SingleThreadTaskRunner>&
57 glib_task_runner) = 0;
56 58
57 // Releases the gconf/gsettings client, which clears cached directories and 59 // Releases the gconf/gsettings client, which clears cached directories and
58 // stops notifications. 60 // stops notifications.
59 virtual void ShutDown() = 0; 61 virtual void ShutDown() = 0;
60 62
61 // Requests notification of gconf/gsettings changes for proxy 63 // Requests notification of gconf/gsettings changes for proxy
62 // settings. Returns true on success. 64 // settings. Returns true on success.
63 virtual bool SetUpNotifications(Delegate* delegate) = 0; 65 virtual bool SetUpNotifications(Delegate* delegate) = 0;
64 66
65 // Returns the message loop for the thread on which this object 67 // Returns the message loop for the thread on which this object
66 // handles notifications, and also on which it must be destroyed. 68 // handles notifications, and also on which it must be destroyed.
67 // Returns NULL if it does not matter. 69 // Returns NULL if it does not matter.
68 virtual const scoped_refptr<base::SingleThreadTaskRunner>& 70 virtual const scoped_refptr<base::SequencedTaskRunner>&
69 GetNotificationTaskRunner() = 0; 71 GetNotificationTaskRunner() = 0;
70 72
71 // Returns the source of proxy settings. 73 // Returns the source of proxy settings.
72 virtual ProxyConfigSource GetConfigSource() = 0; 74 virtual ProxyConfigSource GetConfigSource() = 0;
73 75
74 // These are all the values that can be fetched. We used to just use the 76 // These are all the values that can be fetched. We used to just use the
75 // corresponding paths in gconf for these, but gconf is now obsolete and 77 // corresponding paths in gconf for these, but gconf is now obsolete and
76 // in the future we'll be using mostly gsettings/kioslaverc so we 78 // in the future we'll be using mostly gsettings/kioslaverc so we
77 // enumerate them instead to avoid unnecessary string operations. 79 // enumerate them instead to avoid unnecessary string operations.
78 enum StringSetting { 80 enum StringSetting {
79 PROXY_MODE, 81 PROXY_MODE,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // ProxyConfigServiceLinux is created on the UI thread, and 145 // ProxyConfigServiceLinux is created on the UI thread, and
144 // SetUpAndFetchInitialConfig() is immediately called to synchronously 146 // SetUpAndFetchInitialConfig() is immediately called to synchronously
145 // fetch the original configuration and set up change notifications on 147 // fetch the original configuration and set up change notifications on
146 // the UI thread. 148 // the UI thread.
147 // 149 //
148 // Past that point, it is accessed periodically through the 150 // Past that point, it is accessed periodically through the
149 // ProxyConfigService interface (GetLatestProxyConfig, AddObserver, 151 // ProxyConfigService interface (GetLatestProxyConfig, AddObserver,
150 // RemoveObserver) from the IO thread. 152 // RemoveObserver) from the IO thread.
151 // 153 //
152 // Setting change notification callbacks can occur at any time and are 154 // Setting change notification callbacks can occur at any time and are
153 // run on either the UI thread (gconf/gsettings) or the file thread 155 // run on either the UI thread (gconf/gsettings) or the sequenced task
154 // (KDE). The new settings are fetched on that thread, and the resulting 156 // runner (KDE). The new settings are fetched on that thread, and the
155 // proxy config is posted to the IO thread through 157 // resulting proxy config is posted to the IO thread through
156 // Delegate::SetNewProxyConfig(). We then notify observers on the IO 158 // Delegate::SetNewProxyConfig(). We then notify observers on the IO
157 // thread of the configuration change. 159 // thread of the configuration change.
158 // 160 //
159 // ProxyConfigServiceLinux is deleted from the IO thread. 161 // ProxyConfigServiceLinux is deleted from the IO thread.
160 // 162 //
161 // The substance of the ProxyConfigServiceLinux implementation is 163 // The substance of the ProxyConfigServiceLinux implementation is
162 // wrapped in the Delegate ref counted class. On deleting the 164 // wrapped in the Delegate ref counted class. On deleting the
163 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to either 165 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to either
164 // the UI thread (gconf/gsettings) or the file thread (KDE) where change 166 // the UI thread (gconf/gsettings) or a sequenced task runner (KDE)
165 // notifications will be safely stopped before releasing Delegate. 167 // where change notifications will be safely stopped before releasing
168 // Delegate.
166 169
167 class Delegate : public base::RefCountedThreadSafe<Delegate> { 170 class Delegate : public base::RefCountedThreadSafe<Delegate> {
168 public: 171 public:
169 // Normal constructor. 172 // Normal constructor.
170 explicit Delegate(std::unique_ptr<base::Environment> env_var_getter); 173 explicit Delegate(std::unique_ptr<base::Environment> env_var_getter);
171 174
172 // Constructor for testing. 175 // Constructor for testing.
173 Delegate(std::unique_ptr<base::Environment> env_var_getter, 176 Delegate(std::unique_ptr<base::Environment> env_var_getter,
174 SettingGetter* setting_getter); 177 SettingGetter* setting_getter);
175 178
176 // Synchronously obtains the proxy configuration. If gconf, 179 // Synchronously obtains the proxy configuration. If gconf,
177 // gsettings, or kioslaverc are used, also enables notifications for 180 // gsettings, or kioslaverc are used, also enables notifications for
178 // setting changes. gconf/gsettings must only be accessed from the 181 // setting changes. gconf/gsettings must only be accessed from the
179 // thread running the default glib main loop, and so this method 182 // thread running the default glib main loop, and so this method
180 // must be called from the UI thread. The message loop for the IO 183 // must be called from the UI thread. The message loop for the IO
181 // thread is specified so that notifications can post tasks to it 184 // thread is specified so that notifications can post tasks to it
182 // (and for assertions). The message loop for the file thread is 185 // (and for assertions).
183 // used to read any files needed to determine proxy settings.
184 void SetUpAndFetchInitialConfig( 186 void SetUpAndFetchInitialConfig(
185 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, 187 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
186 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 188 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
187 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner);
188 189
189 // Handler for setting change notifications: fetches a new proxy 190 // Handler for setting change notifications: fetches a new proxy
190 // configuration from settings, and if this config is different 191 // configuration from settings, and if this config is different
191 // than what we had before, posts a task to have it stored in 192 // than what we had before, posts a task to have it stored in
192 // cached_config_. 193 // cached_config_.
193 // Left public for simplicity. 194 // Left public for simplicity.
194 void OnCheckProxyConfigSettings(); 195 void OnCheckProxyConfigSettings();
195 196
196 // Called from IO thread. 197 // Called from IO thread.
197 void AddObserver(Observer* observer); 198 void AddObserver(Observer* observer);
198 void RemoveObserver(Observer* observer); 199 void RemoveObserver(Observer* observer);
199 ProxyConfigService::ConfigAvailability GetLatestProxyConfig( 200 ProxyConfigService::ConfigAvailability GetLatestProxyConfig(
200 ProxyConfig* config); 201 ProxyConfig* config);
201 202
202 // Posts a call to OnDestroy() to the UI or FILE thread, depending on the 203 // Posts a call to OnDestroy() to the UI or sequenced task runner,
203 // setting getter in use. Called from ProxyConfigServiceLinux's destructor. 204 // depending on the setting getter in use. Called from
205 // ProxyConfigServiceLinux's destructor.
204 void PostDestroyTask(); 206 void PostDestroyTask();
205 // Safely stops change notifications. Posted to either the UI or FILE 207 // Safely stops change notifications. Posted to either the UI or
206 // thread, depending on the setting getter in use. 208 // sequenced task runner, depending on the setting getter in use.
207 void OnDestroy(); 209 void OnDestroy();
208 210
209 private: 211 private:
210 friend class base::RefCountedThreadSafe<Delegate>; 212 friend class base::RefCountedThreadSafe<Delegate>;
211 213
212 ~Delegate(); 214 ~Delegate();
213 215
214 // Obtains an environment variable's value. Parses a proxy server 216 // Obtains an environment variable's value. Parses a proxy server
215 // specification from it and puts it in result. Returns true if the 217 // specification from it and puts it in result. Returns true if the
216 // requested variable is defined and the value valid. 218 // requested variable is defined and the value valid.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // For testing: take alternate setting and env var getter implementations. 282 // For testing: take alternate setting and env var getter implementations.
281 explicit ProxyConfigServiceLinux( 283 explicit ProxyConfigServiceLinux(
282 std::unique_ptr<base::Environment> env_var_getter); 284 std::unique_ptr<base::Environment> env_var_getter);
283 ProxyConfigServiceLinux(std::unique_ptr<base::Environment> env_var_getter, 285 ProxyConfigServiceLinux(std::unique_ptr<base::Environment> env_var_getter,
284 SettingGetter* setting_getter); 286 SettingGetter* setting_getter);
285 287
286 ~ProxyConfigServiceLinux() override; 288 ~ProxyConfigServiceLinux() override;
287 289
288 void SetupAndFetchInitialConfig( 290 void SetupAndFetchInitialConfig(
289 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, 291 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
290 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 292 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) {
291 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { 293 delegate_->SetUpAndFetchInitialConfig(glib_task_runner, io_task_runner);
292 delegate_->SetUpAndFetchInitialConfig(glib_task_runner,
293 io_task_runner,
294 file_task_runner);
295 } 294 }
296 void OnCheckProxyConfigSettings() { 295 void OnCheckProxyConfigSettings() {
297 delegate_->OnCheckProxyConfigSettings(); 296 delegate_->OnCheckProxyConfigSettings();
298 } 297 }
299 298
300 // ProxyConfigService methods: 299 // ProxyConfigService methods:
301 // Called from IO thread. 300 // Called from IO thread.
302 void AddObserver(Observer* observer) override; 301 void AddObserver(Observer* observer) override;
303 void RemoveObserver(Observer* observer) override; 302 void RemoveObserver(Observer* observer) override;
304 ProxyConfigService::ConfigAvailability GetLatestProxyConfig( 303 ProxyConfigService::ConfigAvailability GetLatestProxyConfig(
305 ProxyConfig* config) override; 304 ProxyConfig* config) override;
306 305
307 private: 306 private:
308 scoped_refptr<Delegate> delegate_; 307 scoped_refptr<Delegate> delegate_;
309 308
310 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); 309 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux);
311 }; 310 };
312 311
313 } // namespace net 312 } // namespace net
314 313
315 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ 314 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_
OLDNEW
« no previous file with comments | « ios/crnet/crnet_environment.mm ('k') | net/proxy/proxy_config_service_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698