| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "chromeos/network/network_state_handler_observer.h" | |
| 13 #include "components/onc/onc_constants.h" | |
| 14 #include "components/prefs/pref_change_registrar.h" | |
| 15 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | |
| 16 | |
| 17 namespace chromeos { | |
| 18 | |
| 19 class NetworkState; | |
| 20 | |
| 21 // Implementation of proxy config service for chromeos that: | |
| 22 // - extends PrefProxyConfigTrackerImpl (and so lives and runs entirely on UI | |
| 23 // thread) to handle proxy from prefs (via PrefProxyConfigTrackerImpl) and | |
| 24 // system i.e. network (via shill notifications) | |
| 25 // - exists one per profile and one per local state | |
| 26 // - persists proxy setting per network in flimflim | |
| 27 // - provides network stack with latest effective proxy configuration for | |
| 28 // currently active network via PrefProxyConfigTrackerImpl's mechanism of | |
| 29 // pushing config to ChromeProxyConfigService | |
| 30 class ProxyConfigServiceImpl : public PrefProxyConfigTrackerImpl, | |
| 31 public NetworkStateHandlerObserver { | |
| 32 public: | |
| 33 // ProxyConfigServiceImpl is created in ProxyServiceFactory:: | |
| 34 // CreatePrefProxyConfigTrackerImpl via Profile::GetProxyConfigTracker() for | |
| 35 // profile or via IOThread constructor for local state and is owned by the | |
| 36 // respective classes. | |
| 37 // | |
| 38 // The user's proxy config, proxy policies and proxy from prefs, are used to | |
| 39 // determine the effective proxy config, which is then pushed through | |
| 40 // PrefProxyConfigTrackerImpl to ChromeProxyConfigService to the | |
| 41 // network stack. | |
| 42 // | |
| 43 // |profile_prefs| can be NULL if this object should only track prefs from | |
| 44 // local state (e.g., for system request context or sigin-in screen). | |
| 45 explicit ProxyConfigServiceImpl(PrefService* profile_prefs, | |
| 46 PrefService* local_state_prefs); | |
| 47 ~ProxyConfigServiceImpl() override; | |
| 48 | |
| 49 // PrefProxyConfigTrackerImpl implementation. | |
| 50 void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state, | |
| 51 const net::ProxyConfig& config) override; | |
| 52 | |
| 53 // NetworkStateHandlerObserver implementation. | |
| 54 void DefaultNetworkChanged(const NetworkState* network) override; | |
| 55 void OnShuttingDown() override; | |
| 56 | |
| 57 // Returns true if proxy is to be ignored for this network profile and | |
| 58 // |onc_source|, e.g. this happens if the network is shared and | |
| 59 // use-shared-proxies is turned off. |profile_prefs| may be NULL. | |
| 60 static bool IgnoreProxy(const PrefService* profile_prefs, | |
| 61 const std::string network_profile_path, | |
| 62 ::onc::ONCSource onc_source); | |
| 63 | |
| 64 // Returns Pref Proxy configuration if available or a proxy config dictionary | |
| 65 // applied to the default network. | |
| 66 // Returns null if no Pref Proxy configuration and no active network. | |
| 67 // |profile_prefs| and |local_state_prefs| must be not null. | |
| 68 static std::unique_ptr<ProxyConfigDictionary> GetActiveProxyConfigDictionary( | |
| 69 const PrefService* profile_prefs, | |
| 70 const PrefService* local_state_prefs); | |
| 71 | |
| 72 private: | |
| 73 // Called when any proxy preference changes. | |
| 74 void OnProxyPrefChanged(); | |
| 75 | |
| 76 // Determines effective proxy config based on prefs from config tracker, the | |
| 77 // current default network and if user is using shared proxies. The effective | |
| 78 // config is stored in |active_config_| and activated on network stack, and | |
| 79 // hence, picked up by observers. | |
| 80 void DetermineEffectiveConfigFromDefaultNetwork(); | |
| 81 | |
| 82 // State of |active_config_|. |active_config_| is only valid if | |
| 83 // |active_config_state_| is not ProxyPrefs::CONFIG_UNSET. | |
| 84 ProxyPrefs::ConfigState active_config_state_; | |
| 85 | |
| 86 // Active proxy configuration, which could be from prefs or network. | |
| 87 net::ProxyConfig active_config_; | |
| 88 | |
| 89 // Track changes in profile preferences: UseSharedProxies and | |
| 90 // OpenNetworkConfiguration. | |
| 91 PrefChangeRegistrar profile_pref_registrar_; | |
| 92 | |
| 93 // Track changes in local state preferences: DeviceOpenNetworkConfiguration. | |
| 94 PrefChangeRegistrar local_state_pref_registrar_; | |
| 95 | |
| 96 // Not owned. NULL if tracking only local state prefs (e.g. in the system | |
| 97 // request context or sign-in screen). | |
| 98 PrefService* profile_prefs_; | |
| 99 | |
| 100 // Not owned. | |
| 101 PrefService* local_state_prefs_; | |
| 102 | |
| 103 base::WeakPtrFactory<ProxyConfigServiceImpl> pointer_factory_; | |
| 104 | |
| 105 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl); | |
| 106 }; | |
| 107 | |
| 108 } // namespace chromeos | |
| 109 | |
| 110 #endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ | |
| OLD | NEW |