| 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" | 5 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/extensions/chrome_extension_function.h" | 10 #include "chrome/browser/extensions/chrome_extension_function.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 new settings_private::PrefObject()); | 249 new settings_private::PrefObject()); |
| 250 | 250 |
| 251 #if defined(OS_CHROMEOS) | 251 #if defined(OS_CHROMEOS) |
| 252 const base::Value* value = CrosSettings::Get()->GetPref(name); | 252 const base::Value* value = CrosSettings::Get()->GetPref(name); |
| 253 DCHECK(value); | 253 DCHECK(value); |
| 254 pref_object->key = name; | 254 pref_object->key = name; |
| 255 pref_object->type = GetType(name, value->GetType()); | 255 pref_object->type = GetType(name, value->GetType()); |
| 256 pref_object->value.reset(value->DeepCopy()); | 256 pref_object->value.reset(value->DeepCopy()); |
| 257 #endif | 257 #endif |
| 258 | 258 |
| 259 return pref_object.Pass(); | 259 return pref_object; |
| 260 } | 260 } |
| 261 | 261 |
| 262 scoped_ptr<settings_private::PrefObject> PrefsUtil::GetPref( | 262 scoped_ptr<settings_private::PrefObject> PrefsUtil::GetPref( |
| 263 const std::string& name) { | 263 const std::string& name) { |
| 264 const PrefService::Preference* pref = nullptr; | 264 const PrefService::Preference* pref = nullptr; |
| 265 scoped_ptr<settings_private::PrefObject> pref_object; | 265 scoped_ptr<settings_private::PrefObject> pref_object; |
| 266 if (IsCrosSetting(name)) { | 266 if (IsCrosSetting(name)) { |
| 267 pref_object = GetCrosSettingsPref(name); | 267 pref_object = GetCrosSettingsPref(name); |
| 268 } else { | 268 } else { |
| 269 PrefService* pref_service = FindServiceForPref(name); | 269 PrefService* pref_service = FindServiceForPref(name); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 295 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; | 295 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; |
| 296 return pref_object.Pass(); | 296 return pref_object.Pass(); |
| 297 } | 297 } |
| 298 #endif | 298 #endif |
| 299 | 299 |
| 300 if (pref && pref->IsManaged()) { | 300 if (pref && pref->IsManaged()) { |
| 301 pref_object->policy_source = | 301 pref_object->policy_source = |
| 302 settings_private::PolicySource::POLICY_SOURCE_USER_POLICY; | 302 settings_private::PolicySource::POLICY_SOURCE_USER_POLICY; |
| 303 pref_object->policy_enforcement = | 303 pref_object->policy_enforcement = |
| 304 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; | 304 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; |
| 305 return pref_object.Pass(); | 305 return pref_object; |
| 306 } | 306 } |
| 307 if (pref && pref->IsRecommended()) { | 307 if (pref && pref->IsRecommended()) { |
| 308 pref_object->policy_source = | 308 pref_object->policy_source = |
| 309 settings_private::PolicySource::POLICY_SOURCE_USER_POLICY; | 309 settings_private::PolicySource::POLICY_SOURCE_USER_POLICY; |
| 310 pref_object->policy_enforcement = | 310 pref_object->policy_enforcement = |
| 311 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_RECOMMENDED; | 311 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_RECOMMENDED; |
| 312 pref_object->recommended_value.reset( | 312 pref_object->recommended_value.reset( |
| 313 pref->GetRecommendedValue()->DeepCopy()); | 313 pref->GetRecommendedValue()->DeepCopy()); |
| 314 return pref_object.Pass(); | 314 return pref_object; |
| 315 } | 315 } |
| 316 | 316 |
| 317 #if defined(OS_CHROMEOS) | 317 #if defined(OS_CHROMEOS) |
| 318 if (IsPrefOwnerControlled(name)) { | 318 if (IsPrefOwnerControlled(name)) { |
| 319 // Check for owner controlled after managed checks because if there is a | 319 // Check for owner controlled after managed checks because if there is a |
| 320 // device policy there is no "owner". (In the unlikely case that both | 320 // device policy there is no "owner". (In the unlikely case that both |
| 321 // situations apply, either badge is potentially relevant, so the order | 321 // situations apply, either badge is potentially relevant, so the order |
| 322 // is somewhat arbitrary). | 322 // is somewhat arbitrary). |
| 323 pref_object->policy_source = | 323 pref_object->policy_source = |
| 324 settings_private::PolicySource::POLICY_SOURCE_OWNER; | 324 settings_private::PolicySource::POLICY_SOURCE_OWNER; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 336 ->GetExtensionControllingPref(pref->name()); | 336 ->GetExtensionControllingPref(pref->name()); |
| 337 const Extension* extension = ExtensionRegistry::Get(profile_)-> | 337 const Extension* extension = ExtensionRegistry::Get(profile_)-> |
| 338 GetExtensionById(extension_id, ExtensionRegistry::ENABLED); | 338 GetExtensionById(extension_id, ExtensionRegistry::ENABLED); |
| 339 if (extension) { | 339 if (extension) { |
| 340 pref_object->policy_source = | 340 pref_object->policy_source = |
| 341 settings_private::PolicySource::POLICY_SOURCE_EXTENSION; | 341 settings_private::PolicySource::POLICY_SOURCE_EXTENSION; |
| 342 pref_object->policy_enforcement = | 342 pref_object->policy_enforcement = |
| 343 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; | 343 settings_private::PolicyEnforcement::POLICY_ENFORCEMENT_ENFORCED; |
| 344 pref_object->extension_id.reset(new std::string(extension_id)); | 344 pref_object->extension_id.reset(new std::string(extension_id)); |
| 345 pref_object->policy_source_name.reset(new std::string(extension->name())); | 345 pref_object->policy_source_name.reset(new std::string(extension->name())); |
| 346 return pref_object.Pass(); | 346 return pref_object; |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 if (pref && (!pref->IsUserModifiable() || IsPrefSupervisorControlled(name))) { | 349 if (pref && (!pref->IsUserModifiable() || IsPrefSupervisorControlled(name))) { |
| 350 // TODO(stevenjb): Investigate whether either of these should be badged. | 350 // TODO(stevenjb): Investigate whether either of these should be badged. |
| 351 pref_object->read_only.reset(new bool(true)); | 351 pref_object->read_only.reset(new bool(true)); |
| 352 return pref_object.Pass(); | 352 return pref_object; |
| 353 } | 353 } |
| 354 | 354 |
| 355 return pref_object.Pass(); | 355 return pref_object; |
| 356 } | 356 } |
| 357 | 357 |
| 358 PrefsUtil::SetPrefResult PrefsUtil::SetPref(const std::string& pref_name, | 358 PrefsUtil::SetPrefResult PrefsUtil::SetPref(const std::string& pref_name, |
| 359 const base::Value* value) { | 359 const base::Value* value) { |
| 360 if (IsCrosSetting(pref_name)) | 360 if (IsCrosSetting(pref_name)) |
| 361 return SetCrosSettingsPref(pref_name, value); | 361 return SetCrosSettingsPref(pref_name, value); |
| 362 | 362 |
| 363 PrefService* pref_service = FindServiceForPref(pref_name); | 363 PrefService* pref_service = FindServiceForPref(pref_name); |
| 364 | 364 |
| 365 if (!IsPrefUserModifiable(pref_name)) | 365 if (!IsPrefUserModifiable(pref_name)) |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 | 559 |
| 560 bool PrefsUtil::IsCrosSetting(const std::string& pref_name) { | 560 bool PrefsUtil::IsCrosSetting(const std::string& pref_name) { |
| 561 #if defined(OS_CHROMEOS) | 561 #if defined(OS_CHROMEOS) |
| 562 return CrosSettings::Get()->IsCrosSettings(pref_name); | 562 return CrosSettings::Get()->IsCrosSettings(pref_name); |
| 563 #else | 563 #else |
| 564 return false; | 564 return false; |
| 565 #endif | 565 #endif |
| 566 } | 566 } |
| 567 | 567 |
| 568 } // namespace extensions | 568 } // namespace extensions |
| OLD | NEW |