| OLD | NEW |
| 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/memory/ref_counted.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/observer_list.h" | |
| 16 #include "base/values.h" | 13 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/cros/network_library.h" | 14 #include "chrome/browser/chromeos/cros/network_library.h" |
| 18 #include "chrome/browser/chromeos/login/signed_settings.h" | 15 #include "chrome/browser/chromeos/login/signed_settings.h" |
| 19 #include "net/proxy/proxy_config.h" | 16 #include "chrome/browser/net/pref_proxy_config_tracker.h" |
| 20 #include "net/proxy/proxy_config_service.h" | 17 #include "chrome/browser/prefs/pref_member.h" |
| 21 #include "net/proxy/proxy_server.h" | |
| 22 | 18 |
| 23 namespace chromeos { | 19 namespace chromeos { |
| 24 | 20 |
| 25 // Implementation of proxy config service for chromeos that: | 21 // Implementation of proxy config service for chromeos that: |
| 26 // - is RefCountedThreadSafe | 22 // - extends PrefProxyConfigTracker (and so lives and runs entirely on UI |
| 27 // - is wrapped by chromeos::ProxyConfigService which implements | 23 // thread) to handle proxy from prefs (via PrefProxyConfigTracker) and system |
| 28 // net::ProxyConfigService interface by fowarding the methods to this class | 24 // i.e. network (via flimflam notifications) |
| 25 // - exists one per profile and one per local state |
| 29 // - retrieves initial system proxy configuration from cros settings persisted | 26 // - retrieves initial system proxy configuration from cros settings persisted |
| 30 // on chromeos device from chromeos revisions before migration to flimflam, | 27 // on chromeos device from chromeos revisions before migration to flimflam, |
| 31 // - persists proxy setting per network in flimflim | 28 // - persists proxy setting per network in flimflim |
| 32 // - provides network stack with latest proxy configuration for currently | 29 // - provides network stack with latest effective proxy configuration for |
| 33 // active network for use on IO thread | 30 // currently active network via PrefProxyConfigTracker's mechanism of pushing |
| 31 // config to ChromeProxyConfigService |
| 34 // - provides UI with methods to retrieve and modify proxy configuration for | 32 // - provides UI with methods to retrieve and modify proxy configuration for |
| 35 // any network (either currently active or non-active) on UI thread | 33 // any remembered network (either currently active or non-active) of current |
| 34 // user profile |
| 36 class ProxyConfigServiceImpl | 35 class ProxyConfigServiceImpl |
| 37 : public base::RefCountedThreadSafe<ProxyConfigServiceImpl>, | 36 : public PrefProxyConfigTracker, |
| 38 public SignedSettings::Delegate<std::string>, | 37 public SignedSettings::Delegate<std::string>, |
| 39 public NetworkLibrary::NetworkManagerObserver, | 38 public NetworkLibrary::NetworkManagerObserver, |
| 40 public NetworkLibrary::NetworkObserver { | 39 public NetworkLibrary::NetworkObserver { |
| 41 public: | 40 public: |
| 42 // ProxyConfigServiceImpl is created on the UI thread in | 41 // ProxyConfigServiceImpl is created in ProxyServiceFactory:: |
| 43 // chrome/browser/net/proxy_service_factory.cc::CreateProxyConfigService | 42 // CreatePrefProxyConfigTracker via Profile::GetProxyConfigTracker() for |
| 44 // via BrowserProcess::chromeos_proxy_config_service_impl, and stored in | 43 // profile or IOThread constructor for local state and is owned by the |
| 45 // g_browser_process as a scoped_refptr (because it's RefCountedThreadSafe). | 44 // respective classes. |
| 46 // | 45 // |
| 47 // Past that point, it can be accessed from the IO or UI threads. | 46 // From the UI, it is accessed via Profile::GetProxyConfigTracker to allow |
| 47 // user to read or modify the proxy configuration via UIGetProxyConfig or |
| 48 // UISetProxyConfigTo* respectively. |
| 49 // The new modified proxy config, together with proxy from prefs if available, |
| 50 // are used to determine the effective proxy config, which is then pushed |
| 51 // through PrefProxyConfigTracker to ChromeProxyConfigService to the network |
| 52 // stack. |
| 48 // | 53 // |
| 49 // From the IO thread, it is accessed periodically through the wrapper class | |
| 50 // chromeos::ProxyConfigService via net::ProxyConfigService interface | |
| 51 // (GetLatestProxyConfig, AddObserver, RemoveObserver). | |
| 52 // | |
| 53 // From the UI thread, it is accessed via | |
| 54 // BrowserProcess::chromeos_proxy_config_service_impl to allow user to read | |
| 55 // or modify the proxy configuration via UIGetProxyConfig or | |
| 56 // UISetProxyConfigTo* respectively. | |
| 57 // The new modified proxy config is posted to the IO thread through | |
| 58 // SetNewProxyConfig(). We then notify observers on the IO thread of the | |
| 59 // configuration change. | |
| 60 | |
| 61 // In contrary to other platforms which simply use the systems' UI to allow | 54 // In contrary to other platforms which simply use the systems' UI to allow |
| 62 // users to configure proxies, we have to implement our own UI on the chromeos | 55 // users to configure proxies, we have to implement our own UI on the chromeos |
| 63 // device. This requires extra and specific UI requirements that | 56 // device. This requires extra and specific UI requirements that |
| 64 // net::ProxyConfig does not suffice. So we create an augmented analog to | 57 // net::ProxyConfig does not suffice. So we create an augmented analog to |
| 65 // net:ProxyConfig here to include and handle these UI requirements, e.g. | 58 // net:ProxyConfig here to include and handle these UI requirements, e.g. |
| 66 // - where configuration was picked up from - policy or owner | 59 // - where configuration was picked up from - policy, extension, etc (refer |
| 60 // to ProxyPrefs::ConfigSource) |
| 67 // - the read/write access of a proxy setting | 61 // - the read/write access of a proxy setting |
| 68 // - may add more stuff later. | 62 // - may add more stuff later. |
| 69 // This is then converted to the common net::ProxyConfig before being returned | 63 // This is then converted to the common net::ProxyConfig before being pushed |
| 70 // to ProxyService::GetLatestProxyConfig on the IO thread to be used on the | 64 // to PrefProxyConfigTracker::OnProxyConfigChanged and then to the network |
| 71 // network stack. | 65 // stack. |
| 72 struct ProxyConfig { | 66 struct ProxyConfig { |
| 73 // Specifies if proxy config is direct, auto-detect, using pac script, | 67 // Specifies if proxy config is direct, auto-detect, using pac script, |
| 74 // single-proxy, or proxy-per-scheme. | 68 // single-proxy, or proxy-per-scheme. |
| 75 enum Mode { | 69 enum Mode { |
| 76 MODE_DIRECT, | 70 MODE_DIRECT, |
| 77 MODE_AUTO_DETECT, | 71 MODE_AUTO_DETECT, |
| 78 MODE_PAC_SCRIPT, | 72 MODE_PAC_SCRIPT, |
| 79 MODE_SINGLE_PROXY, | 73 MODE_SINGLE_PROXY, |
| 80 MODE_PROXY_PER_SCHEME, | 74 MODE_PROXY_PER_SCHEME, |
| 81 }; | 75 }; |
| 82 | 76 |
| 83 // Specifies where proxy configuration was picked up from. | |
| 84 enum Source { | |
| 85 SOURCE_NONE, // No default configuration. | |
| 86 SOURCE_POLICY, // Configuration is from policy. | |
| 87 SOURCE_OWNER, // Configuration is from owner. | |
| 88 }; | |
| 89 | |
| 90 struct Setting { | |
| 91 Setting() : source(SOURCE_NONE) {} | |
| 92 bool CanBeWrittenByUser(bool user_is_owner); | |
| 93 | |
| 94 Source source; | |
| 95 }; | |
| 96 | |
| 97 // Proxy setting for mode = direct or auto-detect or using pac script. | 77 // Proxy setting for mode = direct or auto-detect or using pac script. |
| 98 struct AutomaticProxy : public Setting { | 78 struct AutomaticProxy { |
| 99 GURL pac_url; // Set if proxy is using pac script. | 79 GURL pac_url; // Set if proxy is using pac script. |
| 100 }; | 80 }; |
| 101 | 81 |
| 102 // Proxy setting for mode = single-proxy or proxy-per-scheme. | 82 // Proxy setting for mode = single-proxy or proxy-per-scheme. |
| 103 struct ManualProxy : public Setting { | 83 struct ManualProxy { |
| 104 net::ProxyServer server; | 84 net::ProxyServer server; |
| 105 }; | 85 }; |
| 106 | 86 |
| 107 ProxyConfig(); | 87 ProxyConfig(); |
| 108 ~ProxyConfig(); | 88 ~ProxyConfig(); |
| 109 | 89 |
| 110 // Converts |this| to net::ProxyConfig. | 90 // Converts |this| to net::ProxyConfig. |
| 111 void ToNetProxyConfig(net::ProxyConfig* net_config); | 91 void ToNetProxyConfig(net::ProxyConfig* net_config); |
| 112 | 92 |
| 113 // Returns true if proxy config can be written by user. | 93 // Converts net::ProxyConfig to |this|. |
| 114 // If mode is MODE_PROXY_PER_SCHEME, |scheme| is one of "http", "https", | 94 bool FromNetProxyConfig(const net::ProxyConfig& net_config); |
| 115 // "ftp" or "socks"; otherwise, it should be empty or will be ignored. | 95 |
| 116 bool CanBeWrittenByUser(bool user_is_owner, const std::string& scheme); | 96 // Converts |this| to Dictionary of ProxyConfigDictionary format (which |
| 97 // is the same format used by prefs). |
| 98 DictionaryValue* ToPrefProxyConfig(); |
| 99 |
| 100 // Converts |this| from Dictionary of ProxyConfigDictionary format. |
| 101 bool FromPrefProxyConfig(const DictionaryValue* proxy_dict); |
| 117 | 102 |
| 118 // Map |scheme| (one of "http", "https", "ftp" or "socks") to the correct | 103 // Map |scheme| (one of "http", "https", "ftp" or "socks") to the correct |
| 119 // ManualProxy. Returns NULL if scheme is invalid. | 104 // ManualProxy. Returns NULL if scheme is invalid. |
| 120 ManualProxy* MapSchemeToProxy(const std::string& scheme); | 105 ManualProxy* MapSchemeToProxy(const std::string& scheme); |
| 121 | 106 |
| 122 // We've migrated device settings to flimflam, so we only need to | 107 // We've migrated device settings to flimflam, so we only need to |
| 123 // deserialize previously persisted device settings. | 108 // deserialize previously persisted device settings. |
| 124 // Deserializes from signed setting on device as std::string into a | 109 // Deserializes from signed setting on device as std::string into a |
| 125 // protobuf and then into the config. | 110 // protobuf and then into the config. |
| 126 bool DeserializeForDevice(const std::string& input); | 111 bool DeserializeForDevice(const std::string& input); |
| 127 | 112 |
| 128 // Serializes config into a ProxyConfigDictionary and then std::string | 113 // Serializes config into a ProxyConfigDictionary and then std::string |
| 129 // persisted as string property in flimflam for a network. | 114 // persisted as string property in flimflam for a network. |
| 130 bool SerializeForNetwork(std::string* output); | 115 bool SerializeForNetwork(std::string* output); |
| 131 | 116 |
| 132 // Deserializes from string property in flimflam for a network into a | 117 // Deserializes from string property in flimflam for a network into a |
| 133 // ProxyConfigDictionary and then into the config. | 118 // ProxyConfigDictionary and then into the config. |
| 134 // Opposite of SerializeForNetwork. | 119 // Opposite of SerializeForNetwork. |
| 135 bool DeserializeForNetwork(const std::string& input); | 120 bool DeserializeForNetwork(const std::string& input); |
| 136 | 121 |
| 137 // Returns true if the given config is equivalent to this config. | 122 // Returns true if the given config is equivalent to this config. |
| 138 bool Equals(const ProxyConfig& other) const; | 123 bool Equals(const ProxyConfig& other) const; |
| 139 | 124 |
| 140 // Creates a textual dump of the configuration. | 125 Mode mode; |
| 141 std::string ToString() const; | |
| 142 | 126 |
| 143 Mode mode; | 127 ProxyPrefs::ConfigState state; |
| 128 |
| 129 // True if user can modify proxy settings via UI. |
| 130 // If proxy is managed by policy or extension or other_precde or is for |
| 131 // shared network but kUseSharedProxies is turned off, it can't be modified |
| 132 // by user. |
| 133 bool user_modifiable; |
| 144 | 134 |
| 145 // Set if mode is MODE_DIRECT or MODE_AUTO_DETECT or MODE_PAC_SCRIPT. | 135 // Set if mode is MODE_DIRECT or MODE_AUTO_DETECT or MODE_PAC_SCRIPT. |
| 146 AutomaticProxy automatic_proxy; | 136 AutomaticProxy automatic_proxy; |
| 147 // Set if mode is MODE_SINGLE_PROXY. | 137 // Set if mode is MODE_SINGLE_PROXY. |
| 148 ManualProxy single_proxy; | 138 ManualProxy single_proxy; |
| 149 // Set if mode is MODE_PROXY_PER_SCHEME and has http proxy. | 139 // Set if mode is MODE_PROXY_PER_SCHEME and has http proxy. |
| 150 ManualProxy http_proxy; | 140 ManualProxy http_proxy; |
| 151 // Set if mode is MODE_PROXY_PER_SCHEME and has https proxy. | 141 // Set if mode is MODE_PROXY_PER_SCHEME and has https proxy. |
| 152 ManualProxy https_proxy; | 142 ManualProxy https_proxy; |
| 153 // Set if mode is MODE_PROXY_PER_SCHEME and has ftp proxy. | 143 // Set if mode is MODE_PROXY_PER_SCHEME and has ftp proxy. |
| 154 ManualProxy ftp_proxy; | 144 ManualProxy ftp_proxy; |
| 155 // Set if mode is MODE_PROXY_PER_SCHEME and has socks proxy. | 145 // Set if mode is MODE_PROXY_PER_SCHEME and has socks proxy. |
| 156 ManualProxy socks_proxy; | 146 ManualProxy socks_proxy; |
| 157 | 147 |
| 158 // Exceptions for when not to use a proxy. | 148 // Exceptions for when not to use a proxy. |
| 159 net::ProxyBypassRules bypass_rules; | 149 net::ProxyBypassRules bypass_rules; |
| 160 | 150 |
| 161 private: | 151 private: |
| 162 // Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>" | 152 // Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>" |
| 163 static void EncodeAndAppendProxyServer(const std::string& scheme, | 153 static void EncodeAndAppendProxyServer(const std::string& scheme, |
| 164 const net::ProxyServer& server, | 154 const net::ProxyServer& server, |
| 165 std::string* spec); | 155 std::string* spec); |
| 166 | |
| 167 // Converts |this| to Dictionary of ProxyConfigDictionary format (which | |
| 168 // is the same format used by prefs). | |
| 169 DictionaryValue* ToPrefProxyConfig(); | |
| 170 | |
| 171 // Converts |this| from Dictionary of ProxyConfigDictionary format. | |
| 172 bool FromPrefProxyConfig(const DictionaryValue* proxy_dict); | |
| 173 }; | 156 }; |
| 174 | 157 |
| 175 // Usual constructor. | 158 // Constructor. |
| 176 ProxyConfigServiceImpl(); | 159 explicit ProxyConfigServiceImpl(PrefService* pref_service); |
| 177 // Constructor for testing. | |
| 178 // |init_config| specifies the ProxyConfig to use for initialization. | |
| 179 explicit ProxyConfigServiceImpl(const ProxyConfig& init_config); | |
| 180 virtual ~ProxyConfigServiceImpl(); | 160 virtual ~ProxyConfigServiceImpl(); |
| 181 | 161 |
| 182 // Methods called on IO thread from wrapper class chromeos::ProxyConfigService | 162 // Called by UI to set service path of |network| to be displayed or edited. |
| 183 // as ProxyConfigService methods. | 163 // Subsequent UISet* methods will use this network, until UI calls it again |
| 184 void AddObserver(net::ProxyConfigService::Observer* observer); | 164 // with a different network. |
| 185 void RemoveObserver(net::ProxyConfigService::Observer* observer); | 165 void UISetCurrentNetwork(const std::string& current_network); |
| 186 // Called from GetLatestProxyConfig. | |
| 187 net::ProxyConfigService::ConfigAvailability IOGetProxyConfig( | |
| 188 net::ProxyConfig* config); | |
| 189 | 166 |
| 190 // Called from UI thread to retrieve proxy configuration in |config|. | 167 // Called from UI to make the currently active network the one to be displayed |
| 191 void UIGetProxyConfig(ProxyConfig* config); | 168 // or edited. Subsequent UISet* methods will use this network until UI calls |
| 169 // it again when the active network has changed. |
| 170 void UIMakeActiveNetworkCurrent(); |
| 192 | 171 |
| 193 // Called from UI thread to set service path of network to be displayed or | 172 // Called from UI to get name of the current active network. |
| 194 // edited. Subsequent UISet* methods will use this network, until UI calls | |
| 195 // it again with a different network. | |
| 196 bool UISetCurrentNetwork(const std::string& current_network); | |
| 197 | |
| 198 // Called from UI thread to make the currently active network the one to be | |
| 199 // displayed or edited. Subsequent UISet* methods will use this network. until | |
| 200 // UI calls it again when the active network has changed. | |
| 201 bool UIMakeActiveNetworkCurrent(); | |
| 202 | |
| 203 // Called from UI thread to get name of the current active network. | |
| 204 const std::string& current_network_name() const { | 173 const std::string& current_network_name() const { |
| 205 return current_ui_network_name_; | 174 return current_ui_network_name_; |
| 206 } | 175 } |
| 207 | 176 |
| 208 // Called from UI thread to set/get user preference use_shared_proxies. | 177 // Called from UI to retrieve proxy configuration in |current_ui_config_|. |
| 209 void UISetUseSharedProxies(bool use_shared); | 178 void UIGetProxyConfig(ProxyConfig* config); |
| 210 bool use_shared_proxies() const { | |
| 211 return use_shared_proxies_; | |
| 212 } | |
| 213 | 179 |
| 214 // Called from UI thread to update proxy configuration for different modes. | 180 // Called from UI to update proxy configuration for different modes. |
| 215 // Returns true if config is set properly and persisted to flimflam for the | 181 // Returns true if config is set properly and persisted to flimflam for the |
| 216 // current network (set via UISetCurrentNetwork/UIMakeActiveNetworkCurrent). | 182 // current network (set via UISetCurrentNetwork/UIMakeActiveNetworkCurrent). |
| 217 // If this network is also currently active, config service proceeds to start | 183 // If this network is also currently active, config service proceeds to start |
| 218 // activating it on network stack. | 184 // activating it on network stack. |
| 219 // Returns false if config is not set properly, probably because information | 185 // Returns false if config is not set properly, probably because information |
| 220 // is incomplete or invalid; while config service won't proceed to activate or | 186 // is incomplete or invalid; while config service won't proceed to activate or |
| 221 // persist this config, the information is "cached" in the service, so that | 187 // persist this config, the information is "cached" in the service, so that |
| 222 // the next UIGetProxyConfig call will return this latest information. | 188 // the next UIGetProxyConfig call will return this latest information. |
| 223 bool UISetProxyConfigToDirect(); | 189 bool UISetProxyConfigToDirect(); |
| 224 bool UISetProxyConfigToAutoDetect(); | 190 bool UISetProxyConfigToAutoDetect(); |
| 225 bool UISetProxyConfigToPACScript(const GURL& pac_url); | 191 bool UISetProxyConfigToPACScript(const GURL& pac_url); |
| 226 bool UISetProxyConfigToSingleProxy(const net::ProxyServer& server); | 192 bool UISetProxyConfigToSingleProxy(const net::ProxyServer& server); |
| 227 // |scheme| is one of "http", "https", "ftp" or "socks". | 193 // |scheme| is one of "http", "https", "ftp" or "socks". |
| 228 bool UISetProxyConfigToProxyPerScheme(const std::string& scheme, | 194 bool UISetProxyConfigToProxyPerScheme(const std::string& scheme, |
| 229 const net::ProxyServer& server); | 195 const net::ProxyServer& server); |
| 230 // Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME. | 196 // Only valid for MODE_SINGLE_PROXY or MODE_PROXY_PER_SCHEME. |
| 231 bool UISetProxyConfigBypassRules(const net::ProxyBypassRules& bypass_rules); | 197 bool UISetProxyConfigBypassRules(const net::ProxyBypassRules& bypass_rules); |
| 232 | 198 |
| 233 // Implementation for SignedSettings::Delegate | 199 // Implementation for SignedSettings::Delegate |
| 234 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, | 200 virtual void OnSettingsOpCompleted(SignedSettings::ReturnCode code, |
| 235 std::string value); | 201 std::string value); |
| 236 | 202 |
| 237 // NetworkLibrary::NetworkManagerObserver implementation. | 203 // NetworkLibrary::NetworkManagerObserver implementation. |
| 238 virtual void OnNetworkManagerChanged(NetworkLibrary* cros); | 204 virtual void OnNetworkManagerChanged(NetworkLibrary* cros); |
| 239 | 205 |
| 240 // NetworkLibrary::NetworkObserver implementation. | 206 // NetworkLibrary::NetworkObserver implementation. |
| 241 virtual void OnNetworkChanged(NetworkLibrary* cros, const Network* network); | 207 virtual void OnNetworkChanged(NetworkLibrary* cros, const Network* network); |
| 242 | 208 |
| 209 // PrefProxyConfigTracker implementation. |
| 210 virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state, |
| 211 const net::ProxyConfig& config); |
| 212 |
| 243 #if defined(UNIT_TEST) | 213 #if defined(UNIT_TEST) |
| 244 void SetTesting() { | 214 void SetTesting(ProxyConfig* test_config) { |
| 245 testing_ = true; | |
| 246 active_network_ = "test"; | |
| 247 UIMakeActiveNetworkCurrent(); | 215 UIMakeActiveNetworkCurrent(); |
| 216 if (test_config) { |
| 217 std::string value; |
| 218 test_config->SerializeForNetwork(&value); |
| 219 SetProxyConfigForNetwork(active_network_, value, false); |
| 220 } |
| 248 } | 221 } |
| 249 #endif // defined(UNIT_TEST) | 222 #endif // defined(UNIT_TEST) |
| 250 | 223 |
| 251 private: | 224 private: |
| 252 friend class base::RefCountedThreadSafe<ProxyConfigServiceImpl>; | 225 // Called from the various UISetProxyConfigTo*. |
| 253 | |
| 254 // Called from UI thread from the various UISetProxyConfigTo*. | |
| 255 void OnUISetProxyConfig(); | 226 void OnUISetProxyConfig(); |
| 256 | 227 |
| 257 // Posted from UI thread to IO thread to carry the new config information. | |
| 258 void IOSetProxyConfig( | |
| 259 const ProxyConfig& new_config, | |
| 260 net::ProxyConfigService::ConfigAvailability new_availability); | |
| 261 | |
| 262 // Called from OnNetworkManagerChanged and OnNetworkChanged for currently | 228 // Called from OnNetworkManagerChanged and OnNetworkChanged for currently |
| 263 // active network, to handle previously active network, new active network, | 229 // active network, to handle previously active network, new active network, |
| 264 // and if necessary, migrates device settings to flimflam and/or activates | 230 // and if necessary, migrates device settings to flimflam and/or activates |
| 265 // proxy setting of new network. | 231 // proxy setting of new network. |
| 266 void OnActiveNetworkChanged(NetworkLibrary* cros, | 232 void OnActiveNetworkChanged(NetworkLibrary* cros, |
| 267 const Network* active_network); | 233 const Network* active_network); |
| 268 | 234 |
| 269 // Sets proxy config for |network_path| into flimflam and activates setting | 235 // Sets proxy config for |network_path| into flimflam and activates setting |
| 270 // if the network is currently active. | 236 // if the network is currently active. If |only_set_if_empty| is true, |
| 237 // proxy will be set and saved only if network has no proxy. |
| 271 void SetProxyConfigForNetwork(const std::string& network_path, | 238 void SetProxyConfigForNetwork(const std::string& network_path, |
| 272 const std::string& value, | 239 const std::string& value, |
| 273 bool only_set_if_empty); | 240 bool only_set_if_empty); |
| 274 | 241 |
| 275 // Determines and activates proxy config of |network| based on if network is | 242 // Sets the use-shared-proxies user pref; if this triggers new effective |
| 276 // shared/private or user is using shared proxies, etc. | 243 // config, activate it. |
| 277 void DetermineConfigFromNetwork(const Network* network); | 244 void SetUseSharedProxies(bool use_shared); |
| 278 | 245 |
| 279 // Set |current_ui_network_name_| with name of |network|. | 246 // Determines effective proxy config based on prefs from config tracker, |
| 280 void SetCurrentNetworkName(const Network* network); | 247 // |network| and if user is using shared proxies. |
| 248 // If |activate| is true, effective config is stored in |active_config_| and |
| 249 // activated on network stack, and hence, picked up by observers. |
| 250 // if |activate| is false, effective config is stored in |current_ui_config_| |
| 251 // but not activated on network stack, and hence, not picked up by observers. |
| 252 void DetermineEffectiveConfig(const Network* network, bool activate); |
| 281 | 253 |
| 282 // Checks that method is called on BrowserThread::IO thread. | 254 // Determines UI-related variables (|current_network_name_| and |
| 283 void CheckCurrentlyOnIOThread(); | 255 // |current_ui_config_|) based on |network|, called from UISetCurrentNetwork |
| 256 // and UIMakeActiveNetworkActive. |
| 257 void OnUISetCurrentNetwork(const Network* network); |
| 284 | 258 |
| 285 // Checks that method is called on BrowserThread::UI thread. | 259 // NotificationObserver implementation. |
| 286 void CheckCurrentlyOnUIThread(); | 260 virtual void Observe(int type, |
| 261 const NotificationSource& source, |
| 262 const NotificationDetails& details); |
| 263 |
| 264 // Returns true if proxy is to be ignored for network, which happens if |
| 265 // network is shared and use-shared-proxies is turned off. |
| 266 bool IgnoreProxy(const Network* network) { |
| 267 return network->profile_type() == PROFILE_SHARED && !use_shared_proxies_; |
| 268 } |
| 269 |
| 270 // Reset UI cache variables that keep track of UI activities. |
| 271 void ResetUICache(); |
| 287 | 272 |
| 288 // Data members. | 273 // Data members. |
| 289 | 274 |
| 290 // True if running unit_tests, which will need to specifically exclude | 275 // Service path of currently active network (determined via flimflam |
| 291 // flimflam logic. | 276 // notifications); if effective proxy config is from system, proxy of this |
| 292 bool testing_; | 277 // network will be the one taking effect. |
| 278 std::string active_network_; |
| 293 | 279 |
| 294 // True if tasks can be posted, which can only happen if constructor has | 280 // State of |active_config_|. |active_config_| is only valid if |
| 295 // completed (NewRunnableMethod cannot be created for a RefCountedThreadBase's | 281 // |active_config_state_| is not ProxyPrefs::CONFIG_UNSET. |
| 296 // method until the class's ref_count is at least one). | 282 ProxyPrefs::ConfigState active_config_state_; |
| 297 bool can_post_task_; | |
| 298 | 283 |
| 299 // Availability status of the configuration, initialized on UI thread, but | 284 // Active proxy configuration, which could be from prefs or network. |
| 300 // afterwards only accessed from IO thread. | |
| 301 net::ProxyConfigService::ConfigAvailability config_availability_; | |
| 302 | |
| 303 // Service path of currently active network (determined via flimflam | |
| 304 // notifications) whose proxy config is taking effect. | |
| 305 std::string active_network_; | |
| 306 // Proxy configuration of |active_network_|, only accessed from UI thread. | |
| 307 ProxyConfig active_config_; | 285 ProxyConfig active_config_; |
| 308 | 286 |
| 309 // Proxy config retreived from device, in format generated from | 287 // Proxy config retreived from device, in format generated from |
| 310 // SerializeForNetwork, that can be directly set into flimflam. | 288 // SerializeForNetwork, that can be directly set into flimflam. |
| 311 std::string device_config_; | 289 std::string device_config_; |
| 312 | 290 |
| 313 // Cached proxy configuration, to be converted to net::ProxyConfig and | 291 // True if user preference UseSharedProxies is true. |
| 314 // returned by IOGetProxyConfig. | 292 bool use_shared_proxies_; |
| 315 // Initially populated from UI thread, but afterwards only accessed from IO | |
| 316 // thread. | |
| 317 ProxyConfig cached_config_; | |
| 318 | 293 |
| 319 // Service path of network whose proxy configuration is being displayed or | 294 // Service path of network whose proxy configuration is being displayed or |
| 320 // edited via UI, separate from |active_network_| which may be same or | 295 // edited via UI, separate from |active_network_| which may be same or |
| 321 // different. | 296 // different. |
| 322 std::string current_ui_network_; | 297 std::string current_ui_network_; |
| 323 | 298 |
| 324 // Name of network with current_ui_network_, set in UIMakeActiveNetworkCurrent | 299 // Name of network with current_ui_network_, set in UISetCurrentNetwork and |
| 325 // and UISetCurrentNetwork. | 300 // UIMakeActiveNetworkCurrent. |
| 326 std::string current_ui_network_name_; | 301 std::string current_ui_network_name_; |
| 327 | 302 |
| 328 // Proxy configuration of |current_ui_network|. | 303 // Proxy configuration of |current_ui_network_|. |
| 329 ProxyConfig current_ui_config_; | 304 ProxyConfig current_ui_config_; |
| 330 | 305 |
| 331 // True if user preference UseSharedProxies is true. | 306 // Track changes in user preference UseSharedProxies. |
| 332 bool use_shared_proxies_; | 307 BooleanPrefMember use_shared_proxies_pref_; |
| 333 | |
| 334 // List of observers for changes in proxy config. | |
| 335 ObserverList<net::ProxyConfigService::Observer> observers_; | |
| 336 | 308 |
| 337 // Operation to retrieve proxy setting from device. | 309 // Operation to retrieve proxy setting from device. |
| 338 scoped_refptr<SignedSettings> retrieve_property_op_; | 310 scoped_refptr<SignedSettings> retrieve_property_op_; |
| 339 | 311 |
| 340 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl); | 312 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl); |
| 341 }; | 313 }; |
| 342 | 314 |
| 343 } // namespace chromeos | 315 } // namespace chromeos |
| 344 | 316 |
| 345 #endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ | 317 #endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ |
| OLD | NEW |