Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 def __init__(self, item): | 50 def __init__(self, item): |
| 51 self.caption = PolicyDetails._RemovePlaceholders(item['caption']) | 51 self.caption = PolicyDetails._RemovePlaceholders(item['caption']) |
| 52 self.value = item['value'] | 52 self.value = item['value'] |
| 53 | 53 |
| 54 def __init__(self, policy, os, is_chromium_os): | 54 def __init__(self, policy, os, is_chromium_os): |
| 55 self.id = policy['id'] | 55 self.id = policy['id'] |
| 56 self.name = policy['name'] | 56 self.name = policy['name'] |
| 57 self.is_deprecated = policy.get('deprecated', False) | 57 self.is_deprecated = policy.get('deprecated', False) |
| 58 self.is_device_only = policy.get('device_only', False) | 58 self.is_device_only = policy.get('device_only', False) |
| 59 self.schema = policy.get('schema', {}) | 59 self.schema = policy.get('schema', {}) |
| 60 self.has_enterprise_default = 'default_for_enterprise_users' in policy | |
| 61 if self.has_enterprise_default: | |
| 62 self.enterprise_default = policy['default_for_enterprise_users'] | |
| 60 | 63 |
| 61 expected_platform = 'chrome_os' if is_chromium_os else os.lower() | 64 expected_platform = 'chrome_os' if is_chromium_os else os.lower() |
| 62 self.platforms = [] | 65 self.platforms = [] |
| 63 for platform, version in [ p.split(':') for p in policy['supported_on'] ]: | 66 for platform, version in [ p.split(':') for p in policy['supported_on'] ]: |
| 64 if not version.endswith('-'): | 67 if not version.endswith('-'): |
| 65 continue | 68 continue |
| 66 | 69 |
| 67 if platform.startswith('chrome.'): | 70 if platform.startswith('chrome.'): |
| 68 platform_sub = platform[7:] | 71 platform_sub = platform[7:] |
| 69 if platform_sub == '*': | 72 if platform_sub == '*': |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 | 212 |
| 210 def _WritePolicyConstantHeader(policies, os, f): | 213 def _WritePolicyConstantHeader(policies, os, f): |
| 211 f.write('#ifndef CHROME_COMMON_POLICY_CONSTANTS_H_\n' | 214 f.write('#ifndef CHROME_COMMON_POLICY_CONSTANTS_H_\n' |
| 212 '#define CHROME_COMMON_POLICY_CONSTANTS_H_\n' | 215 '#define CHROME_COMMON_POLICY_CONSTANTS_H_\n' |
| 213 '\n' | 216 '\n' |
| 214 '#include <string>\n' | 217 '#include <string>\n' |
| 215 '\n' | 218 '\n' |
| 216 '#include "base/basictypes.h"\n' | 219 '#include "base/basictypes.h"\n' |
| 217 '#include "base/values.h"\n' | 220 '#include "base/values.h"\n' |
| 218 '#include "components/policy/core/common/policy_details.h"\n' | 221 '#include "components/policy/core/common/policy_details.h"\n' |
| 222 '#include "components/policy/core/common/policy_map.h"\n' | |
| 219 '\n' | 223 '\n' |
| 220 'namespace policy {\n' | 224 'namespace policy {\n' |
| 221 '\n' | 225 '\n' |
| 222 'namespace internal {\n' | 226 'namespace internal {\n' |
| 223 'struct SchemaData;\n' | 227 'struct SchemaData;\n' |
| 224 '}\n\n') | 228 '}\n\n') |
| 225 | 229 |
| 226 if os == 'win': | 230 if os == 'win': |
| 227 f.write('// The windows registry path where Chrome policy ' | 231 f.write('// The windows registry path where Chrome policy ' |
| 228 'configuration resides.\n' | 232 'configuration resides.\n' |
| 229 'extern const wchar_t kRegistryChromePolicyKey[];\n') | 233 'extern const wchar_t kRegistryChromePolicyKey[];\n') |
| 230 | 234 |
| 231 f.write('// Returns the PolicyDetails for |policy| if |policy| is a known\n' | 235 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.
| |
| 236 '// Sets default values for enterprise users.\n' | |
| 237 'void SetEnterpriseUsersDefaults(PolicyMap* policy_map);\n' | |
| 238 '#endif\n' | |
| 239 '\n' | |
| 240 '// Returns the PolicyDetails for |policy| if |policy| is a known\n' | |
| 232 '// Chrome policy, otherwise returns NULL.\n' | 241 '// Chrome policy, otherwise returns NULL.\n' |
| 233 'const PolicyDetails* GetChromePolicyDetails(' | 242 'const PolicyDetails* GetChromePolicyDetails(' |
| 234 'const std::string& policy);\n' | 243 'const std::string& policy);\n' |
| 235 '\n' | 244 '\n' |
| 236 '// Returns the schema data of the Chrome policy schema.\n' | 245 '// Returns the schema data of the Chrome policy schema.\n' |
| 237 'const internal::SchemaData* GetChromeSchemaData();\n' | 246 'const internal::SchemaData* GetChromeSchemaData();\n' |
| 238 '\n') | 247 '\n') |
| 239 f.write('// Key names for the policy settings.\n' | 248 f.write('// Key names for the policy settings.\n' |
| 240 'namespace key {\n\n') | 249 'namespace key {\n\n') |
| 241 for policy in policies: | 250 for policy in policies: |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 'L"' + CHROME_POLICY_KEY + '";\n' | 632 'L"' + CHROME_POLICY_KEY + '";\n' |
| 624 '#else\n' | 633 '#else\n' |
| 625 'const wchar_t kRegistryChromePolicyKey[] = ' | 634 'const wchar_t kRegistryChromePolicyKey[] = ' |
| 626 'L"' + CHROMIUM_POLICY_KEY + '";\n' | 635 'L"' + CHROMIUM_POLICY_KEY + '";\n' |
| 627 '#endif\n\n') | 636 '#endif\n\n') |
| 628 | 637 |
| 629 f.write('const internal::SchemaData* GetChromeSchemaData() {\n' | 638 f.write('const internal::SchemaData* GetChromeSchemaData() {\n' |
| 630 ' return &kChromeSchemaData;\n' | 639 ' return &kChromeSchemaData;\n' |
| 631 '}\n\n') | 640 '}\n\n') |
| 632 | 641 |
| 642 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.
| |
| 643 'void SetEnterpriseUsersDefaults(PolicyMap* policy_map) {\n') | |
| 644 | |
| 645 for policy in policies: | |
| 646 if policy.has_enterprise_default: | |
| 647 if policy.policy_type == 'TYPE_BOOLEAN': | |
| 648 creation_expression = 'new base::FundamentalValue(%s)' %\ | |
| 649 ('true' if policy.enterprise_default else 'false') | |
| 650 elif policy.policy_type == 'TYPE_INTEGER': | |
| 651 creation_expression = 'new base::FundamentalValue(%s)' %\ | |
| 652 policy.enterprise_default | |
| 653 elif policy.policy_type == 'TYPE_STRING': | |
| 654 creation_expression = 'new base::StringValue("%s")' %\ | |
| 655 policy.enterprise_default | |
| 656 else: | |
| 657 raise RuntimeError('Type %s of policy %s is not supported at ' | |
| 658 'enterprise defaults' % (policy.policy_type, | |
| 659 policy.name)) | |
| 660 f.write(' if (!policy_map->Get(key::k%s)) {\n' | |
| 661 ' policy_map->Set(key::k%s,\n' | |
| 662 ' POLICY_LEVEL_MANDATORY,\n' | |
| 663 ' POLICY_SCOPE_USER,\n' | |
| 664 ' %s,\n' | |
| 665 ' NULL);\n' | |
| 666 ' }\n' % (policy.name, policy.name, creation_expression)) | |
| 667 | |
| 668 f.write('}\n' | |
| 669 '#endif\n\n') | |
| 670 | |
| 633 f.write('const PolicyDetails* GetChromePolicyDetails(' | 671 f.write('const PolicyDetails* GetChromePolicyDetails(' |
| 634 'const std::string& policy) {\n' | 672 'const std::string& policy) {\n' |
| 635 ' // First index in kPropertyNodes of the Chrome policies.\n' | 673 ' // First index in kPropertyNodes of the Chrome policies.\n' |
| 636 ' static const int begin_index = %s;\n' | 674 ' static const int begin_index = %s;\n' |
| 637 ' // One-past-the-end of the Chrome policies in kPropertyNodes.\n' | 675 ' // One-past-the-end of the Chrome policies in kPropertyNodes.\n' |
| 638 ' static const int end_index = %s;\n' % | 676 ' static const int end_index = %s;\n' % |
| 639 (schema_generator.root_properties_begin, | 677 (schema_generator.root_properties_begin, |
| 640 schema_generator.root_properties_end)) | 678 schema_generator.root_properties_end)) |
| 641 f.write(' const internal::PropertyNode* begin =\n' | 679 f.write(' const internal::PropertyNode* begin =\n' |
| 642 ' kPropertyNodes + begin_index;\n' | 680 ' kPropertyNodes + begin_index;\n' |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 919 def _WriteCloudPolicyDecoder(policies, os, f): | 957 def _WriteCloudPolicyDecoder(policies, os, f): |
| 920 f.write(CPP_HEAD) | 958 f.write(CPP_HEAD) |
| 921 for policy in policies: | 959 for policy in policies: |
| 922 if policy.is_supported and not policy.is_device_only: | 960 if policy.is_supported and not policy.is_device_only: |
| 923 _WritePolicyCode(f, policy) | 961 _WritePolicyCode(f, policy) |
| 924 f.write(CPP_FOOT) | 962 f.write(CPP_FOOT) |
| 925 | 963 |
| 926 | 964 |
| 927 if __name__ == '__main__': | 965 if __name__ == '__main__': |
| 928 sys.exit(main()) | 966 sys.exit(main()) |
| OLD | NEW |