7b87cd6efe8cf1088665f31ced1488e1d9561787
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / proxy_config_service_impl.h
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_change_registrar.h"
13 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h"
14 #include "chromeos/network/network_state_handler_observer.h"
15 #include "components/onc/onc_constants.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   virtual ~ProxyConfigServiceImpl();
48
49   // PrefProxyConfigTrackerImpl implementation.
50   virtual void OnProxyConfigChanged(ProxyPrefs::ConfigState config_state,
51                                     const net::ProxyConfig& config) override;
52
53   // NetworkStateHandlerObserver implementation.
54   virtual void DefaultNetworkChanged(const NetworkState* network) override;
55
56  protected:
57   friend class UIProxyConfigService;
58
59   // Returns true if proxy is to be ignored for this network profile and
60   // |onc_source|, e.g. this happens if the network is shared and
61   // use-shared-proxies is turned off. |profile_prefs| may be NULL.
62   static bool IgnoreProxy(const PrefService* profile_prefs,
63                           const std::string network_profile_path,
64                           onc::ONCSource onc_source);
65
66  private:
67   // Called when any proxy preference changes.
68   void OnProxyPrefChanged();
69
70   // Determines effective proxy config based on prefs from config tracker, the
71   // current default network and if user is using shared proxies.  The effective
72   // config is stored in |active_config_| and activated on network stack, and
73   // hence, picked up by observers.
74   void DetermineEffectiveConfigFromDefaultNetwork();
75
76   // State of |active_config_|.  |active_config_| is only valid if
77   // |active_config_state_| is not ProxyPrefs::CONFIG_UNSET.
78   ProxyPrefs::ConfigState active_config_state_;
79
80   // Active proxy configuration, which could be from prefs or network.
81   net::ProxyConfig active_config_;
82
83   // Track changes in profile preferences: UseSharedProxies and
84   // OpenNetworkConfiguration.
85   PrefChangeRegistrar profile_pref_registrar_;
86
87   // Track changes in local state preferences: DeviceOpenNetworkConfiguration.
88   PrefChangeRegistrar local_state_pref_registrar_;
89
90   // Not owned. NULL if tracking only local state prefs (e.g. in the system
91   // request context or sign-in screen).
92   PrefService* profile_prefs_;
93
94   // Not owned.
95   PrefService* local_state_prefs_;
96
97   base::WeakPtrFactory<ProxyConfigServiceImpl> pointer_factory_;
98
99   DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceImpl);
100 };
101
102 }  // namespace chromeos
103
104 #endif  // CHROME_BROWSER_CHROMEOS_PROXY_CONFIG_SERVICE_IMPL_H_