proxy_config_service_impl.h revision 868fa2fe829687343ffae624259930155e16dbd8
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/basictypes.h" 11#include "base/compiler_specific.h" 12#include "base/prefs/pref_member.h" 13#include "chrome/browser/net/pref_proxy_config_tracker_impl.h" 14#include "chromeos/network/network_state_handler_observer.h" 15#include "chromeos/network/onc/onc_constants.h" 16 17class PrefRegistrySimple; 18 19namespace user_prefs { 20class PrefRegistrySyncable; 21} 22 23namespace chromeos { 24 25class NetworkState; 26 27// Implementation of proxy config service for chromeos that: 28// - extends PrefProxyConfigTrackerImpl (and so lives and runs entirely on UI 29// thread) to handle proxy from prefs (via PrefProxyConfigTrackerImpl) and 30// system i.e. network (via shill notifications) 31// - exists one per profile and one per local state 32// - persists proxy setting per network in flimflim 33// - provides network stack with latest effective proxy configuration for 34// currently active network via PrefProxyConfigTrackerImpl's mechanism of 35// pushing config to ChromeProxyConfigService 36class ProxyConfigServiceImpl : public PrefProxyConfigTrackerImpl, 37 public NetworkStateHandlerObserver { 38 public: 39 // ProxyConfigServiceImpl is created in ProxyServiceFactory:: 40 // CreatePrefProxyConfigTrackerImpl via Profile::GetProxyConfigTracker() for 41 // profile or IOThread constructor for local state and is owned by the 42 // respective classes. 43 // 44 // The new modified proxy config, together with proxy from prefs if available, 45 // are used to determine the effective proxy config, which is then pushed 46 // through PrefProxyConfigTrackerImpl to ChromeProxyConfigService to the 47 // network stack. 48 explicit ProxyConfigServiceImpl(PrefService* pref_service); 49 virtual ~ProxyConfigServiceImpl(); 50 51 // PrefProxyConfigTrackerImpl implementation. 52 virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state, 53 const net::ProxyConfig& config) OVERRIDE; 54 55 // NetworkStateHandlerObserver implementation. 56 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE; 57 58 // Register UseShardProxies preference. 59 static void RegisterPrefs(PrefRegistrySimple* registry); 60 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); 61 62 protected: 63 friend class UIProxyConfigService; 64 65 // Returns value of UseSharedProxies preference if it's not default, else 66 // returns false if user is logged in and true otherwise. 67 static bool GetUseSharedProxies(const PrefService* pref_service); 68 69 // Returns true if proxy is to be ignored for this profile and |onc_source|, 70 // e.g. this happens if the network is shared and use-shared-proxies is turned 71 // off. 72 static bool IgnoreProxy(const PrefService* pref_service, 73 const std::string network_profile_path, 74 onc::ONCSource onc_source); 75 76 private: 77 // Called when the kUseSharedProxies preference changes. 78 void OnUseSharedProxiesChanged(); 79 80 // Determines effective proxy config based on prefs from config tracker, the 81 // current default network and if user is using shared proxies. The effective 82 // config is stored in |active_config_| and activated on network stack, and 83 // hence, picked up by observers. 84 void DetermineEffectiveConfigFromDefaultNetwork(); 85 86 // State of |active_config_|. |active_config_| is only valid if 87 // |active_config_state_| is not ProxyPrefs::CONFIG_UNSET. 88 ProxyPrefs::ConfigState active_config_state_; 89 90 // Active proxy configuration, which could be from prefs or network. 91 net::ProxyConfig active_config_; 92 93 // Track changes in UseSharedProxies user preference. 94 BooleanPrefMember use_shared_proxies_; 95 96 base::WeakPtrFactory<ProxyConfigServiceImpl> pointer_factory_; 97 98 DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl); 99}; 100 101} // namespace chromeos 102 103#endif // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_ 104