| OLD | NEW |
| 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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 // Forward declaration of Delegate. | 27 // Forward declaration of Delegate. |
| 28 class Delegate; | 28 class Delegate; |
| 29 | 29 |
| 30 class GConfSettingGetter { | 30 class GConfSettingGetter { |
| 31 public: | 31 public: |
| 32 // Buffer size used in some implementations of this class when reading | 32 // Buffer size used in some implementations of this class when reading |
| 33 // files. Defined here so unit tests can construct worst-case inputs. | 33 // files. Defined here so unit tests can construct worst-case inputs. |
| 34 static const size_t BUFFER_SIZE = 512; | 34 static const size_t BUFFER_SIZE = 512; |
| 35 | 35 |
| 36 GConfSettingGetter() {} |
| 36 virtual ~GConfSettingGetter() {} | 37 virtual ~GConfSettingGetter() {} |
| 37 | 38 |
| 38 // Initializes the class: obtains a gconf client, or simulates one, in | 39 // Initializes the class: obtains a gconf client, or simulates one, in |
| 39 // the concrete implementations. Returns true on success. Must be called | 40 // the concrete implementations. Returns true on success. Must be called |
| 40 // before using other methods, and should be called on the thread running | 41 // before using other methods, and should be called on the thread running |
| 41 // the glib main loop. | 42 // the glib main loop. |
| 42 // One of |glib_default_loop| and |file_loop| will be used for gconf calls | 43 // One of |glib_default_loop| and |file_loop| will be used for gconf calls |
| 43 // or reading necessary files, depending on the implementation. | 44 // or reading necessary files, depending on the implementation. |
| 44 virtual bool Init(MessageLoop* glib_default_loop, | 45 virtual bool Init(MessageLoop* glib_default_loop, |
| 45 MessageLoopForIO* file_loop) = 0; | 46 MessageLoopForIO* file_loop) = 0; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 67 // after a failed call to SetupNotification() or after calling | 68 // after a failed call to SetupNotification() or after calling |
| 68 // Release(). | 69 // Release(). |
| 69 virtual bool GetString(const char* key, std::string* result) = 0; | 70 virtual bool GetString(const char* key, std::string* result) = 0; |
| 70 // Same thing for a bool typed value. | 71 // Same thing for a bool typed value. |
| 71 virtual bool GetBoolean(const char* key, bool* result) = 0; | 72 virtual bool GetBoolean(const char* key, bool* result) = 0; |
| 72 // Same for an int typed value. | 73 // Same for an int typed value. |
| 73 virtual bool GetInt(const char* key, int* result) = 0; | 74 virtual bool GetInt(const char* key, int* result) = 0; |
| 74 // And for a string list. | 75 // And for a string list. |
| 75 virtual bool GetStringList(const char* key, | 76 virtual bool GetStringList(const char* key, |
| 76 std::vector<std::string>* result) = 0; | 77 std::vector<std::string>* result) = 0; |
| 78 |
| 79 private: |
| 80 DISALLOW_COPY_AND_ASSIGN(GConfSettingGetter); |
| 77 }; | 81 }; |
| 78 | 82 |
| 79 // ProxyConfigServiceLinux is created on the UI thread, and | 83 // ProxyConfigServiceLinux is created on the UI thread, and |
| 80 // SetupAndFetchInitialConfig() is immediately called to | 84 // SetupAndFetchInitialConfig() is immediately called to |
| 81 // synchronously fetch the original configuration and setup gconf | 85 // synchronously fetch the original configuration and setup gconf |
| 82 // notifications on the UI thread. | 86 // notifications on the UI thread. |
| 83 // | 87 // |
| 84 // Passed that point, it is accessed periodically through | 88 // Passed that point, it is accessed periodically through |
| 85 // GetProxyConfig() from the IO thread. | 89 // GetProxyConfig() from the IO thread. |
| 86 // | 90 // |
| (...skipping 23 matching lines...) Expand all Loading... |
| 110 // used, also enables gconf notification for setting | 114 // used, also enables gconf notification for setting |
| 111 // changes. gconf must only be accessed from the thread running | 115 // changes. gconf must only be accessed from the thread running |
| 112 // the default glib main loop, and so this method must be called | 116 // the default glib main loop, and so this method must be called |
| 113 // from the UI thread. The message loop for the IO thread is | 117 // from the UI thread. The message loop for the IO thread is |
| 114 // specified so that notifications can post tasks to it (and for | 118 // specified so that notifications can post tasks to it (and for |
| 115 // assertions). The message loop for the file thread is used to | 119 // assertions). The message loop for the file thread is used to |
| 116 // read any files needed to determine proxy settings. | 120 // read any files needed to determine proxy settings. |
| 117 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, | 121 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, |
| 118 MessageLoop* io_loop, | 122 MessageLoop* io_loop, |
| 119 MessageLoopForIO* file_loop); | 123 MessageLoopForIO* file_loop); |
| 120 // Resets cached_config_ and releases the gconf_getter_, making it | |
| 121 // possible to call SetupAndFetchInitialConfig() again. Only used | |
| 122 // in testing. | |
| 123 void Reset(); | |
| 124 | 124 |
| 125 // Handler for gconf change notifications: fetches a new proxy | 125 // Handler for gconf change notifications: fetches a new proxy |
| 126 // configuration from gconf settings, and if this config is | 126 // configuration from gconf settings, and if this config is |
| 127 // different than what we had before, posts a task to have it | 127 // different than what we had before, posts a task to have it |
| 128 // stored in cached_config_. | 128 // stored in cached_config_. |
| 129 // Left public for simplicity. | 129 // Left public for simplicity. |
| 130 void OnCheckProxyConfigSettings(); | 130 void OnCheckProxyConfigSettings(); |
| 131 | 131 |
| 132 // Called from IO thread. | 132 // Called from IO thread. |
| 133 int GetProxyConfig(ProxyConfig* config); | 133 int GetProxyConfig(ProxyConfig* config); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 virtual ~ProxyConfigServiceLinux() { | 207 virtual ~ProxyConfigServiceLinux() { |
| 208 delegate_->PostDestroyTask(); | 208 delegate_->PostDestroyTask(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, | 211 void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop, |
| 212 MessageLoop* io_loop, | 212 MessageLoop* io_loop, |
| 213 MessageLoopForIO* file_loop) { | 213 MessageLoopForIO* file_loop) { |
| 214 delegate_->SetupAndFetchInitialConfig(glib_default_loop, io_loop, | 214 delegate_->SetupAndFetchInitialConfig(glib_default_loop, io_loop, |
| 215 file_loop); | 215 file_loop); |
| 216 } | 216 } |
| 217 void Reset() { | |
| 218 delegate_->Reset(); | |
| 219 } | |
| 220 void OnCheckProxyConfigSettings() { | 217 void OnCheckProxyConfigSettings() { |
| 221 delegate_->OnCheckProxyConfigSettings(); | 218 delegate_->OnCheckProxyConfigSettings(); |
| 222 } | 219 } |
| 223 | 220 |
| 224 // ProxyConfigService methods: | 221 // ProxyConfigService methods: |
| 225 // Called from IO thread. | 222 // Called from IO thread. |
| 226 virtual int GetProxyConfig(ProxyConfig* config) { | 223 virtual int GetProxyConfig(ProxyConfig* config) { |
| 227 return delegate_->GetProxyConfig(config); | 224 return delegate_->GetProxyConfig(config); |
| 228 } | 225 } |
| 229 | 226 |
| 230 private: | 227 private: |
| 231 scoped_refptr<Delegate> delegate_; | 228 scoped_refptr<Delegate> delegate_; |
| 232 | 229 |
| 233 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); | 230 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceLinux); |
| 234 }; | 231 }; |
| 235 | 232 |
| 236 } // namespace net | 233 } // namespace net |
| 237 | 234 |
| 238 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ | 235 #endif // NET_PROXY_PROXY_CONFIG_SERVICE_LINUX_H_ |
| OLD | NEW |