diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-14 20:05:21 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-14 20:05:21 +0000 |
commit | 4cd7adb2f69afcebd5690b10d24cd13f5c05f095 (patch) | |
tree | b563fafc38aed7c76795ff568d035dc7b011e361 /chrome/browser/configuration_policy_provider_mac.cc | |
parent | e63783695ea1efc9789883c132b7cfb56c26454c (diff) | |
download | chromium_src-4cd7adb2f69afcebd5690b10d24cd13f5c05f095.zip chromium_src-4cd7adb2f69afcebd5690b10d24cd13f5c05f095.tar.gz chromium_src-4cd7adb2f69afcebd5690b10d24cd13f5c05f095.tar.bz2 |
Policy provider for the Mac.
BUG=http://crbug.com/7147
TEST=unit tested; not integrated yet
Review URL: http://codereview.chromium.org/2605002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49715 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/configuration_policy_provider_mac.cc')
-rw-r--r-- | chrome/browser/configuration_policy_provider_mac.cc | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/chrome/browser/configuration_policy_provider_mac.cc b/chrome/browser/configuration_policy_provider_mac.cc new file mode 100644 index 0000000..c1a9c2c --- /dev/null +++ b/chrome/browser/configuration_policy_provider_mac.cc @@ -0,0 +1,78 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/configuration_policy_provider_mac.h" + +#include "base/logging.h" +#include "base/scoped_cftyperef.h" +#include "base/sys_string_conversions.h" + +ConfigurationPolicyProviderMac::ConfigurationPolicyProviderMac() + : preferences_(new MacPreferences()) { +} + +ConfigurationPolicyProviderMac::ConfigurationPolicyProviderMac( + MacPreferences* preferences) : preferences_(preferences) { +} + +bool ConfigurationPolicyProviderMac::Provide(ConfigurationPolicyStore* store) { + bool success = true; + const PolicyValueMap* mapping = PolicyValueMapping(); + + for (PolicyValueMap::const_iterator current = mapping->begin(); + current != mapping->end(); ++current) { + scoped_cftyperef<CFStringRef> name( + base::SysUTF8ToCFStringRef(current->name)); + scoped_cftyperef<CFPropertyListRef> value( + preferences_->CopyAppValue(name, kCFPreferencesCurrentApplication)); + if (!value.get()) + continue; + if (!preferences_->AppValueIsForced(name, kCFPreferencesCurrentApplication)) + continue; + + switch (current->value_type) { + case Value::TYPE_STRING: + if (CFGetTypeID(value) == CFStringGetTypeID()) { + std::string string_value = + base::SysCFStringRefToUTF8((CFStringRef)value.get()); + store->Apply( + current->policy_type, + Value::CreateStringValue(string_value)); + } else { + success = false; + } + break; + case Value::TYPE_BOOLEAN: + if (CFGetTypeID(value) == CFBooleanGetTypeID()) { + bool bool_value = CFBooleanGetValue((CFBooleanRef)value.get()); + store->Apply(current->policy_type, + Value::CreateBooleanValue(bool_value)); + } else { + success = false; + } + break; + case Value::TYPE_INTEGER: + if (CFGetTypeID(value) == CFNumberGetTypeID()) { + int int_value; + bool cast = CFNumberGetValue((CFNumberRef)value.get(), + kCFNumberIntType, + &int_value); + if (cast) + store->Apply(current->policy_type, + Value::CreateIntegerValue(int_value)); + else + success = false; + } else { + success = false; + } + break; + default: + NOTREACHED(); + return false; + } + } + + return success; +} + |