Load policy for extensions at the Mac policy provider.

The Mac policy provider loads policies for the browser. This change makes it
additionally load policies for the extensions described in the PolicyDomainDescriptor
for extensions.

BUG=108992

Review URL: https://chromiumcodereview.appspot.com/15038007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202597 0039d316-1c4b-4281-b951-d872f2087c98
parent 0224e60c
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "chrome/browser/policy/policy_loader_mac.h" #include "chrome/browser/policy/policy_loader_mac.h"
#include <string>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/file_util.h" #include "base/file_util.h"
...@@ -16,8 +14,10 @@ ...@@ -16,8 +14,10 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/policy/policy_bundle.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_load_status.h"
#include "chrome/browser/policy/policy_map.h" #include "chrome/browser/policy/policy_map.h"
#include "chrome/browser/policy/policy_schema.h"
#include "chrome/browser/policy/preferences_mac.h" #include "chrome/browser/policy/preferences_mac.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "policy/policy_constants.h" #include "policy/policy_constants.h"
...@@ -97,6 +97,10 @@ void PolicyLoaderMac::InitOnFile() { ...@@ -97,6 +97,10 @@ void PolicyLoaderMac::InitOnFile() {
scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() {
preferences_->AppSynchronize(kCFPreferencesCurrentApplication); preferences_->AppSynchronize(kCFPreferencesCurrentApplication);
scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); 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 = PolicyMap& chrome_policy =
bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
...@@ -126,6 +130,22 @@ scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() { ...@@ -126,6 +130,22 @@ scoped_ptr<PolicyBundle> PolicyLoaderMac::Load() {
if (!policy_present) if (!policy_present)
status.Add(POLICY_LOAD_STATUS_NO_POLICY); 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(); return bundle.Pass();
} }
...@@ -183,6 +203,65 @@ base::Value* PolicyLoaderMac::CreateValueFromProperty( ...@@ -183,6 +203,65 @@ base::Value* PolicyLoaderMac::CreateValueFromProperty(
return NULL; 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) { void PolicyLoaderMac::OnFileUpdated(const base::FilePath& path, bool error) {
if (!error) if (!error)
Reload(false); Reload(false);
......
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
#ifndef CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_ #ifndef CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_
#define CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_ #define CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_
#include <string>
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_path_watcher.h" #include "base/files/file_path_watcher.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/policy/async_policy_loader.h" #include "chrome/browser/policy/async_policy_loader.h"
class MacPreferences; class MacPreferences;
...@@ -19,6 +22,9 @@ class Value; ...@@ -19,6 +22,9 @@ class Value;
namespace policy { namespace policy {
class PolicyDomainDescriptor;
class PolicyMap;
class PolicySchema;
struct PolicyDefinitionList; struct PolicyDefinitionList;
// A policy loader that loads policies from the Mac preferences system, and // A policy loader that loads policies from the Mac preferences system, and
...@@ -44,6 +50,19 @@ class PolicyLoaderMac : public AsyncPolicyLoader { ...@@ -44,6 +50,19 @@ class PolicyLoaderMac : public AsyncPolicyLoader {
// Callback for the FilePathWatcher. // Callback for the FilePathWatcher.
void OnFileUpdated(const base::FilePath& path, bool error); void OnFileUpdated(const base::FilePath& path, bool error);
// Loads policies for the components described in |descriptor|, which belong
// to the domain |domain_name|, and stores them in the |bundle|.
void LoadPolicyForDomain(
scoped_refptr<const PolicyDomainDescriptor> descriptor,
const std::string& domain_name,
PolicyBundle* bundle);
// Loads the policies described in |schema| from the bundle identified by
// |bundle_id_string|, and stores them in |policy|.
void LoadPolicyForComponent(const std::string& bundle_id_string,
const PolicySchema* schema,
PolicyMap* policy);
// List of recognized policies. // List of recognized policies.
const PolicyDefinitionList* policy_list_; const PolicyDefinitionList* policy_list_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment