Index: components/policy/tools/generate_policy_source.py |
diff --git a/components/policy/tools/generate_policy_source.py b/components/policy/tools/generate_policy_source.py |
index 4e07baa70dbd6ed870dfa982ecc14ad883fe9237..826c91544cc1a37f78920e64f76514d0b797cd9d 100755 |
--- a/components/policy/tools/generate_policy_source.py |
+++ b/components/policy/tools/generate_policy_source.py |
@@ -57,6 +57,9 @@ class PolicyDetails: |
self.is_deprecated = policy.get('deprecated', False) |
self.is_device_only = policy.get('device_only', False) |
self.schema = policy.get('schema', {}) |
+ self.has_enterprise_default = 'default_for_enterprise_users' in policy |
+ if self.has_enterprise_default: |
+ self.enterprise_default = policy['default_for_enterprise_users'] |
expected_platform = 'chrome_os' if is_chromium_os else os.lower() |
self.platforms = [] |
@@ -216,6 +219,7 @@ def _WritePolicyConstantHeader(policies, os, f): |
'#include "base/basictypes.h"\n' |
'#include "base/values.h"\n' |
'#include "components/policy/core/common/policy_details.h"\n' |
+ '#include "components/policy/core/common/policy_map.h"\n' |
'\n' |
'namespace policy {\n' |
'\n' |
@@ -228,7 +232,12 @@ def _WritePolicyConstantHeader(policies, os, f): |
'configuration resides.\n' |
'extern const wchar_t kRegistryChromePolicyKey[];\n') |
- f.write('// Returns the PolicyDetails for |policy| if |policy| is a known\n' |
+ f.write('#ifdef OS_CHROMEOS\n' |
Joao da Silva
2014/09/01 09:09:11
#if defined(OS_CHROMEOS)
merkulova
2014/09/01 09:26:24
Done.
|
+ '// Sets default values for enterprise users.\n' |
+ 'void SetEnterpriseUsersDefaults(PolicyMap* policy_map);\n' |
+ '#endif\n' |
+ '\n' |
+ '// Returns the PolicyDetails for |policy| if |policy| is a known\n' |
'// Chrome policy, otherwise returns NULL.\n' |
'const PolicyDetails* GetChromePolicyDetails(' |
'const std::string& policy);\n' |
@@ -630,6 +639,35 @@ def _WritePolicyConstantSource(policies, os, f): |
' return &kChromeSchemaData;\n' |
'}\n\n') |
+ f.write('#ifdef OS_CHROMEOS\n' |
Joao da Silva
2014/09/01 09:09:11
#if defined(OS_CHROMEOS)
merkulova
2014/09/01 09:26:24
Done.
|
+ 'void SetEnterpriseUsersDefaults(PolicyMap* policy_map) {\n') |
+ |
+ for policy in policies: |
+ if policy.has_enterprise_default: |
+ if policy.policy_type == 'TYPE_BOOLEAN': |
+ creation_expression = 'new base::FundamentalValue(%s)' %\ |
+ ('true' if policy.enterprise_default else 'false') |
+ elif policy.policy_type == 'TYPE_INTEGER': |
+ creation_expression = 'new base::FundamentalValue(%s)' %\ |
+ policy.enterprise_default |
+ elif policy.policy_type == 'TYPE_STRING': |
+ creation_expression = 'new base::StringValue("%s")' %\ |
+ policy.enterprise_default |
+ else: |
+ raise RuntimeError('Type %s of policy %s is not supported at ' |
+ 'enterprise defaults' % (policy.policy_type, |
+ policy.name)) |
+ f.write(' if (!policy_map->Get(key::k%s)) {\n' |
+ ' policy_map->Set(key::k%s,\n' |
+ ' POLICY_LEVEL_MANDATORY,\n' |
+ ' POLICY_SCOPE_USER,\n' |
+ ' %s,\n' |
+ ' NULL);\n' |
+ ' }\n' % (policy.name, policy.name, creation_expression)) |
+ |
+ f.write('}\n' |
+ '#endif\n\n') |
+ |
f.write('const PolicyDetails* GetChromePolicyDetails(' |
'const std::string& policy) {\n' |
' // First index in kPropertyNodes of the Chrome policies.\n' |