Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: components/policy/tools/generate_policy_source.py

Issue 2275963004: Apply default policy values also on non-ChromeOS
Patch Set: move down into UserCloudPolicyManager[ChromeOS] Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/policy/core/common/cloud/user_cloud_policy_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''python %prog [options] platform chromium_os_flag template 6 '''python %prog [options] platform chromium_os_flag template
7 7
8 platform specifies which platform source is being generated for 8 platform specifies which platform source is being generated for
9 and can be one of (win, mac, linux) 9 and can be one of (win, mac, linux)
10 chromium_os_flag should be 1 if this is a Chromium OS build 10 chromium_os_flag should be 1 if this is a Chromium OS build
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 '\n' 310 '\n'
311 'namespace internal {\n' 311 'namespace internal {\n'
312 'struct SchemaData;\n' 312 'struct SchemaData;\n'
313 '}\n\n') 313 '}\n\n')
314 314
315 if os == 'win': 315 if os == 'win':
316 f.write('// The windows registry path where Chrome policy ' 316 f.write('// The windows registry path where Chrome policy '
317 'configuration resides.\n' 317 'configuration resides.\n'
318 'extern const wchar_t kRegistryChromePolicyKey[];\n') 318 'extern const wchar_t kRegistryChromePolicyKey[];\n')
319 319
320 f.write('#if defined (OS_CHROMEOS)\n' 320 f.write('// Sets default values for enterprise users.\n'
321 '// Sets default values for enterprise users.\n'
322 'void SetEnterpriseUsersDefaults(PolicyMap* policy_map);\n' 321 'void SetEnterpriseUsersDefaults(PolicyMap* policy_map);\n'
323 '#endif\n'
324 '\n' 322 '\n'
325 '// Returns the PolicyDetails for |policy| if |policy| is a known\n' 323 '// Returns the PolicyDetails for |policy| if |policy| is a known\n'
326 '// Chrome policy, otherwise returns NULL.\n' 324 '// Chrome policy, otherwise returns NULL.\n'
327 'const PolicyDetails* GetChromePolicyDetails(' 325 'const PolicyDetails* GetChromePolicyDetails('
328 'const std::string& policy);\n' 326 'const std::string& policy);\n'
329 '\n' 327 '\n'
330 '// Returns the schema data of the Chrome policy schema.\n' 328 '// Returns the schema data of the Chrome policy schema.\n'
331 'const internal::SchemaData* GetChromeSchemaData();\n' 329 'const internal::SchemaData* GetChromeSchemaData();\n'
332 '\n') 330 '\n')
333 f.write('// Key names for the policy settings.\n' 331 f.write('// Key names for the policy settings.\n'
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 'L"' + CHROME_POLICY_KEY + '";\n' 722 'L"' + CHROME_POLICY_KEY + '";\n'
725 '#else\n' 723 '#else\n'
726 'const wchar_t kRegistryChromePolicyKey[] = ' 724 'const wchar_t kRegistryChromePolicyKey[] = '
727 'L"' + CHROMIUM_POLICY_KEY + '";\n' 725 'L"' + CHROMIUM_POLICY_KEY + '";\n'
728 '#endif\n\n') 726 '#endif\n\n')
729 727
730 f.write('const internal::SchemaData* GetChromeSchemaData() {\n' 728 f.write('const internal::SchemaData* GetChromeSchemaData() {\n'
731 ' return &kChromeSchemaData;\n' 729 ' return &kChromeSchemaData;\n'
732 '}\n\n') 730 '}\n\n')
733 731
734 f.write('#if defined (OS_CHROMEOS)\n' 732 f.write('void SetEnterpriseUsersDefaults(PolicyMap* policy_map) {\n')
735 'void SetEnterpriseUsersDefaults(PolicyMap* policy_map) {\n')
736 733
737 for policy in policies: 734 for policy in policies:
738 if policy.has_enterprise_default: 735 if policy.has_enterprise_default:
739 if policy.policy_type == 'TYPE_BOOLEAN': 736 if policy.policy_type == 'TYPE_BOOLEAN':
740 creation_expression = 'new base::FundamentalValue(%s)' %\ 737 creation_expression = 'new base::FundamentalValue(%s)' %\
741 ('true' if policy.enterprise_default else 'false') 738 ('true' if policy.enterprise_default else 'false')
742 elif policy.policy_type == 'TYPE_INTEGER': 739 elif policy.policy_type == 'TYPE_INTEGER':
743 creation_expression = 'new base::FundamentalValue(%s)' %\ 740 creation_expression = 'new base::FundamentalValue(%s)' %\
744 policy.enterprise_default 741 policy.enterprise_default
745 elif policy.policy_type == 'TYPE_STRING': 742 elif policy.policy_type == 'TYPE_STRING':
746 creation_expression = 'new base::StringValue("%s")' %\ 743 creation_expression = 'new base::StringValue("%s")' %\
747 policy.enterprise_default 744 policy.enterprise_default
748 else: 745 else:
749 raise RuntimeError('Type %s of policy %s is not supported at ' 746 raise RuntimeError('Type %s of policy %s is not supported at '
750 'enterprise defaults' % (policy.policy_type, 747 'enterprise defaults' % (policy.policy_type,
751 policy.name)) 748 policy.name))
752 f.write(' if (!policy_map->Get(key::k%s)) {\n' 749 f.write(' if (!policy_map->Get(key::k%s)) {\n'
753 ' policy_map->Set(key::k%s,\n' 750 ' policy_map->Set(key::k%s,\n'
754 ' POLICY_LEVEL_MANDATORY,\n' 751 ' POLICY_LEVEL_MANDATORY,\n'
755 ' POLICY_SCOPE_USER,\n' 752 ' POLICY_SCOPE_USER,\n'
756 ' POLICY_SOURCE_ENTERPRISE_DEFAULT,\n' 753 ' POLICY_SOURCE_ENTERPRISE_DEFAULT,\n'
757 ' base::WrapUnique(%s),\n' 754 ' base::WrapUnique(%s),\n'
758 ' NULL);\n' 755 ' NULL);\n'
759 ' }\n' % (policy.name, policy.name, creation_expression)) 756 ' }\n' % (policy.name, policy.name, creation_expression))
760 757
761 f.write('}\n' 758 f.write('}\n\n')
762 '#endif\n\n')
763 759
764 f.write('const PolicyDetails* GetChromePolicyDetails(' 760 f.write('const PolicyDetails* GetChromePolicyDetails('
765 'const std::string& policy) {\n' 761 'const std::string& policy) {\n'
766 ' // First index in kPropertyNodes of the Chrome policies.\n' 762 ' // First index in kPropertyNodes of the Chrome policies.\n'
767 ' static const int begin_index = %s;\n' 763 ' static const int begin_index = %s;\n'
768 ' // One-past-the-end of the Chrome policies in kPropertyNodes.\n' 764 ' // One-past-the-end of the Chrome policies in kPropertyNodes.\n'
769 ' static const int end_index = %s;\n' % 765 ' static const int end_index = %s;\n' %
770 (schema_generator.root_properties_begin, 766 (schema_generator.root_properties_begin,
771 schema_generator.root_properties_end)) 767 schema_generator.root_properties_end))
772 f.write(' const internal::PropertyNode* begin =\n' 768 f.write(' const internal::PropertyNode* begin =\n'
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 # _WriteAppRestrictions body 1166 # _WriteAppRestrictions body
1171 f.write('<restrictions xmlns:android="' 1167 f.write('<restrictions xmlns:android="'
1172 'http://schemas.android.com/apk/res/android">\n\n') 1168 'http://schemas.android.com/apk/res/android">\n\n')
1173 for policy in policies: 1169 for policy in policies:
1174 if policy.is_supported and policy.restriction_type != 'invalid': 1170 if policy.is_supported and policy.restriction_type != 'invalid':
1175 WriteAppRestriction(policy) 1171 WriteAppRestriction(policy)
1176 f.write('</restrictions>') 1172 f.write('</restrictions>')
1177 1173
1178 if __name__ == '__main__': 1174 if __name__ == '__main__':
1179 sys.exit(main()) 1175 sys.exit(main())
OLDNEW
« no previous file with comments | « components/policy/core/common/cloud/user_cloud_policy_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698