summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/proxy_config_service_impl.h
diff options
context:
space:
mode:
authorkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-17 07:44:10 +0000
committerkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-17 07:44:10 +0000
commit02dbca0bce56a1ef5e53c8f446eef38df2f62e8f (patch)
treeb66a88c1611cb091fbf498d40c891f1672c1be02 /chrome/browser/chromeos/proxy_config_service_impl.h
parent33f03e7856cee789c4a011e6736a9b3cf9f618a7 (diff)
downloadchromium_src-02dbca0bce56a1ef5e53c8f446eef38df2f62e8f.zip
chromium_src-02dbca0bce56a1ef5e53c8f446eef38df2f62e8f.tar.gz
chromium_src-02dbca0bce56a1ef5e53c8f446eef38df2f62e8f.tar.bz2
chromeos: implement persistence of proxy config to device, enhance unittest
- during storing, all info in proxy config is serialized into a dictionary and persisted to device via SignedSettings::StoragePropertyOp - during retrieving, value is retrieved from device via SignedSettings::RetrievePropertyOp and deserialized into proxy config - modify API to return bool when setting proxy config from UI - in DOMUI design, every interaction with the page triggers a call to update config in backend - but, sometimes, the info is incomplete, e.g. single-proxy checkbox is checked but proxy server is still empty - for such cases, config service caches the info (so that UI can get this info on the next Get), but doesn't activate or persist it, and returns false to UI - wrote unittests for configuring socks proxy and bypass rules, serialize and deserialize, update unittest for code changes - handle using stub implementation of libcros to make browser tests pass BUG=chromium_os:5127 TEST=as owner, modify proxy config from UI, log out or reboot device, verify that proxy config is updated. Review URL: http://codereview.chromium.org/3366028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59772 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/proxy_config_service_impl.h')
-rw-r--r--chrome/browser/chromeos/proxy_config_service_impl.h87
1 files changed, 77 insertions, 10 deletions
diff --git a/chrome/browser/chromeos/proxy_config_service_impl.h b/chrome/browser/chromeos/proxy_config_service_impl.h
index c22f1a5..e8e184d 100644
--- a/chrome/browser/chromeos/proxy_config_service_impl.h
+++ b/chrome/browser/chromeos/proxy_config_service_impl.h
@@ -13,6 +13,8 @@
#include "base/observer_list.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/login/signed_settings.h"
#include "net/proxy/proxy_config.h"
#include "net/proxy/proxy_config_service.h"
#include "net/proxy/proxy_server.h"
@@ -32,7 +34,9 @@ namespace chromeos {
// - TODO(kuan): persists proxy configuration settings on chromeos device using
// cros settings
class ProxyConfigServiceImpl
- : public base::RefCountedThreadSafe<ProxyConfigServiceImpl> {
+ : public base::RefCountedThreadSafe<ProxyConfigServiceImpl>,
+ 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
@@ -84,25 +88,40 @@ class ProxyConfigServiceImpl
struct Setting {
Setting() : source(SOURCE_NONE) {}
+ bool CanBeWrittenByUser(bool user_is_owner);
+ virtual DictionaryValue* Encode() const;
+ bool Decode(DictionaryValue* dict);
Source source;
- bool CanBeWrittenByUser(bool user_is_owner);
};
// Proxy setting for mode = direct or auto-detect or using pac script.
struct AutomaticProxy : public Setting {
+ virtual DictionaryValue* Encode() const;
+ bool Decode(DictionaryValue* dict, Mode mode);
+
GURL pac_url; // Set if proxy is using pac script.
};
// Proxy setting for mode = single-proxy or proxy-per-scheme.
struct ManualProxy : public Setting {
+ virtual DictionaryValue* Encode() const;
+ bool Decode(DictionaryValue* dict, net::ProxyServer::Scheme scheme);
+
net::ProxyServer server;
};
ProxyConfig() : mode(MODE_DIRECT) {}
// Converts |this| to net::ProxyConfig.
- void ConvertToNetProxyConfig(net::ProxyConfig* net_config);
+ void ToNetProxyConfig(net::ProxyConfig* net_config);
+
+ // Serializes config into a DictionaryValue and then into std::string
+ // persisted as property on device.
+ bool Serialize(std::string* output);
+ // Deserializes from property value on device as std::string into a
+ // DictionaryValue and then into the config. Opposite of Serialize.
+ bool Deserialize(const std::string& input);
// Creates a textual dump of the configuration.
std::string ToString() const;
@@ -124,6 +143,17 @@ class ProxyConfigServiceImpl
// Exceptions for when not to use a proxy.
net::ProxyBypassRules bypass_rules;
+
+ private:
+ // 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);
};
// Usual constructor.
@@ -144,20 +174,40 @@ class ProxyConfigServiceImpl
void UIGetProxyConfig(ProxyConfig* config);
// Called from UI thread to update proxy configuration for different modes.
- void UISetProxyConfigToDirect();
- void UISetProxyConfigToAutoDetect();
- void UISetProxyConfigToPACScript(const GURL& url);
- void UISetProxyConfigToSingleProxy(const net::ProxyServer& server);
- void UISetProxyConfigToProxyPerScheme(const std::string& scheme,
+ // Returns true if config is set properly and config service has proceeded to
+ // start activating it on network stack and persisting it to device.
+ // Returns false if config is not set properly, probably because information
+ // is incomplete or invalid; while config service won't proceed to activate or
+ // persist this config, the information is "cached" in the service, so that
+ // the next UIGetProxyConfig call will return this latest information.
+ bool UISetProxyConfigToDirect();
+ bool UISetProxyConfigToAutoDetect();
+ bool UISetProxyConfigToPACScript(const GURL& pac_url);
+ bool UISetProxyConfigToSingleProxy(const net::ProxyServer& server);
+ bool UISetProxyConfigToProxyPerScheme(const std::string& scheme,
const net::ProxyServer& server);
// Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME.
- void UISetProxyConfigBypassRules(const net::ProxyBypassRules& bypass_rules);
+ bool UISetProxyConfigBypassRules(const net::ProxyBypassRules& bypass_rules);
+
+ // Implementation for SignedSettings::Delegate
+ virtual void OnSettingsOpSucceeded(bool value);
+ virtual void OnSettingsOpSucceeded(std::string value);
+ virtual void OnSettingsOpFailed();
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);
+
+ // Persists proxy config to device.
+ void PersistConfigToDevice();
+
// Called from UI thread from the various UISetProxyConfigTo*
- void OnUISetProxyConfig();
+ // |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);
@@ -170,6 +220,17 @@ class ProxyConfigServiceImpl
// Data members.
+ // True if tasks can be posted, which can only happen if constructor has
+ // completed (NewRunnableMethod cannot be created for a RefCountedThreadBase's
+ // method until the class's ref_count is at least one).
+ bool can_post_task_;
+
+ // True if config has been fetched from device or initialized properly.
+ bool has_config_;
+
+ // 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
@@ -181,8 +242,14 @@ class ProxyConfigServiceImpl
// are called by UI to set new proxy but the config has not actually changed.
ProxyConfig reference_config_;
+ // List of observers for changes in proxy config.
ObserverList<net::ProxyConfigService::Observer> observers_;
+ // Operations to retrieve and store proxy setting from and to device
+ // respectively.
+ scoped_refptr<SignedSettings> retrieve_property_op_;
+ scoped_refptr<SignedSettings> store_property_op_;
+
DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl);
};