Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/settings_private/prefs_util.h" | |
| 6 | |
| 5 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 6 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" | |
| 8 #include "chrome/browser/extensions/chrome_extension_function.h" | 9 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 11 #include "components/proxy_config/proxy_config_pref_names.h" | 12 #include "components/proxy_config/proxy_config_pref_names.h" |
| 12 #include "components/url_formatter/url_fixer.h" | 13 #include "components/url_formatter/url_fixer.h" |
| 14 #include "extensions/browser/extension_pref_value_map.h" | |
| 15 #include "extensions/browser/extension_pref_value_map_factory.h" | |
| 16 #include "extensions/browser/extension_registry.h" | |
| 13 | 17 |
| 14 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
| 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 19 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 16 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" | 20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" |
| 21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 17 #include "chrome/browser/chromeos/settings/cros_settings.h" | 23 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 24 #include "chromeos/settings/cros_settings_names.h" | |
| 18 #endif | 25 #endif |
| 19 | 26 |
| 27 namespace { | |
| 28 | |
| 29 #if defined(OS_CHROMEOS) | |
| 30 bool IsPrivilegedCrosSetting(const std::string& pref_name) { | |
| 31 if (!chromeos::CrosSettings::IsCrosSettings(pref_name)) | |
| 32 return false; | |
| 33 // kSystemTimezone should be changeable by all users. | |
| 34 if (pref_name == chromeos::kSystemTimezone) | |
| 35 return false; | |
| 36 // All other Cros settings are considered privileged and are either policy | |
| 37 // controlled or owner controlled. | |
| 38 return true; | |
| 39 } | |
| 40 #endif | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 20 namespace extensions { | 44 namespace extensions { |
| 21 | 45 |
| 22 namespace settings_private = api::settings_private; | 46 namespace settings_private = api::settings_private; |
| 23 | 47 |
| 24 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) { | 48 PrefsUtil::PrefsUtil(Profile* profile) : profile_(profile) {} |
| 25 } | |
| 26 | 49 |
| 27 PrefsUtil::~PrefsUtil() { | 50 PrefsUtil::~PrefsUtil() {} |
| 28 } | |
| 29 | 51 |
| 30 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
| 31 using CrosSettings = chromeos::CrosSettings; | 53 using CrosSettings = chromeos::CrosSettings; |
| 32 #endif | 54 #endif |
| 33 | 55 |
| 34 const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() { | 56 const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() { |
| 35 static PrefsUtil::TypedPrefMap* s_whitelist = nullptr; | 57 static PrefsUtil::TypedPrefMap* s_whitelist = nullptr; |
| 36 if (s_whitelist) | 58 if (s_whitelist) |
| 37 return *s_whitelist; | 59 return *s_whitelist; |
| 38 s_whitelist = new PrefsUtil::TypedPrefMap(); | 60 s_whitelist = new PrefsUtil::TypedPrefMap(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 123 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 102 (*s_whitelist)["cros.device.attestation_for_content_protection_enabled"] = | 124 (*s_whitelist)["cros.device.attestation_for_content_protection_enabled"] = |
| 103 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 125 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 104 (*s_whitelist)["settings.internet.wake_on_wifi_ssid"] = | 126 (*s_whitelist)["settings.internet.wake_on_wifi_ssid"] = |
| 105 settings_private::PrefType::PREF_TYPE_BOOLEAN; | 127 settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 106 #endif | 128 #endif |
| 107 | 129 |
| 108 return *s_whitelist; | 130 return *s_whitelist; |
| 109 } | 131 } |
| 110 | 132 |
| 111 api::settings_private::PrefType PrefsUtil::GetType(const std::string& name, | 133 settings_private::PrefType PrefsUtil::GetType(const std::string& name, |
| 112 base::Value::Type type) { | 134 base::Value::Type type) { |
| 113 switch (type) { | 135 switch (type) { |
| 114 case base::Value::Type::TYPE_BOOLEAN: | 136 case base::Value::Type::TYPE_BOOLEAN: |
| 115 return api::settings_private::PrefType::PREF_TYPE_BOOLEAN; | 137 return settings_private::PrefType::PREF_TYPE_BOOLEAN; |
| 116 case base::Value::Type::TYPE_INTEGER: | 138 case base::Value::Type::TYPE_INTEGER: |
| 117 case base::Value::Type::TYPE_DOUBLE: | 139 case base::Value::Type::TYPE_DOUBLE: |
| 118 return api::settings_private::PrefType::PREF_TYPE_NUMBER; | 140 return settings_private::PrefType::PREF_TYPE_NUMBER; |
| 119 case base::Value::Type::TYPE_STRING: | 141 case base::Value::Type::TYPE_STRING: |
| 120 return IsPrefTypeURL(name) | 142 return IsPrefTypeURL(name) ? settings_private::PrefType::PREF_TYPE_URL |
| 121 ? api::settings_private::PrefType::PREF_TYPE_URL | 143 : settings_private::PrefType::PREF_TYPE_STRING; |
| 122 : api::settings_private::PrefType::PREF_TYPE_STRING; | |
| 123 case base::Value::Type::TYPE_LIST: | 144 case base::Value::Type::TYPE_LIST: |
| 124 return api::settings_private::PrefType::PREF_TYPE_LIST; | 145 return settings_private::PrefType::PREF_TYPE_LIST; |
| 125 default: | 146 default: |
| 126 return api::settings_private::PrefType::PREF_TYPE_NONE; | 147 return settings_private::PrefType::PREF_TYPE_NONE; |
| 127 } | 148 } |
| 128 } | 149 } |
| 129 | 150 |
| 130 scoped_ptr<api::settings_private::PrefObject> PrefsUtil::GetCrosSettingsPref( | 151 scoped_ptr<settings_private::PrefObject> PrefsUtil::GetCrosSettingsPref( |
| 131 const std::string& name) { | 152 const std::string& name) { |
| 132 scoped_ptr<api::settings_private::PrefObject> pref_object( | 153 scoped_ptr<settings_private::PrefObject> pref_object( |
| 133 new api::settings_private::PrefObject()); | 154 new settings_private::PrefObject()); |
| 134 | 155 |
| 135 #if defined(OS_CHROMEOS) | 156 #if defined(OS_CHROMEOS) |
| 136 const base::Value* value = CrosSettings::Get()->GetPref(name); | 157 const base::Value* value = CrosSettings::Get()->GetPref(name); |
| 158 if (!value) | |
| 159 return nullptr; | |
| 137 pref_object->key = name; | 160 pref_object->key = name; |
| 138 pref_object->type = GetType(name, value->GetType()); | 161 pref_object->type = GetType(name, value->GetType()); |
| 139 pref_object->value.reset(value->DeepCopy()); | 162 pref_object->value.reset(value->DeepCopy()); |
| 140 #endif | 163 #endif |
| 141 | 164 |
| 142 return pref_object.Pass(); | 165 return pref_object.Pass(); |
| 143 } | 166 } |
| 144 | 167 |
| 145 scoped_ptr<api::settings_private::PrefObject> PrefsUtil::GetPref( | 168 scoped_ptr<settings_private::PrefObject> PrefsUtil::GetPref( |
| 146 const std::string& name) { | 169 const std::string& name) { |
| 147 if (IsCrosSetting(name)) | 170 const PrefService::Preference* pref = nullptr; |
| 148 return GetCrosSettingsPref(name); | 171 scoped_ptr<settings_private::PrefObject> pref_object; |
| 172 if (IsCrosSetting(name)) { | |
|
michaelpg
2015/09/14 05:14:51
no need to check this on non-Chrome OS
stevenjb
2015/09/14 23:05:30
Maybe fix in a re-factor.
| |
| 173 pref_object = GetCrosSettingsPref(name); | |
| 174 } else { | |
| 175 PrefService* pref_service = FindServiceForPref(name); | |
| 176 pref = pref_service->FindPreference(name); | |
| 177 if (!pref) | |
| 178 return nullptr; | |
| 179 pref_object.reset(new settings_private::PrefObject()); | |
| 180 pref_object->key = pref->name(); | |
| 181 pref_object->type = GetType(name, pref->GetType()); | |
| 182 pref_object->value.reset(pref->GetValue()->DeepCopy()); | |
| 183 } | |
| 149 | 184 |
| 150 PrefService* pref_service = FindServiceForPref(name); | 185 #if defined(OS_CHROMEOS) |
| 151 const PrefService::Preference* pref = pref_service->FindPreference(name); | 186 if (IsPrefPrimaryUserControlled(name)) { |
|
michaelpg
2015/09/14 05:14:51
shouldn't we check enterprise policy first, since
stevenjb
2015/09/14 23:05:30
So, with the last iteration, I did think about the
michaelpg
2015/09/16 18:58:52
granted
stevenjb
2015/09/16 21:33:53
Acknowledged.
| |
| 187 pref_object->policy_source = | |
| 188 settings_private::PolicySource::POLICY_SOURCE_PRIMARY_USER; | |
| 189 pref_object->policy_enforcement = | |
| 190 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; | |
| 191 return pref_object.Pass(); | |
| 192 } | |
| 193 if (IsPrefOwnerControlled(name)) { | |
|
michaelpg
2015/09/14 05:14:51
this ordering also doesn't look right: for managed
stevenjb
2015/09/14 23:05:30
Which is correct; the policy for the logged in use
michaelpg
2015/09/16 18:58:52
If it is an enrolled device there *is no owner*, b
stevenjb
2015/09/16 21:33:53
Yeah, the logic there is fragile at best. I'll go
| |
| 194 pref_object->policy_source = | |
| 195 settings_private::PolicySource::POLICY_SOURCE_OWNER; | |
| 196 pref_object->policy_enforcement = | |
| 197 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; | |
| 198 return pref_object.Pass(); | |
| 199 } | |
| 200 if (IsPrefEnterpriseManaged(name)) { | |
| 201 // Enterprise managed prefs are treated the same as device policy restricted | |
| 202 // prefs in the UI. | |
| 203 pref_object->policy_source = | |
| 204 settings_private::PolicySource::POLICY_SOURCE_DEVICE_POLICY; | |
| 205 pref_object->policy_enforcement = | |
| 206 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; | |
| 207 return pref_object.Pass(); | |
| 208 } | |
| 209 #endif | |
| 210 | |
| 152 if (!pref) | 211 if (!pref) |
| 153 return nullptr; | 212 return pref_object.Pass(); |
| 154 | |
| 155 scoped_ptr<api::settings_private::PrefObject> pref_object( | |
| 156 new api::settings_private::PrefObject()); | |
| 157 pref_object->key = pref->name(); | |
| 158 pref_object->type = GetType(name, pref->GetType()); | |
| 159 pref_object->value.reset(pref->GetValue()->DeepCopy()); | |
| 160 | 213 |
| 161 if (pref->IsManaged()) { | 214 if (pref->IsManaged()) { |
| 162 if (pref->IsManagedByCustodian()) { | 215 pref_object->policy_source = |
| 163 pref_object->policy_source = | 216 settings_private::PolicySource::POLICY_SOURCE_USER_POLICY; |
| 164 api::settings_private::PolicySource::POLICY_SOURCE_DEVICE; | |
| 165 } else { | |
| 166 pref_object->policy_source = | |
| 167 api::settings_private::PolicySource::POLICY_SOURCE_USER; | |
| 168 } | |
| 169 pref_object->policy_enforcement = | 217 pref_object->policy_enforcement = |
| 170 pref->IsRecommended() ? api::settings_private::PolicyEnforcement:: | 218 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; |
| 171 POLICY_ENFORCEMENT_RECOMMENDED | 219 return pref_object.Pass(); |
| 172 : api::settings_private::PolicyEnforcement:: | 220 } |
| 173 POLICY_ENFORCEMENT_ENFORCED; | 221 if (pref->IsRecommended()) { |
| 174 } else if (!IsPrefUserModifiable(name)) { | |
| 175 pref_object->policy_source = | 222 pref_object->policy_source = |
| 176 api::settings_private::PolicySource::POLICY_SOURCE_USER; | 223 settings_private::PolicySource::POLICY_SOURCE_USER_POLICY; |
| 177 pref_object->policy_enforcement = | 224 pref_object->policy_enforcement = |
| 178 api::settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; | 225 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_RECOMMENDED; |
| 226 pref_object->recommended_value.reset( | |
| 227 pref->GetRecommendedValue()->DeepCopy()); | |
| 228 return pref_object.Pass(); | |
| 229 } | |
| 230 if (pref->IsExtensionControlled()) { | |
| 231 pref_object->policy_source = | |
| 232 settings_private::PolicySource::POLICY_SOURCE_EXTENSION; | |
| 233 pref_object->policy_enforcement = | |
| 234 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; | |
| 235 std::string extension_id = | |
| 236 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_) | |
| 237 ->GetExtensionControllingPref(pref->name()); | |
| 238 pref_object->extension_id.reset(new std::string(extension_id)); | |
| 239 return pref_object.Pass(); | |
| 240 } | |
| 241 if (!pref->IsUserModifiable() || IsPrefSupervisorControlled(name)) { | |
| 242 // TODO(stevenjb): Investigate whether either of these should be badged. | |
| 243 pref_object->read_only.reset(new bool(true)); | |
| 244 return pref_object.Pass(); | |
| 179 } | 245 } |
| 180 | 246 |
| 181 return pref_object.Pass(); | 247 return pref_object.Pass(); |
| 182 } | 248 } |
| 183 | 249 |
| 184 PrefsUtil::SetPrefResult PrefsUtil::SetPref(const std::string& pref_name, | 250 PrefsUtil::SetPrefResult PrefsUtil::SetPref(const std::string& pref_name, |
| 185 const base::Value* value) { | 251 const base::Value* value) { |
| 186 if (IsCrosSetting(pref_name)) | 252 if (IsCrosSetting(pref_name)) |
| 187 return SetCrosSettingsPref(pref_name, value); | 253 return SetCrosSettingsPref(pref_name, value); |
| 188 | 254 |
| 189 PrefService* pref_service = FindServiceForPref(pref_name); | 255 PrefService* pref_service = FindServiceForPref(pref_name); |
| 190 | 256 |
| 191 if (!IsPrefUserModifiable(pref_name)) | 257 if (!IsPrefUserModifiable(pref_name)) |
| 192 return PREF_NOT_MODIFIABLE; | 258 return PREF_NOT_MODIFIABLE; |
| 193 | 259 |
| 194 const PrefService::Preference* pref = | 260 const PrefService::Preference* pref = pref_service->FindPreference(pref_name); |
| 195 pref_service->FindPreference(pref_name); | |
| 196 if (!pref) | 261 if (!pref) |
| 197 return PREF_NOT_FOUND; | 262 return PREF_NOT_FOUND; |
| 198 | 263 |
| 199 DCHECK_EQ(pref->GetType(), value->GetType()); | 264 DCHECK_EQ(pref->GetType(), value->GetType()); |
| 200 | 265 |
| 201 switch (pref->GetType()) { | 266 switch (pref->GetType()) { |
| 202 case base::Value::TYPE_BOOLEAN: | 267 case base::Value::TYPE_BOOLEAN: |
| 203 case base::Value::TYPE_DOUBLE: | 268 case base::Value::TYPE_DOUBLE: |
| 204 case base::Value::TYPE_LIST: | 269 case base::Value::TYPE_LIST: |
| 205 pref_service->Set(pref_name, *value); | 270 pref_service->Set(pref_name, *value); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( | 307 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
| 243 profile_); | 308 profile_); |
| 244 | 309 |
| 245 // Check if setting requires owner. | 310 // Check if setting requires owner. |
| 246 if (service && service->HandlesSetting(pref_name)) { | 311 if (service && service->HandlesSetting(pref_name)) { |
| 247 if (service->Set(pref_name, *value)) | 312 if (service->Set(pref_name, *value)) |
| 248 return SUCCESS; | 313 return SUCCESS; |
| 249 return PREF_NOT_MODIFIABLE; | 314 return PREF_NOT_MODIFIABLE; |
| 250 } | 315 } |
| 251 | 316 |
| 252 chromeos::CrosSettings::Get()->Set(pref_name, *value); | 317 CrosSettings::Get()->Set(pref_name, *value); |
| 253 return SUCCESS; | 318 return SUCCESS; |
| 254 #else | 319 #else |
| 255 return PREF_NOT_FOUND; | 320 return PREF_NOT_FOUND; |
| 256 #endif | 321 #endif |
| 257 } | 322 } |
| 258 | 323 |
| 259 bool PrefsUtil::AppendToListCrosSetting(const std::string& pref_name, | 324 bool PrefsUtil::AppendToListCrosSetting(const std::string& pref_name, |
| 260 const base::Value& value) { | 325 const base::Value& value) { |
| 261 #if defined(OS_CHROMEOS) | 326 #if defined(OS_CHROMEOS) |
| 262 chromeos::OwnerSettingsServiceChromeOS* service = | 327 chromeos::OwnerSettingsServiceChromeOS* service = |
| 263 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( | 328 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
| 264 profile_); | 329 profile_); |
| 265 | 330 |
| 266 // Returns false if not the owner, for settings requiring owner. | 331 // Returns false if not the owner, for settings requiring owner. |
| 267 if (service && service->HandlesSetting(pref_name)) { | 332 if (service && service->HandlesSetting(pref_name)) { |
| 268 return service->AppendToList(pref_name, value); | 333 return service->AppendToList(pref_name, value); |
| 269 } | 334 } |
| 270 | 335 |
| 271 chromeos::CrosSettings::Get()->AppendToList(pref_name, &value); | 336 CrosSettings::Get()->AppendToList(pref_name, &value); |
| 272 return true; | 337 return true; |
| 273 #else | 338 #else |
| 274 return false; | 339 return false; |
| 275 #endif | 340 #endif |
| 276 } | 341 } |
| 277 | 342 |
| 278 bool PrefsUtil::RemoveFromListCrosSetting(const std::string& pref_name, | 343 bool PrefsUtil::RemoveFromListCrosSetting(const std::string& pref_name, |
| 279 const base::Value& value) { | 344 const base::Value& value) { |
| 280 #if defined(OS_CHROMEOS) | 345 #if defined(OS_CHROMEOS) |
| 281 chromeos::OwnerSettingsServiceChromeOS* service = | 346 chromeos::OwnerSettingsServiceChromeOS* service = |
| 282 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( | 347 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
| 283 profile_); | 348 profile_); |
| 284 | 349 |
| 285 // Returns false if not the owner, for settings requiring owner. | 350 // Returns false if not the owner, for settings requiring owner. |
| 286 if (service && service->HandlesSetting(pref_name)) { | 351 if (service && service->HandlesSetting(pref_name)) { |
| 287 return service->RemoveFromList(pref_name, value); | 352 return service->RemoveFromList(pref_name, value); |
| 288 } | 353 } |
| 289 | 354 |
| 290 chromeos::CrosSettings::Get()->RemoveFromList(pref_name, &value); | 355 CrosSettings::Get()->RemoveFromList(pref_name, &value); |
| 291 return true; | 356 return true; |
| 292 #else | 357 #else |
| 293 return false; | 358 return false; |
| 294 #endif | 359 #endif |
| 295 } | 360 } |
| 296 | 361 |
| 297 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { | 362 bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { |
| 298 settings_private::PrefType pref_type = | 363 settings_private::PrefType pref_type = |
| 299 settings_private::PrefType::PREF_TYPE_NONE; | 364 settings_private::PrefType::PREF_TYPE_NONE; |
| 300 | 365 |
| 301 const TypedPrefMap keys = GetWhitelistedKeys(); | 366 const TypedPrefMap keys = GetWhitelistedKeys(); |
| 302 const auto& iter = keys.find(pref_name); | 367 const auto& iter = keys.find(pref_name); |
| 303 if (iter != keys.end()) | 368 if (iter != keys.end()) |
| 304 pref_type = iter->second; | 369 pref_type = iter->second; |
| 305 | 370 |
| 306 return pref_type == settings_private::PrefType::PREF_TYPE_URL; | 371 return pref_type == settings_private::PrefType::PREF_TYPE_URL; |
| 307 } | 372 } |
| 308 | 373 |
| 374 #if defined(OS_CHROMEOS) | |
| 375 bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) { | |
| 376 if (IsPrivilegedCrosSetting(pref_name)) { | |
| 377 policy::BrowserPolicyConnectorChromeOS* connector = | |
| 378 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 379 if (connector->IsEnterpriseManaged()) | |
| 380 return true; | |
| 381 } | |
| 382 return false; | |
| 383 } | |
| 384 | |
| 385 bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) { | |
| 386 if (IsPrivilegedCrosSetting(pref_name)) { | |
| 387 if (!chromeos::ProfileHelper::IsOwnerProfile(profile_)) | |
| 388 return true; | |
| 389 } | |
| 390 return false; | |
| 391 } | |
| 392 | |
| 393 bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) { | |
| 394 if (pref_name == prefs::kWakeOnWifiSsid) { | |
| 395 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | |
| 396 const user_manager::User* user = | |
| 397 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | |
| 398 if (user && user->email() != user_manager->GetPrimaryUser()->email()) | |
| 399 return true; | |
| 400 } | |
| 401 return false; | |
| 402 } | |
| 403 #endif | |
| 404 | |
| 405 bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { | |
| 406 if (pref_name == prefs::kBrowserGuestModeEnabled || | |
| 407 pref_name == prefs::kBrowserAddPersonEnabled) { | |
| 408 if (profile_->IsSupervised()) | |
| 409 return true; | |
|
michaelpg
2015/09/14 05:14:51
nit: return IsSupervised();
or move this check to
stevenjb
2015/09/14 23:05:31
Did the opposite since IsSupervised() has some cos
| |
| 410 } | |
| 411 return false; | |
| 412 } | |
| 413 | |
| 309 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { | 414 bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { |
| 310 if (pref_name != prefs::kBrowserGuestModeEnabled && | |
| 311 pref_name != prefs::kBrowserAddPersonEnabled) { | |
| 312 return true; | |
| 313 } | |
| 314 | |
| 315 PrefService* pref_service = profile_->GetPrefs(); | 415 PrefService* pref_service = profile_->GetPrefs(); |
| 316 const PrefService::Preference* pref = | 416 const PrefService::Preference* pref = |
| 317 pref_service->FindPreference(pref_name.c_str()); | 417 pref_service->FindPreference(pref_name.c_str()); |
| 318 if (!pref || !pref->IsUserModifiable() || profile_->IsSupervised()) | 418 return pref && pref->IsUserModifiable(); |
| 319 return false; | |
| 320 | |
| 321 return true; | |
| 322 } | 419 } |
| 323 | 420 |
| 324 PrefService* PrefsUtil::FindServiceForPref(const std::string& pref_name) { | 421 PrefService* PrefsUtil::FindServiceForPref(const std::string& pref_name) { |
| 325 PrefService* user_prefs = profile_->GetPrefs(); | 422 PrefService* user_prefs = profile_->GetPrefs(); |
| 326 | 423 |
| 327 // Proxy is a peculiar case: on ChromeOS, settings exist in both user | 424 // Proxy is a peculiar case: on ChromeOS, settings exist in both user |
| 328 // prefs and local state, but chrome://settings should affect only user prefs. | 425 // prefs and local state, but chrome://settings should affect only user prefs. |
| 329 // Elsewhere the proxy settings are stored in local state. | 426 // Elsewhere the proxy settings are stored in local state. |
| 330 // See http://crbug.com/157147 | 427 // See http://crbug.com/157147 |
| 331 | 428 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 351 | 448 |
| 352 bool PrefsUtil::IsCrosSetting(const std::string& pref_name) { | 449 bool PrefsUtil::IsCrosSetting(const std::string& pref_name) { |
| 353 #if defined(OS_CHROMEOS) | 450 #if defined(OS_CHROMEOS) |
| 354 return CrosSettings::Get()->IsCrosSettings(pref_name); | 451 return CrosSettings::Get()->IsCrosSettings(pref_name); |
| 355 #else | 452 #else |
| 356 return false; | 453 return false; |
| 357 #endif | 454 #endif |
| 358 } | 455 } |
| 359 | 456 |
| 360 } // namespace extensions | 457 } // namespace extensions |
| OLD | NEW |