| Index: chrome/browser/policy/policy_loader_mac.cc
|
| diff --git a/chrome/browser/policy/policy_loader_mac.cc b/chrome/browser/policy/policy_loader_mac.cc
|
| index 291063b620acbb83c2f345ed5e28b1fafe13c7fc..761a7a6f767f1f85d0d0cf0c9e9b7e4251d1969a 100644
|
| --- a/chrome/browser/policy/policy_loader_mac.cc
|
| +++ b/chrome/browser/policy/policy_loader_mac.cc
|
| @@ -4,8 +4,6 @@
|
|
|
| #include "chrome/browser/policy/policy_loader_mac.h"
|
|
|
| -#include <string>
|
| -
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| #include "base/file_util.h"
|
| @@ -16,8 +14,10 @@
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/policy/policy_bundle.h"
|
| +#include "chrome/browser/policy/policy_domain_descriptor.h"
|
| #include "chrome/browser/policy/policy_load_status.h"
|
| #include "chrome/browser/policy/policy_map.h"
|
| +#include "chrome/browser/policy/policy_schema.h"
|
| #include "chrome/browser/policy/preferences_mac.h"
|
| #include "chrome/common/chrome_paths.h"
|
| #include "policy/policy_constants.h"
|
| @@ -97,6 +97,10 @@ void PolicyLoaderMac::InitOnFile() {
|
| scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() {
|
| preferences_->AppSynchronize(kCFPreferencesCurrentApplication);
|
| scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
|
| +
|
| + // Load Chrome's policy.
|
| + // TODO(joaodasilva): use a schema for Chrome once it's generated and
|
| + // available from a PolicyDomainDescriptor.
|
| PolicyMap& chrome_policy =
|
| bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
|
|
|
| @@ -126,6 +130,22 @@ scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() {
|
| if (!policy_present)
|
| status.Add(POLICY_LOAD_STATUS_NO_POLICY);
|
|
|
| + // Load policy for the registered components.
|
| + static const struct {
|
| + PolicyDomain domain;
|
| + const char* domain_name;
|
| + } kSupportedDomains[] = {
|
| + { POLICY_DOMAIN_EXTENSIONS, "extensions" },
|
| + };
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSupportedDomains); ++i) {
|
| + DescriptorMap::const_iterator it =
|
| + descriptor_map().find(kSupportedDomains[i].domain);
|
| + if (it != descriptor_map().end()) {
|
| + LoadPolicyForDomain(
|
| + it->second, kSupportedDomains[i].domain_name, bundle.get());
|
| + }
|
| + }
|
| +
|
| return bundle.Pass();
|
| }
|
|
|
| @@ -183,6 +203,65 @@ base::Value* PolicyLoaderMac::CreateValueFromProperty(
|
| return NULL;
|
| }
|
|
|
| +void PolicyLoaderMac::LoadPolicyForDomain(
|
| + scoped_refptr<const PolicyDomainDescriptor> descriptor,
|
| + const std::string& domain_name,
|
| + PolicyBundle* bundle) {
|
| + std::string id_prefix(base::mac::BaseBundleID());
|
| + id_prefix.append(".").append(domain_name).append(".");
|
| +
|
| + for (PolicyDomainDescriptor::SchemaMap::const_iterator it_schema =
|
| + descriptor->components().begin();
|
| + it_schema != descriptor->components().end(); ++it_schema) {
|
| + PolicyMap policy;
|
| + LoadPolicyForComponent(
|
| + id_prefix + it_schema->first, it_schema->second, &policy);
|
| + if (!policy.empty()) {
|
| + bundle->Get(PolicyNamespace(descriptor->domain(), it_schema->first))
|
| + .Swap(&policy);
|
| + }
|
| + }
|
| +}
|
| +
|
| +void PolicyLoaderMac::LoadPolicyForComponent(
|
| + const std::string& bundle_id_string,
|
| + const PolicySchema* schema,
|
| + PolicyMap* policy) {
|
| + // TODO(joaodasilva): extensions may be registered in a PolicyDomainDescriptor
|
| + // without a PolicySchema, to allow a graceful update of the Legacy Browser
|
| + // Support extension on Windows. Remove this temporary check once that support
|
| + // is removed.
|
| + if (!schema)
|
| + return;
|
| +
|
| + base::mac::ScopedCFTypeRef<CFStringRef> bundle_id(
|
| + base::SysUTF8ToCFStringRef(bundle_id_string));
|
| + preferences_->AppSynchronize(bundle_id);
|
| +
|
| + const PolicySchemaMap* map = schema->GetProperties();
|
| + if (!map) {
|
| + NOTREACHED();
|
| + return;
|
| + }
|
| +
|
| + for (PolicySchemaMap::const_iterator it = map->begin();
|
| + it != map->end(); ++it) {
|
| + base::mac::ScopedCFTypeRef<CFStringRef> pref_name(
|
| + base::SysUTF8ToCFStringRef(it->first));
|
| + base::mac::ScopedCFTypeRef<CFPropertyListRef> value(
|
| + preferences_->CopyAppValue(pref_name, bundle_id));
|
| + if (!value.get())
|
| + continue;
|
| + bool forced =
|
| + preferences_->AppValueIsForced(pref_name, bundle_id);
|
| + PolicyLevel level = forced ? POLICY_LEVEL_MANDATORY :
|
| + POLICY_LEVEL_RECOMMENDED;
|
| + scoped_ptr<base::Value> policy_value(CreateValueFromProperty(value));
|
| + if (policy_value)
|
| + policy->Set(it->first, level, POLICY_SCOPE_USER, policy_value.release());
|
| + }
|
| +}
|
| +
|
| void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) {
|
| if (!error)
|
| Reload(false);
|
|
|