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

Unified Diff: components/policy/core/common/policy_loader_mac.cc

Issue 179813008: Move PolicyLoaderMac::CreateValueFromProperty to a generic file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: POLICY_EXPORT Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/policy/core/common/policy_loader_mac.cc
diff --git a/components/policy/core/common/policy_loader_mac.cc b/components/policy/core/common/policy_loader_mac.cc
index 326db7eabc4bf3bb0a686c0305121fad3f28fcc4..91bda0902a566013584048587fc79cea9d5979be 100644
--- a/components/policy/core/common/policy_loader_mac.cc
+++ b/components/policy/core/common/policy_loader_mac.cc
@@ -16,6 +16,7 @@
#include "base/strings/sys_string_conversions.h"
#include "base/values.h"
#include "components/policy/core/common/external_data_fetcher.h"
+#include "components/policy/core/common/mac_util.h"
#include "components/policy/core/common/policy_bundle.h"
#include "components/policy/core/common/policy_load_status.h"
#include "components/policy/core/common/policy_map.h"
@@ -23,41 +24,10 @@
#include "components/policy/core/common/schema.h"
#include "components/policy/core/common/schema_map.h"
-using base::mac::CFCast;
using base::ScopedCFTypeRef;
namespace policy {
-namespace {
-
-// Callback function for CFDictionaryApplyFunction. |key| and |value| are an
-// entry of the CFDictionary that should be converted into an equivalent entry
-// in the DictionaryValue in |context|.
-void DictionaryEntryToValue(const void* key, const void* value, void* context) {
- if (CFStringRef cf_key = CFCast<CFStringRef>(key)) {
- base::Value* converted =
- PolicyLoaderMac::CreateValueFromProperty(
- static_cast<CFPropertyListRef>(value));
- if (converted) {
- const std::string string = base::SysCFStringRefToUTF8(cf_key);
- static_cast<base::DictionaryValue *>(context)->Set(string, converted);
- }
- }
-}
-
-// Callback function for CFArrayApplyFunction. |value| is an entry of the
-// CFArray that should be converted into an equivalent entry in the ListValue
-// in |context|.
-void ArrayEntryToValue(const void* value, void* context) {
- base::Value* converted =
- PolicyLoaderMac::CreateValueFromProperty(
- static_cast<CFPropertyListRef>(value));
- if (converted)
- static_cast<base::ListValue *>(context)->Append(converted);
-}
-
-} // namespace
-
PolicyLoaderMac::PolicyLoaderMac(
scoped_refptr<base::SequencedTaskRunner> task_runner,
const base::FilePath& managed_policy_path,
@@ -102,11 +72,13 @@ scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() {
PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY :
POLICY_LEVEL_RECOMMENDED;
// TODO(joaodasilva): figure the policy scope.
- base::Value* policy = CreateValueFromProperty(value);
- if (policy)
- chrome_policy.Set(it.key(), level, POLICY_SCOPE_USER, policy, NULL);
- else
+ scoped_ptr<base::Value> policy = PropertyToValue(value);
+ if (policy) {
+ chrome_policy.Set(
+ it.key(), level, POLICY_SCOPE_USER, policy.release(), NULL);
+ } else {
status.Add(POLICY_LOAD_STATUS_PARSE_ERROR);
+ }
}
if (!policy_present)
@@ -128,50 +100,6 @@ base::Time PolicyLoaderMac::LastModificationTime() {
return file_info.last_modified;
}
-// static
-base::Value* PolicyLoaderMac::CreateValueFromProperty(
- CFPropertyListRef property) {
- if (CFCast<CFNullRef>(property))
- return base::Value::CreateNullValue();
-
- if (CFBooleanRef boolean = CFCast<CFBooleanRef>(property))
- return base::Value::CreateBooleanValue(CFBooleanGetValue(boolean));
-
- if (CFNumberRef number = CFCast<CFNumberRef>(property)) {
- // CFNumberGetValue() converts values implicitly when the conversion is not
- // lossy. Check the type before trying to convert.
- if (CFNumberIsFloatType(number)) {
- double double_value;
- if (CFNumberGetValue(number, kCFNumberDoubleType, &double_value))
- return base::Value::CreateDoubleValue(double_value);
- } else {
- int int_value;
- if (CFNumberGetValue(number, kCFNumberIntType, &int_value))
- return base::Value::CreateIntegerValue(int_value);
- }
- }
-
- if (CFStringRef string = CFCast<CFStringRef>(property))
- return base::Value::CreateStringValue(base::SysCFStringRefToUTF8(string));
-
- if (CFDictionaryRef dict = CFCast<CFDictionaryRef>(property)) {
- base::DictionaryValue* dict_value = new base::DictionaryValue();
- CFDictionaryApplyFunction(dict, DictionaryEntryToValue, dict_value);
- return dict_value;
- }
-
- if (CFArrayRef array = CFCast<CFArrayRef>(property)) {
- base::ListValue* list_value = new base::ListValue();
- CFArrayApplyFunction(array,
- CFRangeMake(0, CFArrayGetCount(array)),
- ArrayEntryToValue,
- list_value);
- return list_value;
- }
-
- return NULL;
-}
-
void PolicyLoaderMac::LoadPolicyForDomain(
PolicyDomain domain,
const std::string& domain_name,
@@ -218,7 +146,7 @@ void PolicyLoaderMac::LoadPolicyForComponent(
preferences_->AppValueIsForced(pref_name, bundle_id);
PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY :
POLICY_LEVEL_RECOMMENDED;
- scoped_ptr<base::Value> policy_value(CreateValueFromProperty(value));
+ scoped_ptr<base::Value> policy_value = PropertyToValue(value);
if (policy_value) {
policy->Set(it.key(), level, POLICY_SCOPE_USER,
policy_value.release(), NULL);

Powered by Google App Engine
This is Rietveld 408576698