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..601f3ccaba7b43726209f7a1927fccad636a691e 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,8 @@ void PolicyLoaderMac::InitOnFile() { |
scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { |
preferences_->AppSynchronize(kCFPreferencesCurrentApplication); |
scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
+ |
+ // Load chrome policy. |
Mattias Nissler (ping if slow)
2013/05/15 10:42:14
I guess that this could use a TODO explaining that
Joao da Silva
2013/05/19 13:22:01
Done.
|
PolicyMap& chrome_policy = |
bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
@@ -126,6 +128,32 @@ scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { |
if (!policy_present) |
status.Add(POLICY_LOAD_STATUS_NO_POLICY); |
+ // Load policy for the registered components. |
+ std::map<PolicyDomain, std::string> supported_domains; |
+ supported_domains[POLICY_DOMAIN_EXTENSIONS] = "extensions"; |
Mattias Nissler (ping if slow)
2013/05/15 10:42:14
I guess this could be factored into a helper funct
Joao da Silva
2013/05/19 13:22:01
Done.
|
+ for (DescriptorMap::const_iterator it_descriptors = descriptor_map().begin(); |
+ it_descriptors != descriptor_map().end(); ++it_descriptors) { |
+ scoped_refptr<const PolicyDomainDescriptor> descriptor = |
+ it_descriptors->second; |
+ const std::string& domain = supported_domains[descriptor->domain()]; |
+ if (domain.empty()) |
+ continue; |
+ std::string id_prefix(base::mac::BaseBundleID()); |
+ id_prefix.append(".").append(domain).append("."); |
+ |
+ for (PolicyDomainDescriptor::SchemaMap::const_iterator it_schema = |
+ descriptor->components().begin(); |
+ it_schema != descriptor->components().end(); ++it_schema) { |
+ PolicyMap policy; |
+ LoadComponentPolicy( |
+ id_prefix + it_schema->first, it_schema->second, &policy); |
+ if (!policy.empty()) { |
+ bundle->Get(PolicyNamespace(descriptor->domain(), it_schema->first)) |
+ .Swap(&policy); |
+ } |
+ } |
+ } |
+ |
return bundle.Pass(); |
} |
@@ -183,6 +211,34 @@ base::Value* PolicyLoaderMac::CreateValueFromProperty( |
return NULL; |
} |
+void PolicyLoaderMac::LoadComponentPolicy(const std::string& bundle_id_string, |
+ const PolicySchema* schema, |
+ PolicyMap* policy) { |
+ base::mac::ScopedCFTypeRef<CFStringRef> bundle_id( |
+ base::SysUTF8ToCFStringRef(bundle_id_string)); |
+ preferences_->AppSynchronize(bundle_id); |
+ |
+ const PolicySchema::TypeMap& types = schema->type_map(); |
+ for (PolicySchema::TypeMap::const_iterator it_type = types.begin(); |
+ it_type != types.end(); ++it_type) { |
+ base::mac::ScopedCFTypeRef<CFStringRef> pref_name( |
+ base::SysUTF8ToCFStringRef(it_type->first)); |
+ base::mac::ScopedCFTypeRef<CFPropertyListRef> value( |
+ preferences_->CopyAppValue(pref_name, bundle_id)); |
+ if (!value.get()) |
+ continue; |
+ bool forced = |
+ preferences_->AppValueIsForced(pref_name, bundle_id); |
+ if (!forced) |
+ continue; |
+ scoped_ptr<base::Value> policy_value(CreateValueFromProperty(value)); |
+ if (policy_value && policy_value->IsType(it_type->second)) { |
+ policy->Set(it_type->first, POLICY_LEVEL_MANDATORY, |
Mattias Nissler (ping if slow)
2013/05/15 10:42:14
mandatory vs. recommended policy level?
Joao da Silva
2013/05/19 13:22:01
Done.
|
+ POLICY_SCOPE_USER, policy_value.release()); |
+ } |
+ } |
+} |
+ |
void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) { |
if (!error) |
Reload(false); |