Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Side by Side Diff: chrome/browser/chromeos/proxy_config_service_impl.cc

Issue 18112018: Cleanup the UseSharedProxies preference. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/chromeos/proxy_config_service_impl.h" 5 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
12 #include "base/values.h" 11 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chromeos/login/user_manager.h" 13 #include "chrome/browser/chromeos/login/user_manager.h"
15 #include "chrome/browser/chromeos/net/proxy_config_handler.h" 14 #include "chrome/browser/chromeos/net/proxy_config_handler.h"
16 #include "chrome/browser/policy/browser_policy_connector.h" 15 #include "chrome/browser/policy/browser_policy_connector.h"
17 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 16 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
18 #include "chrome/browser/prefs/proxy_config_dictionary.h" 17 #include "chrome/browser/prefs/proxy_config_dictionary.h"
19 #include "chrome/browser/prefs/proxy_prefs.h" 18 #include "chrome/browser/prefs/proxy_prefs.h"
20 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
21 #include "chromeos/network/network_profile.h" 20 #include "chromeos/network/network_profile.h"
22 #include "chromeos/network/network_profile_handler.h" 21 #include "chromeos/network/network_profile_handler.h"
23 #include "chromeos/network/network_state.h" 22 #include "chromeos/network/network_state.h"
24 #include "chromeos/network/network_state_handler.h" 23 #include "chromeos/network/network_state_handler.h"
25 #include "chromeos/network/onc/onc_utils.h" 24 #include "chromeos/network/onc/onc_utils.h"
26 #include "components/user_prefs/pref_registry_syncable.h"
27 25
28 namespace chromeos { 26 namespace chromeos {
29 27
30 namespace { 28 namespace {
31 29
32 // Writes the proxy config of |network| to |proxy_config|. Returns false if no 30 // Writes the proxy config of |network| to |proxy_config|. Returns false if no
33 // proxy was configured for this network. 31 // proxy was configured for this network.
34 bool GetProxyConfig(const NetworkState& network, 32 bool GetProxyConfig(const NetworkState& network,
35 net::ProxyConfig* proxy_config) { 33 net::ProxyConfig* proxy_config) {
36 scoped_ptr<ProxyConfigDictionary> proxy_dict = 34 scoped_ptr<ProxyConfigDictionary> proxy_dict =
37 proxy_config::GetProxyConfigForNetwork(network); 35 proxy_config::GetProxyConfigForNetwork(network);
38 if (!proxy_dict) 36 if (!proxy_dict)
39 return false; 37 return false;
40 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict, 38 return PrefProxyConfigTrackerImpl::PrefConfigToNetConfig(*proxy_dict,
41 proxy_config); 39 proxy_config);
42 } 40 }
43 41
44 } // namespace 42 } // namespace
45 43
46 ProxyConfigServiceImpl::ProxyConfigServiceImpl(PrefService* pref_service) 44 ProxyConfigServiceImpl::ProxyConfigServiceImpl(PrefService* profile_prefs,
47 : PrefProxyConfigTrackerImpl(pref_service), 45 PrefService* local_state_prefs)
46 : PrefProxyConfigTrackerImpl(profile_prefs ? profile_prefs
47 : local_state_prefs),
48 active_config_state_(ProxyPrefs::CONFIG_UNSET), 48 active_config_state_(ProxyPrefs::CONFIG_UNSET),
49 profile_prefs_(profile_prefs),
49 pointer_factory_(this) { 50 pointer_factory_(this) {
50
51 // Register for notifications of UseSharedProxies user preference. 51 // Register for notifications of UseSharedProxies user preference.
52 if (pref_service->FindPreference(prefs::kUseSharedProxies)) { 52 if (profile_prefs) {
53 DCHECK(profile_prefs->FindPreference(prefs::kUseSharedProxies));
53 use_shared_proxies_.Init( 54 use_shared_proxies_.Init(
54 prefs::kUseSharedProxies, pref_service, 55 prefs::kUseSharedProxies,
56 profile_prefs,
55 base::Bind(&ProxyConfigServiceImpl::OnUseSharedProxiesChanged, 57 base::Bind(&ProxyConfigServiceImpl::OnUseSharedProxiesChanged,
56 base::Unretained(this))); 58 base::Unretained(this)));
57 } 59 }
58 60
59 // Register for changes to the default network. 61 // Register for changes to the default network.
60 NetworkStateHandler* state_handler = 62 NetworkStateHandler* state_handler =
61 NetworkHandler::Get()->network_state_handler(); 63 NetworkHandler::Get()->network_state_handler();
62 state_handler->AddObserver(this, FROM_HERE); 64 state_handler->AddObserver(this, FROM_HERE);
63 DefaultNetworkChanged(state_handler->DefaultNetwork()); 65 DefaultNetworkChanged(state_handler->DefaultNetwork());
64 } 66 }
65 67
66 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { 68 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() {
67 if (NetworkHandler::IsInitialized()) { 69 if (NetworkHandler::IsInitialized()) {
68 NetworkHandler::Get()->network_state_handler()->RemoveObserver( 70 NetworkHandler::Get()->network_state_handler()->RemoveObserver(
69 this, FROM_HERE); 71 this, FROM_HERE);
70 } 72 }
71 } 73 }
72 74
73 void ProxyConfigServiceImpl::OnProxyConfigChanged( 75 void ProxyConfigServiceImpl::OnProxyConfigChanged(
74 ProxyPrefs::ConfigState config_state, 76 ProxyPrefs::ConfigState config_state,
75 const net::ProxyConfig& config) { 77 const net::ProxyConfig& config) {
76 VLOG(1) << "Got prefs change: " 78 VLOG(1) << "Got prefs change: "
77 << ProxyPrefs::ConfigStateToDebugString(config_state) 79 << ProxyPrefs::ConfigStateToDebugString(config_state)
78 << ", mode=" << config.proxy_rules().type; 80 << ", mode=" << config.proxy_rules().type;
79 DetermineEffectiveConfigFromDefaultNetwork(); 81 DetermineEffectiveConfigFromDefaultNetwork();
80 } 82 }
81 83
82 // static
83 void ProxyConfigServiceImpl::RegisterPrefs(PrefRegistrySimple* registry) {
84 // Use shared proxies default to off. GetUseSharedProxies will return the
85 // correct value based on pre-login and login.
86 registry->RegisterBooleanPref(prefs::kUseSharedProxies, true);
87 }
88
89 // static
90 void ProxyConfigServiceImpl::RegisterProfilePrefs(
91 user_prefs::PrefRegistrySyncable* registry) {
92 registry->RegisterBooleanPref(
93 prefs::kUseSharedProxies,
94 true,
95 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
96 }
97
98 void ProxyConfigServiceImpl::OnUseSharedProxiesChanged() { 84 void ProxyConfigServiceImpl::OnUseSharedProxiesChanged() {
99 VLOG(1) << "New use-shared-proxies = " << GetUseSharedProxies(prefs()); 85 VLOG(1) << "use-shared-proxies pref changed.";
100 DetermineEffectiveConfigFromDefaultNetwork(); 86 DetermineEffectiveConfigFromDefaultNetwork();
101 } 87 }
102 88
103 void ProxyConfigServiceImpl::DefaultNetworkChanged( 89 void ProxyConfigServiceImpl::DefaultNetworkChanged(
104 const NetworkState* new_network) { 90 const NetworkState* new_network) {
105 std::string new_network_path; 91 std::string new_network_path;
106 if (new_network) 92 if (new_network)
107 new_network_path = new_network->path(); 93 new_network_path = new_network->path();
108 94
109 VLOG(1) << "DefaultNetworkChanged to '" << new_network_path << "'."; 95 VLOG(1) << "DefaultNetworkChanged to '" << new_network_path << "'.";
110 VLOG_IF(1, new_network) << "New network: name=" << new_network->name() 96 VLOG_IF(1, new_network) << "New network: name=" << new_network->name()
111 << ", proxy=" << new_network->proxy_config() 97 << ", proxy=" << new_network->proxy_config()
112 << ", profile=" << new_network->profile_path(); 98 << ", profile=" << new_network->profile_path();
113 99
114 // Even if the default network is the same, its proxy config (e.g. if private 100 // Even if the default network is the same, its proxy config (e.g. if private
115 // version of network replaces the shared version after login), or 101 // version of network replaces the shared version after login), or
116 // use-shared-proxies setting (e.g. after login) may have changed, so 102 // use-shared-proxies setting (e.g. after login) may have changed, so
117 // re-determine effective proxy config, and activate if different. 103 // re-determine effective proxy config, and activate if different.
118 DetermineEffectiveConfigFromDefaultNetwork(); 104 DetermineEffectiveConfigFromDefaultNetwork();
119 } 105 }
120 106
121 // static 107 // static
122 bool ProxyConfigServiceImpl::GetUseSharedProxies( 108 bool ProxyConfigServiceImpl::IgnoreProxy(const PrefService* profile_prefs,
123 const PrefService* pref_service) {
124 const PrefService::Preference* use_shared_proxies_pref =
125 pref_service->FindPreference(prefs::kUseSharedProxies);
126 if (!use_shared_proxies_pref || !use_shared_proxies_pref->GetValue()) {
127 if (UserManager::Get()->IsUserLoggedIn()) {
128 VLOG(1) << "use-shared-proxies not set, defaulting to false/IgnoreProxy.";
129 return false;
130 } else {
131 // Make sure that proxies are always enabled at sign in screen.
132 VLOG(1) << "Use proxy on login screen.";
133 return true;
134 }
135 }
136 bool use_shared_proxies = false;
137 use_shared_proxies_pref->GetValue()->GetAsBoolean(&use_shared_proxies);
138 return use_shared_proxies;
139 }
140
141 // static
142 bool ProxyConfigServiceImpl::IgnoreProxy(const PrefService* pref_service,
143 const std::string network_profile_path, 109 const std::string network_profile_path,
144 onc::ONCSource onc_source) { 110 onc::ONCSource onc_source) {
111 if (!profile_prefs) {
112 // If the profile preference are not available, this must be the object
113 // associated to local state used for system requests or login-profile. Make
114 // sure that proxies are enabled.
115 VLOG(1) << "Use proxy for system requests and sign-in screen.";
116 return false;
117 }
118
145 const NetworkProfile* profile = 119 const NetworkProfile* profile =
146 NetworkHandler::Get()->network_profile_handler()-> 120 NetworkHandler::Get()->network_profile_handler()->
147 GetProfileForPath(network_profile_path); 121 GetProfileForPath(network_profile_path);
148 if (!profile) { 122 if (!profile) {
149 LOG(WARNING) << "Unknown profile_path " << network_profile_path; 123 LOG(WARNING) << "Unknown profile_path '" << network_profile_path
124 << "'. Ignoring proxy.";
150 return true; 125 return true;
151 } 126 }
152 if (profile->type() == NetworkProfile::TYPE_USER) { 127 if (profile->type() == NetworkProfile::TYPE_USER) {
153 VLOG(1) << "Respect proxy of not-shared networks."; 128 VLOG(1) << "Respect proxy of not-shared networks.";
154 return false; 129 return false;
155 } 130 }
156 131 if (onc_source == onc::ONC_SOURCE_DEVICE_POLICY) {
157 if (onc_source == onc::ONC_SOURCE_DEVICE_POLICY &&
158 UserManager::Get()->IsUserLoggedIn()) {
159 policy::BrowserPolicyConnector* connector = 132 policy::BrowserPolicyConnector* connector =
160 g_browser_process->browser_policy_connector(); 133 g_browser_process->browser_policy_connector();
161 const User* logged_in_user = UserManager::Get()->GetLoggedInUser(); 134 const User* logged_in_user = UserManager::Get()->GetLoggedInUser();
162 if (connector->GetUserAffiliation(logged_in_user->email()) == 135 if (connector->GetUserAffiliation(logged_in_user->email()) ==
163 policy::USER_AFFILIATION_MANAGED) { 136 policy::USER_AFFILIATION_MANAGED) {
164 VLOG(1) << "Respecting proxy for network, as logged-in user belongs to " 137 VLOG(1) << "Respecting proxy for network, as logged-in user belongs to "
165 << "the domain the device is enrolled to."; 138 << "the domain the device is enrolled to.";
166 return false; 139 return false;
167 } 140 }
168 } 141 }
169 142
170 return !GetUseSharedProxies(pref_service); 143 // This network is shared and not managed by the user's domain.
144 bool use_shared_proxies = profile_prefs->GetBoolean(prefs::kUseSharedProxies);
145 VLOG(1) << "Use proxy of shared network: " << use_shared_proxies;
146 return !use_shared_proxies;
171 } 147 }
172 148
173 void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() { 149 void ProxyConfigServiceImpl::DetermineEffectiveConfigFromDefaultNetwork() {
174 const NetworkState* network = 150 const NetworkState* network =
175 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); 151 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
176 152
177 // Get prefs proxy config if available. 153 // Get prefs proxy config if available.
178 net::ProxyConfig pref_config; 154 net::ProxyConfig pref_config;
179 ProxyPrefs::ConfigState pref_state = GetProxyConfig(&pref_config); 155 ProxyPrefs::ConfigState pref_state = GetProxyConfig(&pref_config);
180 156
181 // Get network proxy config if available. 157 // Get network proxy config if available.
182 net::ProxyConfig network_config; 158 net::ProxyConfig network_config;
183 net::ProxyConfigService::ConfigAvailability network_availability = 159 net::ProxyConfigService::ConfigAvailability network_availability =
184 net::ProxyConfigService::CONFIG_UNSET; 160 net::ProxyConfigService::CONFIG_UNSET;
185 bool ignore_proxy = true; 161 bool ignore_proxy = true;
186 if (network) { 162 if (network) {
187 ignore_proxy = 163 ignore_proxy = IgnoreProxy(
188 IgnoreProxy(prefs(), network->profile_path(), network->onc_source()); 164 profile_prefs_, network->profile_path(), network->onc_source());
189 // If network is shared but use-shared-proxies is off, use direct mode. 165 // If network is shared but use-shared-proxies is off, use direct mode.
190 if (ignore_proxy) { 166 if (ignore_proxy) {
191 VLOG(1) << "Shared network && !use-shared-proxies, use direct"; 167 VLOG(1) << "Shared network && !use-shared-proxies, use direct";
192 network_availability = net::ProxyConfigService::CONFIG_VALID; 168 network_availability = net::ProxyConfigService::CONFIG_VALID;
193 } else if (chromeos::GetProxyConfig(*network, &network_config)) { 169 } else if (chromeos::GetProxyConfig(*network, &network_config)) {
194 // Network is private or shared with user using shared proxies. 170 // Network is private or shared with user using shared proxies.
195 VLOG(1) << this << ": using network proxy: " 171 VLOG(1) << this << ": using network proxy: "
196 << network->proxy_config(); 172 << network->proxy_config();
197 network_availability = net::ProxyConfigService::CONFIG_VALID; 173 network_availability = net::ProxyConfigService::CONFIG_VALID;
198 } 174 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 scoped_ptr<base::DictionaryValue> config_dict( 209 scoped_ptr<base::DictionaryValue> config_dict(
234 effective_config.ToValue()); 210 effective_config.ToValue());
235 VLOG(1) << this << ": Proxy changed: " 211 VLOG(1) << this << ": Proxy changed: "
236 << ProxyPrefs::ConfigStateToDebugString(active_config_state_) 212 << ProxyPrefs::ConfigStateToDebugString(active_config_state_)
237 << ", " << *config_dict; 213 << ", " << *config_dict;
238 } 214 }
239 } 215 }
240 } 216 }
241 217
242 } // namespace chromeos 218 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/proxy_config_service_impl.h ('k') | chrome/browser/chromeos/proxy_config_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698