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

Side by Side Diff: chrome/browser/chromeos/proxy_config_service_impl.h

Issue 6549007: Make CrOS proxy configuration write prefs directly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix single proxy handling for real! Created 9 years, 10 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) 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 CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ 6 #define CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_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/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
15 #include "base/scoped_ptr.h" 15 #include "base/scoped_ptr.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/chromeos/login/signed_settings.h" 17 #include "chrome/browser/chromeos/login/signed_settings.h"
18 #include "net/proxy/proxy_config.h" 18 #include "net/proxy/proxy_config.h"
19 #include "net/proxy/proxy_config_service.h" 19 #include "net/proxy/proxy_config_service.h"
20 #include "net/proxy/proxy_server.h" 20 #include "net/proxy/proxy_server.h"
21 21
22 class PrefService;
23
22 namespace chromeos { 24 namespace chromeos {
23 25
24 // Implementation of proxy config service for chromeos that: 26 // Implementation of proxy config service for chromeos that:
25 // - is RefCountedThreadSafe
26 // - is wrapped by chromeos::ProxyConfigService which implements
27 // net::ProxyConfigService interface by fowarding the methods to this class
28 // - retrieves initial system proxy configuration from cros settings persisted 27 // - retrieves initial system proxy configuration from cros settings persisted
29 // on chromeos device 28 // on chromeos device
30 // - provides network stack with latest system proxy configuration for use on
31 // IO thread
32 // - provides UI with methods to retrieve and modify system proxy configuration 29 // - provides UI with methods to retrieve and modify system proxy configuration
33 // on UI thread 30 // on UI thread
34 // - TODO(kuan): persists proxy configuration settings on chromeos device using 31 // - TODO(kuan): persists proxy configuration settings on chromeos device using
35 // cros settings 32 // cros settings
36 class ProxyConfigServiceImpl 33 class ProxyConfigServiceImpl
battre 2011/02/22 10:32:40 should this be called ProxyConfigService now?
Mattias Nissler (ping if slow) 2011/02/22 11:08:02 We could change the name. Maybe ChromeOSProxyConfi
37 : public base::RefCountedThreadSafe<ProxyConfigServiceImpl>, 34 : public SignedSettings::Delegate<bool>,
38 public SignedSettings::Delegate<bool>,
39 public SignedSettings::Delegate<std::string> { 35 public SignedSettings::Delegate<std::string> {
40 public: 36 public:
41 // ProxyConfigServiceImpl is created on the UI thread in 37 // ProxyConfigServiceImpl is created on the UI thread in
42 // chrome/browser/net/chrome_url_request_context.cc::CreateProxyConfigService 38 // chrome/browser/net/chrome_url_request_context.cc::CreateProxyConfigService
43 // via ProfileImpl::GetChromeOSProxyConfigServiceImpl, and stored in Profile 39 // via ProfileImpl::GetChromeOSProxyConfigServiceImpl, and stored in Profile
44 // as a scoped_refptr (because it's RefCountedThreadSafe). 40 // as a scoped_refptr (because it's RefCountedThreadSafe).
battre 2011/02/22 10:32:40 ProxyConfigServiceImpl is not RefCountedThreadSafe
Mattias Nissler (ping if slow) 2011/02/22 11:08:02 Done.
45 // 41 //
46 // Past that point, it can be accessed from the IO or UI threads.
47 //
48 // From the IO thread, it is accessed periodically through the wrapper class
49 // chromeos::ProxyConfigService via net::ProxyConfigService interface
50 // (GetLatestProxyConfig, AddObserver, RemoveObserver).
51 //
52 // From the UI thread, it is accessed via 42 // From the UI thread, it is accessed via
53 // WebUI::GetProfile::GetChromeOSProxyConfigServiceImpl to allow user to read 43 // WebUI::GetProfile::GetChromeOSProxyConfigServiceImpl to allow user to read
54 // or modify the proxy configuration via UIGetProxyConfig or 44 // or modify the proxy configuration via UIGetProxyConfig or
55 // UISetProxyConfigTo* respectively. 45 // UISetProxyConfigTo* respectively.
56 // The new modified proxy config is posted to the IO thread through 46 // The new modified proxy config is posted to the IO thread through
57 // SetNewProxyConfig(). We then notify observers on the IO thread of the 47 // SetNewProxyConfig(). We then notify observers on the IO thread of the
58 // configuration change. 48 // configuration change.
59 49
60 // In contrary to other platforms which simply use the systems' UI to allow 50 // In contrary to other platforms which simply use the systems' UI to allow
61 // users to configure proxies, we have to implement our own UI on the chromeos 51 // users to configure proxies, we have to implement our own UI on the chromeos
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // Proxy setting for mode = single-proxy or proxy-per-scheme. 96 // Proxy setting for mode = single-proxy or proxy-per-scheme.
107 struct ManualProxy : public Setting { 97 struct ManualProxy : public Setting {
108 virtual DictionaryValue* Encode() const; 98 virtual DictionaryValue* Encode() const;
109 bool Decode(DictionaryValue* dict, net::ProxyServer::Scheme scheme); 99 bool Decode(DictionaryValue* dict, net::ProxyServer::Scheme scheme);
110 100
111 net::ProxyServer server; 101 net::ProxyServer server;
112 }; 102 };
113 103
114 ProxyConfig() : mode(MODE_DIRECT) {} 104 ProxyConfig() : mode(MODE_DIRECT) {}
115 105
116 // Converts |this| to net::ProxyConfig. 106 // Converts |this| to a proxy config dictionary understood by the pref
117 void ToNetProxyConfig(net::ProxyConfig* net_config); 107 // system. Ownership is transferred to the caller
battre 2011/02/22 10:32:40 nit: . at the end.
Mattias Nissler (ping if slow) 2011/02/22 11:08:02 Done.
108 DictionaryValue* ToProxyConfigDictionary() const;
118 109
119 // Returns true if proxy config can be written by user. 110 // Returns true if proxy config can be written by user.
120 // If mode is MODE_PROXY_PER_SCHEME, |scheme| is one of "http", "https", 111 // If mode is MODE_PROXY_PER_SCHEME, |scheme| is one of "http", "https",
121 // "ftp" or "socks"; otherwise, it should be empty or will be ignored. 112 // "ftp" or "socks"; otherwise, it should be empty or will be ignored.
122 bool CanBeWrittenByUser(bool user_is_owner, const std::string& scheme); 113 bool CanBeWrittenByUser(bool user_is_owner, const std::string& scheme);
123 114
124 // Map |scheme| (one of "http", "https", "ftp" or "socks") to the correct 115 // Map |scheme| (one of "http", "https", "ftp" or "socks") to the correct
125 // ManualProxy. Returns NULL if scheme is invalid. 116 // ManualProxy. Returns NULL if scheme is invalid.
126 ManualProxy* MapSchemeToProxy(const std::string& scheme); 117 ManualProxy* MapSchemeToProxy(const std::string& scheme);
127 118
(...skipping 22 matching lines...) Expand all
150 // Set if mode is MODE_PROXY_PER_SCHEME and has socks proxy. 141 // Set if mode is MODE_PROXY_PER_SCHEME and has socks proxy.
151 ManualProxy socks_proxy; 142 ManualProxy socks_proxy;
152 143
153 // Exceptions for when not to use a proxy. 144 // Exceptions for when not to use a proxy.
154 net::ProxyBypassRules bypass_rules; 145 net::ProxyBypassRules bypass_rules;
155 146
156 private: 147 private:
157 // Encodes |manual_proxy| and adds it as value into |key_name| of |dict|. 148 // Encodes |manual_proxy| and adds it as value into |key_name| of |dict|.
158 void EncodeManualProxy(const ManualProxy& manual_proxy, 149 void EncodeManualProxy(const ManualProxy& manual_proxy,
159 DictionaryValue* dict, const char* key_name); 150 DictionaryValue* dict, const char* key_name);
151
160 // Decodes value of |key_name| in |dict| into |manual_proxy| with |scheme|; 152 // Decodes value of |key_name| in |dict| into |manual_proxy| with |scheme|;
161 // if |ok_if_absent| is true, function returns true if |key_name| doesn't 153 // if |ok_if_absent| is true, function returns true if |key_name| doesn't
162 // exist in |dict|. 154 // exist in |dict|.
163 bool DecodeManualProxy(DictionaryValue* dict, const char* key_name, 155 bool DecodeManualProxy(DictionaryValue* dict, const char* key_name,
164 bool ok_if_absent, net::ProxyServer::Scheme scheme, 156 bool ok_if_absent, net::ProxyServer::Scheme scheme,
165 ManualProxy* manual_proxy); 157 ManualProxy* manual_proxy);
158
159 // Helper function for building up the manual proxy spec. A declration of
battre 2011/02/22 10:32:40 nit: declaration
Mattias Nissler (ping if slow) 2011/02/22 11:08:02 Done.
160 // the form <scheme>=<server> is written to spec. |spec| is in/out, it is
161 // appended to if it already contains data.
162 static void FormatProxySpec(std::string* spec,
163 const std::string& scheme,
164 const net::ProxyServer& server);
166 }; 165 };
167 166
168 // Usual constructor. 167 // Usual constructor.
169 ProxyConfigServiceImpl(); 168 explicit ProxyConfigServiceImpl(PrefService* local_state);
170 // Constructor for testing. 169 // Constructor for testing.
171 // |init_config| specifies the ProxyConfig to use for initialization. 170 // |init_config| specifies the ProxyConfig to use for initialization.
172 explicit ProxyConfigServiceImpl(const ProxyConfig& init_config); 171 ProxyConfigServiceImpl(PrefService* local_state,
172 const ProxyConfig& init_config);
173 virtual ~ProxyConfigServiceImpl(); 173 virtual ~ProxyConfigServiceImpl();
174 174
175 // Methods called on IO thread from wrapper class chromeos::ProxyConfigService
176 // as ProxyConfigService methods.
177 void AddObserver(net::ProxyConfigService::Observer* observer);
178 void RemoveObserver(net::ProxyConfigService::Observer* observer);
179 // Called from GetLatestProxyConfig.
180 bool IOGetProxyConfig(net::ProxyConfig* config);
181
182 // Called from UI thread to retrieve proxy configuration in |config|. 175 // Called from UI thread to retrieve proxy configuration in |config|.
183 void UIGetProxyConfig(ProxyConfig* config); 176 void UIGetProxyConfig(ProxyConfig* config);
184 177
185 // Called from UI thread to set flag to persist settings to device. 178 // Called from UI thread to set flag to persist settings to device.
186 // Subsequent UISet* methods will use this flag, until UI calls it again with 179 // Subsequent UISet* methods will use this flag, until UI calls it again with
187 // a different flag. 180 // a different flag.
188 void UISetPersistToDevice(bool persist) { 181 void UISetPersistToDevice(bool persist) {
189 persist_to_device_ = persist; 182 persist_to_device_ = persist;
190 } 183 }
191 184
(...skipping 14 matching lines...) Expand all
206 // Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME. 199 // Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME.
207 bool UISetProxyConfigBypassRules(const net::ProxyBypassRules& bypass_rules); 200 bool UISetProxyConfigBypassRules(const net::ProxyBypassRules& bypass_rules);
208 201
209 // Implementation for SignedSettings::Delegate 202 // Implementation for SignedSettings::Delegate
210 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, 203 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code,
211 std::string value); 204 std::string value);
212 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, 205 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code,
213 bool value); 206 bool value);
214 207
215 private: 208 private:
216 friend class base::RefCountedThreadSafe<ProxyConfigServiceImpl>;
217
218 // Init proxy to default config, i.e. AutoDetect. 209 // Init proxy to default config, i.e. AutoDetect.
219 // If |post_to_io_thread| is true, a task will be posted to IO thread to 210 void InitConfigToDefault();
220 // update |cached_config|.
221 void InitConfigToDefault(bool post_to_io_thread);
222 211
223 // Persists proxy config to device. 212 // Persists proxy config to device.
224 void PersistConfigToDevice(); 213 void PersistConfigToDevice();
225 214
226 // Called from UI thread from the various UISetProxyConfigTo* 215 // Called from UI thread from the various UISetProxyConfigTo*
227 // |update_to_device| is true to persist new proxy config to device. 216 // |update_to_device| is true to persist new proxy config to device.
228 void OnUISetProxyConfig(bool update_to_device); 217 void OnUISetProxyConfig(bool update_to_device);
229 218
230 // Posted from UI thread to IO thread to carry the new config information.
231 void IOSetProxyConfig(const ProxyConfig& new_config);
232
233 // Checks that method is called on BrowserThread::IO thread.
234 void CheckCurrentlyOnIOThread();
235
236 // Checks that method is called on BrowserThread::UI thread.
237 void CheckCurrentlyOnUIThread();
238
239 // Data members. 219 // Data members.
240 220
241 // True if tasks can be posted, which can only happen if constructor has 221 // True if tasks can be posted, which can only happen if constructor has
242 // completed (NewRunnableMethod cannot be created for a RefCountedThreadBase's 222 // completed (NewRunnableMethod cannot be created for a RefCountedThreadBase's
243 // method until the class's ref_count is at least one). 223 // method until the class's ref_count is at least one).
244 bool can_post_task_; 224 bool can_post_task_;
245 225
246 // True if config has been fetched from device or initialized properly. 226 // True if config has been fetched from device or initialized properly.
247 bool has_config_; 227 bool has_config_;
248 228
249 // True if settings are to be persisted to device. 229 // True if settings are to be persisted to device.
250 bool persist_to_device_; 230 bool persist_to_device_;
251 231
252 // True if there's a pending operation to store proxy setting to device. 232 // True if there's a pending operation to store proxy setting to device.
253 bool persist_to_device_pending_; 233 bool persist_to_device_pending_;
254 234
255 // Cached proxy configuration, to be converted to net::ProxyConfig and
256 // returned by IOGetProxyConfig.
257 // Initially populated from the UI thread, but afterwards only accessed from
258 // the IO thread.
259 ProxyConfig cached_config_;
260
261 // Copy of the proxy configuration kept on the UI thread of the last seen 235 // Copy of the proxy configuration kept on the UI thread of the last seen
262 // proxy config, so as to avoid posting a call to SetNewProxyConfig when we 236 // proxy config, so as to avoid posting a call to SetNewProxyConfig when we
263 // are called by UI to set new proxy but the config has not actually changed. 237 // are called by UI to set new proxy but the config has not actually changed.
264 ProxyConfig reference_config_; 238 ProxyConfig reference_config_;
265 239
240 // The pref service to store the proxy configuration to.
241 PrefService* local_state_;
242
266 // List of observers for changes in proxy config. 243 // List of observers for changes in proxy config.
267 ObserverList<net::ProxyConfigService::Observer> observers_; 244 ObserverList<net::ProxyConfigService::Observer> observers_;
268 245
269 // Operations to retrieve and store proxy setting from and to device 246 // Operations to retrieve and store proxy setting from and to device
270 // respectively. 247 // respectively.
271 scoped_refptr<SignedSettings> retrieve_property_op_; 248 scoped_refptr<SignedSettings> retrieve_property_op_;
272 scoped_refptr<SignedSettings> store_property_op_; 249 scoped_refptr<SignedSettings> store_property_op_;
273 250
274 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl); 251 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl);
275 }; 252 };
276 253
277 } // namespace chromeos 254 } // namespace chromeos
278 255
279 #endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ 256 #endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698