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

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

Issue 10912132: Move ProxyConfigService construction onto the IO thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tiny fix for get_server_time Created 8 years, 2 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 | Annotate | Revision Log
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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // Setting change notification callbacks can occur at any time and are 151 // Setting change notification callbacks can occur at any time and are
152 // run on either the UI thread (gconf/gsettings) or the file thread 152 // run on either the UI thread (gconf/gsettings) or the file thread
153 // (KDE). The new settings are fetched on that thread, and the resulting 153 // (KDE). The new settings are fetched on that thread, and the resulting
154 // proxy config is posted to the IO thread through 154 // proxy config is posted to the IO thread through
155 // Delegate::SetNewProxyConfig(). We then notify observers on the IO 155 // Delegate::SetNewProxyConfig(). We then notify observers on the IO
156 // thread of the configuration change. 156 // thread of the configuration change.
157 // 157 //
158 // ProxyConfigServiceLinux is deleted from the IO thread. 158 // ProxyConfigServiceLinux is deleted from the IO thread.
159 // 159 //
160 // The substance of the ProxyConfigServiceLinux implementation is 160 // The substance of the ProxyConfigServiceLinux implementation is
161 // wrapped in the Delegate ref counted class. On deleting the 161 // wrapped in the Delegate ref counted class. Destruction of the Delegate
162 // ProxyConfigServiceLinux, Delegate::OnDestroy() is posted to either 162 // is commenced by StartTearDown() which calls Delegate::OnDestroy() on
163 // the UI thread (gconf/gsettings) or the file thread (KDE) where change 163 // the UI thread (gconf/gsettings) or posts it to the file thread (KDE) where
164 // notifications will be safely stopped before releasing Delegate. 164 // change notifications will be safely stopped before releasing Delegate.
165 165
166 class Delegate : public base::RefCountedThreadSafe<Delegate> { 166 class Delegate : public base::RefCountedThreadSafe<Delegate> {
167 public: 167 public:
168 // Constructor receives env var getter implementation to use, and 168 // Constructor receives env var getter implementation to use, and
169 // takes ownership of it. This is the normal constructor. 169 // takes ownership of it. This is the normal constructor.
170 explicit Delegate(base::Environment* env_var_getter); 170 explicit Delegate(base::Environment* env_var_getter);
171 // Constructor receives setting and env var getter implementations 171 // Constructor receives setting and env var getter implementations
172 // to use, and takes ownership of them. Used for testing. 172 // to use, and takes ownership of them. Used for testing.
173 Delegate(base::Environment* env_var_getter, SettingGetter* setting_getter); 173 Delegate(base::Environment* env_var_getter, SettingGetter* setting_getter);
174 174
175 // Synchronously obtains the proxy configuration. If gconf, 175 // Asynchronously obtains the proxy configuration. If gconf,
176 // gsettings, or kioslaverc are used, also enables notifications for 176 // gsettings, or kioslaverc are used, also enables notifications for
177 // setting changes. gconf/gsettings must only be accessed from the 177 // setting changes. This method must be called from the IO thread. The
178 // thread running the default glib main loop, and so this method 178 // message loop for the IO thread is specified so that notifications
179 // must be called from the UI thread. The message loop for the IO 179 // can post tasks to it (and for assertions). The message loop for the
180 // thread is specified so that notifications can post tasks to it 180 // file thread is used to read any files needed to determine proxy
181 // (and for assertions). The message loop for the file thread is 181 // settings.
182 // used to read any files needed to determine proxy settings.
183 void SetUpAndFetchInitialConfig( 182 void SetUpAndFetchInitialConfig(
184 base::SingleThreadTaskRunner* glib_thread_task_runner, 183 base::SingleThreadTaskRunner* glib_thread_task_runner,
185 base::SingleThreadTaskRunner* io_thread_task_runner, 184 base::SingleThreadTaskRunner* io_thread_task_runner,
186 MessageLoopForIO* file_loop); 185 MessageLoopForIO* file_loop);
187 186
188 // Handler for setting change notifications: fetches a new proxy 187 // Handler for setting change notifications: fetches a new proxy
189 // configuration from settings, and if this config is different 188 // configuration from settings, and if this config is different
190 // than what we had before, posts a task to have it stored in 189 // than what we had before, posts a task to have it stored in
191 // cached_config_. 190 // cached_config_.
192 // Left public for simplicity. 191 // Left public for simplicity.
193 void OnCheckProxyConfigSettings(); 192 void OnCheckProxyConfigSettings();
194 193
195 // Called from IO thread. 194 // Called from IO thread.
196 void AddObserver(Observer* observer); 195 void AddObserver(Observer* observer);
197 void RemoveObserver(Observer* observer); 196 void RemoveObserver(Observer* observer);
198 ProxyConfigService::ConfigAvailability GetLatestProxyConfig( 197 ProxyConfigService::ConfigAvailability GetLatestProxyConfig(
199 ProxyConfig* config); 198 ProxyConfig* config);
200 199
201 // Posts a call to OnDestroy() to the UI or FILE thread, depending on the 200 // Posts a call to OnDestroy() to the UI or FILE thread, depending on the
202 // setting getter in use. Called from ProxyConfigServiceLinux's destructor. 201 // setting getter in use. Called from ProxyConfigServiceLinux's
202 // StartTearDown.
203 void PostDestroyTask(); 203 void PostDestroyTask();
204 // Safely stops change notifications. Posted to either the UI or FILE 204 // Safely stops change notifications. Posted to either the UI or FILE
205 // thread, depending on the setting getter in use. 205 // thread, depending on the setting getter in use.
206 void OnDestroy(); 206 void OnDestroy();
207 207
208 private: 208 private:
209 friend class base::RefCountedThreadSafe<Delegate>; 209 friend class base::RefCountedThreadSafe<Delegate>;
210 210
211 ~Delegate(); 211 ~Delegate();
212 212
213 // Synchronously obtains the proxy configuration. If gconf,
214 // gsettings, or kioslaverc are used, also enables notifications for
215 // setting changes. gconf/gsettings must only be accessed from the
216 // thread running the default glib main loop, and so this method
217 // must be called from the UI thread. The message loop for the IO
218 // thread is specified so that notifications can post tasks to it
219 // (and for assertions). The message loop for the file thread is
220 // used to read any files needed to determine proxy settings.
221 void SetUpAndFetchInitialConfigOnUIThread(
222 MessageLoopForIO* file_loop);
223
213 // Obtains an environment variable's value. Parses a proxy server 224 // Obtains an environment variable's value. Parses a proxy server
214 // specification from it and puts it in result. Returns true if the 225 // specification from it and puts it in result. Returns true if the
215 // requested variable is defined and the value valid. 226 // requested variable is defined and the value valid.
216 bool GetProxyFromEnvVarForScheme(const char* variable, 227 bool GetProxyFromEnvVarForScheme(const char* variable,
217 ProxyServer::Scheme scheme, 228 ProxyServer::Scheme scheme,
218 ProxyServer* result_server); 229 ProxyServer* result_server);
219 // As above but with scheme set to HTTP, for convenience. 230 // As above but with scheme set to HTTP, for convenience.
220 bool GetProxyFromEnvVar(const char* variable, ProxyServer* result_server); 231 bool GetProxyFromEnvVar(const char* variable, ProxyServer* result_server);
221 // Fills proxy config from environment variables. Returns true if 232 // Fills proxy config from environment variables. Returns true if
222 // variables were found and the configuration is valid. 233 // variables were found and the configuration is valid.
(...skipping 11 matching lines...) Expand all
234 // This method is posted from the UI thread to the IO thread to 245 // This method is posted from the UI thread to the IO thread to
235 // carry the new config information. 246 // carry the new config information.
236 void SetNewProxyConfig(const ProxyConfig& new_config); 247 void SetNewProxyConfig(const ProxyConfig& new_config);
237 248
238 // This method is run on the getter's notification thread. 249 // This method is run on the getter's notification thread.
239 void SetUpNotifications(); 250 void SetUpNotifications();
240 251
241 scoped_ptr<base::Environment> env_var_getter_; 252 scoped_ptr<base::Environment> env_var_getter_;
242 scoped_ptr<SettingGetter> setting_getter_; 253 scoped_ptr<SettingGetter> setting_getter_;
243 254
255 // Has initialization completed and it's safe to read cached_config_.
256 bool finished_initialization_;
257
244 // Cached proxy configuration, to be returned by 258 // Cached proxy configuration, to be returned by
245 // GetLatestProxyConfig. Initially populated from the UI thread, but 259 // GetLatestProxyConfig. Only accessed from the IO thread.
246 // afterwards only accessed from the IO thread.
247 ProxyConfig cached_config_; 260 ProxyConfig cached_config_;
248 261
249 // A copy kept on the UI thread of the last seen proxy config, so as 262 // A copy kept on the UI thread of the last seen proxy config, so as
250 // to avoid posting a call to SetNewProxyConfig when we get a 263 // to avoid posting a call to SetNewProxyConfig when we get a
251 // notification but the config has not actually changed. 264 // notification but the config has not actually changed.
252 ProxyConfig reference_config_; 265 ProxyConfig reference_config_;
253 266
254 // The task runner for the glib thread, aka main browser thread. This thread 267 // The task runner for the glib thread, aka main browser thread. This thread
255 // is where we run the glib main loop (see base/message_pump_glib.h). It is 268 // is where we run the glib main loop (see base/message_pump_glib.h). It is
256 // the glib default loop in the sense that it runs the glib default context: 269 // the glib default loop in the sense that it runs the glib default context:
257 // as in the context where sources are added by g_timeout_add and 270 // as in the context where sources are added by g_timeout_add and
258 // g_idle_add, and returned by g_main_context_default. gconf uses glib 271 // g_idle_add, and returned by g_main_context_default. gconf uses glib
259 // timeouts and idles and possibly other callbacks that will all be 272 // timeouts and idles and possibly other callbacks that will all be
260 // dispatched on this thread. Since gconf is not thread safe, any use of 273 // dispatched on this thread. Since gconf is not thread safe, any use of
261 // gconf must be done on the thread running this loop. 274 // gconf must be done on the thread running this loop.
262 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner_; 275 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner_;
263 // Task runner for the IO thread. GetLatestProxyConfig() is called from 276 // Task runner for the IO thread. GetLatestProxyConfig() is called from
264 // the thread running this loop. 277 // the thread running this loop.
265 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; 278 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_;
266 279
267 ObserverList<Observer> observers_; 280 ObserverList<Observer> observers_;
268 281
269 DISALLOW_COPY_AND_ASSIGN(Delegate); 282 DISALLOW_COPY_AND_ASSIGN(Delegate);
270 }; 283 };
271 284
272 // Thin wrapper shell around Delegate. 285 // Thin wrapper shell around Delegate.
273 286
274 // Usual constructor 287 // Usual constructor
275 ProxyConfigServiceLinux(); 288 ProxyConfigServiceLinux(
289 base::SingleThreadTaskRunner* glib_thread_task_runner,
290 base::SingleThreadTaskRunner* io_thread_task_runner,
291 MessageLoopForIO* file_loop);
276 // For testing: take alternate setting and env var getter implementations. 292 // For testing: take alternate setting and env var getter implementations.
277 explicit ProxyConfigServiceLinux(base::Environment* env_var_getter); 293 explicit ProxyConfigServiceLinux(base::Environment* env_var_getter);
278 ProxyConfigServiceLinux(base::Environment* env_var_getter, 294 ProxyConfigServiceLinux(base::Environment* env_var_getter,
279 SettingGetter* setting_getter); 295 SettingGetter* setting_getter);
280 296
281 virtual ~ProxyConfigServiceLinux(); 297 virtual ~ProxyConfigServiceLinux();
282 298
299 // This is only public for testing.
283 void SetupAndFetchInitialConfig( 300 void SetupAndFetchInitialConfig(
284 base::SingleThreadTaskRunner* glib_thread_task_runner, 301 base::SingleThreadTaskRunner* glib_thread_task_runner,
285 base::SingleThreadTaskRunner* io_thread_task_runner, 302 base::SingleThreadTaskRunner* io_thread_task_runner,
286 MessageLoopForIO* file_loop) { 303 MessageLoopForIO* file_loop) {
287 delegate_->SetUpAndFetchInitialConfig(glib_thread_task_runner, 304 delegate_->SetUpAndFetchInitialConfig(glib_thread_task_runner,
288 io_thread_task_runner, file_loop); 305 io_thread_task_runner, file_loop);
289 } 306 }
290 void OnCheckProxyConfigSettings() { 307 void OnCheckProxyConfigSettings() {
291 delegate_->OnCheckProxyConfigSettings(); 308 delegate_->OnCheckProxyConfigSettings();
292 } 309 }
293 310
294 // ProxyConfigService methods: 311 // ProxyConfigService methods:
295 // Called from IO thread. 312 // Called from IO thread.
296 virtual void AddObserver(Observer* observer) OVERRIDE; 313 virtual void AddObserver(Observer* observer) OVERRIDE;
297 virtual void RemoveObserver(Observer* observer) OVERRIDE; 314 virtual void RemoveObserver(Observer* observer) OVERRIDE;
298 virtual ProxyConfigService::ConfigAvailability GetLatestProxyConfig( 315 virtual ProxyConfigService::ConfigAvailability GetLatestProxyConfig(
299 ProxyConfig* config) OVERRIDE; 316 ProxyConfig* config) OVERRIDE;
300 317 // Called from Glib thread.
318 virtual void StartTearDown() OVERRIDE;
301 private: 319 private:
302 scoped_refptr<Delegate> delegate_; 320 scoped_refptr<Delegate> delegate_;
303 321
304 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); 322 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux);
305 }; 323 };
306 324
307 } // namespace net 325 } // namespace net
308 326
309 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ 327 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698