Chromium Code Reviews| Index: chrome/browser/chromeos/proxy_config_service_impl.h |
| diff --git a/chrome/browser/chromeos/proxy_config_service_impl.h b/chrome/browser/chromeos/proxy_config_service_impl.h |
| index 44a51662723a890effb5fcc651c2c389cf83b1a9..d8a806ad94f47d6ea2c1de94182ffa569663d691 100644 |
| --- a/chrome/browser/chromeos/proxy_config_service_impl.h |
| +++ b/chrome/browser/chromeos/proxy_config_service_impl.h |
| @@ -19,44 +19,28 @@ |
| #include "net/proxy/proxy_config_service.h" |
| #include "net/proxy/proxy_server.h" |
| +class PrefService; |
| + |
| namespace chromeos { |
| // Implementation of proxy config service for chromeos that: |
| -// - is RefCountedThreadSafe |
| -// - is wrapped by chromeos::ProxyConfigService which implements |
| -// net::ProxyConfigService interface by fowarding the methods to this class |
| // - retrieves initial system proxy configuration from cros settings persisted |
| // on chromeos device |
| -// - provides network stack with latest system proxy configuration for use on |
| -// IO thread |
| // - provides UI with methods to retrieve and modify system proxy configuration |
| // on UI thread |
| // - TODO(kuan): persists proxy configuration settings on chromeos device using |
| // cros settings |
| class ProxyConfigServiceImpl |
| - : public base::RefCountedThreadSafe<ProxyConfigServiceImpl>, |
| - public SignedSettings::Delegate<bool>, |
| + : public SignedSettings::Delegate<bool>, |
| public SignedSettings::Delegate<std::string> { |
| public: |
| - // ProxyConfigServiceImpl is created on the UI thread in |
| - // chrome/browser/net/chrome_url_request_context.cc::CreateProxyConfigService |
| - // via ProfileImpl::GetChromeOSProxyConfigServiceImpl, and stored in Profile |
| - // as a scoped_refptr (because it's RefCountedThreadSafe). |
| - // |
| - // Past that point, it can be accessed from the IO or UI threads. |
| + // ProxyConfigServiceImpl lives in the profile and is accessed via |
| + // Profile::GetChromeOSProxyConfigServiceImpl. It is accessed from |
|
kuan
2011/02/22 22:20:25
i'm sure u're aware of battre's cl that places Pro
Mattias Nissler (ping if slow)
2011/03/01 15:19:20
Yes, he's actually sitting 2 desks away from me, a
|
| + // ProxyCrosSettingsProvider in order to read or modify the proxy |
| + // configuration via UIGetProxyConfig or UISetProxyConfigTo* respectively. The |
| + // modified proxy configuration is written to local state preferences that get |
| + // picked up by PrefProxyConfigService and passed to the network stack. |
| // |
| - // From the IO thread, it is accessed periodically through the wrapper class |
| - // chromeos::ProxyConfigService via net::ProxyConfigService interface |
| - // (GetLatestProxyConfig, AddObserver, RemoveObserver). |
| - // |
| - // From the UI thread, it is accessed via |
| - // WebUI::GetProfile::GetChromeOSProxyConfigServiceImpl to allow user to read |
| - // or modify the proxy configuration via UIGetProxyConfig or |
| - // UISetProxyConfigTo* respectively. |
| - // The new modified proxy config is posted to the IO thread through |
| - // SetNewProxyConfig(). We then notify observers on the IO thread of the |
| - // configuration change. |
| - |
| // In contrary to other platforms which simply use the systems' UI to allow |
| // users to configure proxies, we have to implement our own UI on the chromeos |
| // device. This requires extra and specific UI requirements that |
| @@ -65,9 +49,6 @@ class ProxyConfigServiceImpl |
| // - where configuration was picked up from - policy or owner |
| // - the read/write access of a proxy setting |
| // - may add more stuff later. |
| - // This is then converted to the common net::ProxyConfig before being returned |
| - // to ProxyService::GetLatestProxyConfig on the IO thread to be used on the |
| - // network stack. |
| struct ProxyConfig { |
| // Specifies if proxy config is direct, auto-detect, using pac script, |
| // single-proxy, or proxy-per-scheme. |
| @@ -113,8 +94,9 @@ class ProxyConfigServiceImpl |
| ProxyConfig() : mode(MODE_DIRECT) {} |
| - // Converts |this| to net::ProxyConfig. |
| - void ToNetProxyConfig(net::ProxyConfig* net_config); |
| + // Converts |this| to a proxy config dictionary understood by the pref |
| + // system. Ownership is transferred to the caller. |
| + DictionaryValue* ToProxyConfigDictionary() const; |
| // Returns true if proxy config can be written by user. |
| // If mode is MODE_PROXY_PER_SCHEME, |scheme| is one of "http", "https", |
| @@ -157,28 +139,30 @@ class ProxyConfigServiceImpl |
| // Encodes |manual_proxy| and adds it as value into |key_name| of |dict|. |
| void EncodeManualProxy(const ManualProxy& manual_proxy, |
| DictionaryValue* dict, const char* key_name); |
| + |
| // Decodes value of |key_name| in |dict| into |manual_proxy| with |scheme|; |
| // if |ok_if_absent| is true, function returns true if |key_name| doesn't |
| // exist in |dict|. |
| bool DecodeManualProxy(DictionaryValue* dict, const char* key_name, |
| bool ok_if_absent, net::ProxyServer::Scheme scheme, |
| ManualProxy* manual_proxy); |
| + |
| + // Helper function for building up the manual proxy spec. A declaration of |
| + // the form <scheme>=<server> is written to spec. |spec| is in/out, it is |
| + // appended to if it already contains data. |
| + static void FormatProxySpec(std::string* spec, |
| + const std::string& scheme, |
| + const net::ProxyServer& server); |
| }; |
| // Usual constructor. |
| - ProxyConfigServiceImpl(); |
| + explicit ProxyConfigServiceImpl(PrefService* local_state); |
| // Constructor for testing. |
| // |init_config| specifies the ProxyConfig to use for initialization. |
| - explicit ProxyConfigServiceImpl(const ProxyConfig& init_config); |
| + ProxyConfigServiceImpl(PrefService* local_state, |
| + const ProxyConfig& init_config); |
| virtual ~ProxyConfigServiceImpl(); |
| - // Methods called on IO thread from wrapper class chromeos::ProxyConfigService |
| - // as ProxyConfigService methods. |
| - void AddObserver(net::ProxyConfigService::Observer* observer); |
| - void RemoveObserver(net::ProxyConfigService::Observer* observer); |
| - // Called from GetLatestProxyConfig. |
| - bool IOGetProxyConfig(net::ProxyConfig* config); |
| - |
| // Called from UI thread to retrieve proxy configuration in |config|. |
| void UIGetProxyConfig(ProxyConfig* config); |
| @@ -213,12 +197,8 @@ class ProxyConfigServiceImpl |
| bool value); |
| private: |
| - friend class base::RefCountedThreadSafe<ProxyConfigServiceImpl>; |
| - |
| // Init proxy to default config, i.e. AutoDetect. |
| - // If |post_to_io_thread| is true, a task will be posted to IO thread to |
| - // update |cached_config|. |
| - void InitConfigToDefault(bool post_to_io_thread); |
| + void InitConfigToDefault(); |
| // Persists proxy config to device. |
| void PersistConfigToDevice(); |
| @@ -227,15 +207,6 @@ class ProxyConfigServiceImpl |
| // |update_to_device| is true to persist new proxy config to device. |
| void OnUISetProxyConfig(bool update_to_device); |
| - // Posted from UI thread to IO thread to carry the new config information. |
| - void IOSetProxyConfig(const ProxyConfig& new_config); |
| - |
| - // Checks that method is called on BrowserThread::IO thread. |
| - void CheckCurrentlyOnIOThread(); |
| - |
| - // Checks that method is called on BrowserThread::UI thread. |
| - void CheckCurrentlyOnUIThread(); |
| - |
| // Data members. |
| // True if tasks can be posted, which can only happen if constructor has |
| @@ -252,17 +223,14 @@ class ProxyConfigServiceImpl |
| // True if there's a pending operation to store proxy setting to device. |
| bool persist_to_device_pending_; |
| - // Cached proxy configuration, to be converted to net::ProxyConfig and |
| - // returned by IOGetProxyConfig. |
| - // Initially populated from the UI thread, but afterwards only accessed from |
| - // the IO thread. |
| - ProxyConfig cached_config_; |
| - |
| // Copy of the proxy configuration kept on the UI thread of the last seen |
| // proxy config, so as to avoid posting a call to SetNewProxyConfig when we |
| // are called by UI to set new proxy but the config has not actually changed. |
| ProxyConfig reference_config_; |
| + // The pref service to store the proxy configuration to. |
| + PrefService* local_state_; |
| + |
| // List of observers for changes in proxy config. |
| ObserverList<net::ProxyConfigService::Observer> observers_; |