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

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

Issue 519643002: Default values for enterprise users are supported. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 'configuration resides.\n' 231 'configuration resides.\n'
229 'extern const wchar_t kRegistryChromePolicyKey[];\n') 232 'extern const wchar_t kRegistryChromePolicyKey[];\n')
230 233
231 f.write('// Returns the PolicyDetails for |policy| if |policy| is a known\n' 234 f.write('// Returns the PolicyDetails for |policy| if |policy| is a known\n'
232 '// Chrome policy, otherwise returns NULL.\n' 235 '// Chrome policy, otherwise returns NULL.\n'
233 'const PolicyDetails* GetChromePolicyDetails(' 236 'const PolicyDetails* GetChromePolicyDetails('
234 'const std::string& policy);\n' 237 'const std::string& policy);\n'
235 '\n' 238 '\n'
236 '// Returns the schema data of the Chrome policy schema.\n' 239 '// Returns the schema data of the Chrome policy schema.\n'
237 'const internal::SchemaData* GetChromeSchemaData();\n' 240 'const internal::SchemaData* GetChromeSchemaData();\n'
238 '\n') 241 '\n')
Joao da Silva 2014/08/29 09:11:42 Add a forward declaration for SetEnterpriseUsersDe
merkulova 2014/08/29 14:02:52 Done.
239 f.write('// Key names for the policy settings.\n' 242 f.write('// Key names for the policy settings.\n'
240 'namespace key {\n\n') 243 'namespace key {\n\n')
241 for policy in policies: 244 for policy in policies:
242 # TODO(joaodasilva): Include only supported policies in 245 # TODO(joaodasilva): Include only supported policies in
243 # configuration_policy_handler.cc and configuration_policy_handler_list.cc 246 # configuration_policy_handler.cc and configuration_policy_handler_list.cc
244 # so that these names can be conditional on 'policy.is_supported'. 247 # so that these names can be conditional on 'policy.is_supported'.
245 # http://crbug.com/223616 248 # http://crbug.com/223616
246 f.write('extern const char k' + policy.name + '[];\n') 249 f.write('extern const char k' + policy.name + '[];\n')
247 f.write('\n} // namespace key\n\n' 250 f.write('\n} // namespace key\n\n'
248 '} // namespace policy\n\n' 251 '} // namespace policy\n\n'
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 self.properties_nodes) 569 self.properties_nodes)
567 570
568 def _WritePolicyConstantSource(policies, os, f): 571 def _WritePolicyConstantSource(policies, os, f):
569 f.write('#include "policy/policy_constants.h"\n' 572 f.write('#include "policy/policy_constants.h"\n'
570 '\n' 573 '\n'
571 '#include <algorithm>\n' 574 '#include <algorithm>\n'
572 '#include <climits>\n' 575 '#include <climits>\n'
573 '\n' 576 '\n'
574 '#include "base/logging.h"\n' 577 '#include "base/logging.h"\n'
575 '#include "components/policy/core/common/schema_internal.h"\n' 578 '#include "components/policy/core/common/schema_internal.h"\n'
579 '#include "components/policy/core/common/policy_map.h"\n'
Joao da Silva 2014/08/29 09:11:42 Includes in alphabetical order, so this comes befo
merkulova 2014/08/29 14:02:53 Done.
576 '\n' 580 '\n'
577 'namespace policy {\n' 581 'namespace policy {\n'
578 '\n' 582 '\n'
579 'namespace {\n' 583 'namespace {\n'
580 '\n') 584 '\n')
581 585
582 # Generate the Chrome schema. 586 # Generate the Chrome schema.
583 chrome_schema = { 587 chrome_schema = {
584 'type': 'object', 588 'type': 'object',
585 'properties': {}, 589 'properties': {},
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 'L"' + CHROME_POLICY_KEY + '";\n' 627 'L"' + CHROME_POLICY_KEY + '";\n'
624 '#else\n' 628 '#else\n'
625 'const wchar_t kRegistryChromePolicyKey[] = ' 629 'const wchar_t kRegistryChromePolicyKey[] = '
626 'L"' + CHROMIUM_POLICY_KEY + '";\n' 630 'L"' + CHROMIUM_POLICY_KEY + '";\n'
627 '#endif\n\n') 631 '#endif\n\n')
628 632
629 f.write('const internal::SchemaData* GetChromeSchemaData() {\n' 633 f.write('const internal::SchemaData* GetChromeSchemaData() {\n'
630 ' return &kChromeSchemaData;\n' 634 ' return &kChromeSchemaData;\n'
631 '}\n\n') 635 '}\n\n')
632 636
637 f.write('#if defined(OS_CHROMEOS)\n'
638 'void SetEnterpriseUsersDefaults(PolicyMap* policy_map) {\n')
639
640 for policy in policies:
641 if policy.has_enterprise_default:
Joao da Silva 2014/08/29 09:11:42 Use 2 spaces for indentation instead of 4 (below t
merkulova 2014/08/29 14:02:53 Done.
642 if policy.policy_type == 'TYPE_BOOLEAN':
643 creation_expression = 'new bool(%s)' % policy.enterprise_default
Joao da Silva 2014/08/29 09:11:43 new base::FundamentalValue() Also, the |policy.en
merkulova 2014/08/29 14:02:53 Done.
644 elif policy.policy_type == 'TYPE_INTEGER':
645 creation_expression = 'new int(%s)' % policy.enterprise_default
Joao da Silva 2014/08/29 09:11:42 new base::FundamentalValue
merkulova 2014/08/29 14:02:52 Done.
646 elif policy.policy_type == 'TYPE_STRING':
647 creation_expression = 'new base::StringValue("%s")' %\
648 policy.enterprise_default
649 else:
650 raise RuntimeError('Type %s of policy %s is not supported at '
651 'enterprise defaults' % (policy.policy_type,
652 policy.name))
653 f.write(' if (!policy_map->Get("%s")) {\n'
654 ' policy_map->Set("%s",\n'
Joao da Silva 2014/08/29 09:11:42 These 2 lines are duplicating the string for the p
merkulova 2014/08/29 14:02:52 Done.
655 ' POLICY_LEVEL_MANDATORY,\n'
656 ' POLICY_SCOPE_USER,\n'
657 ' %s,\n'
658 ' NULL);\n'
659 ' }\n' % (policy.name, policy.name, creation_expression))
660
661 f.write('}\n\n'
Joao da Silva 2014/08/29 09:11:42 Single newline here, so that the #endif comes righ
merkulova 2014/08/29 14:02:52 Done.
662 '#endif\n\n')
663
633 f.write('const PolicyDetails* GetChromePolicyDetails(' 664 f.write('const PolicyDetails* GetChromePolicyDetails('
634 'const std::string& policy) {\n' 665 'const std::string& policy) {\n'
635 ' // First index in kPropertyNodes of the Chrome policies.\n' 666 ' // First index in kPropertyNodes of the Chrome policies.\n'
636 ' static const int begin_index = %s;\n' 667 ' static const int begin_index = %s;\n'
637 ' // One-past-the-end of the Chrome policies in kPropertyNodes.\n' 668 ' // One-past-the-end of the Chrome policies in kPropertyNodes.\n'
638 ' static const int end_index = %s;\n' % 669 ' static const int end_index = %s;\n' %
639 (schema_generator.root_properties_begin, 670 (schema_generator.root_properties_begin,
640 schema_generator.root_properties_end)) 671 schema_generator.root_properties_end))
641 f.write(' const internal::PropertyNode* begin =\n' 672 f.write(' const internal::PropertyNode* begin =\n'
642 ' kPropertyNodes + begin_index;\n' 673 ' kPropertyNodes + begin_index;\n'
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 def _WriteCloudPolicyDecoder(policies, os, f): 950 def _WriteCloudPolicyDecoder(policies, os, f):
920 f.write(CPP_HEAD) 951 f.write(CPP_HEAD)
921 for policy in policies: 952 for policy in policies:
922 if policy.is_supported and not policy.is_device_only: 953 if policy.is_supported and not policy.is_device_only:
923 _WritePolicyCode(f, policy) 954 _WritePolicyCode(f, policy)
924 f.write(CPP_FOOT) 955 f.write(CPP_FOOT)
925 956
926 957
927 if __name__ == '__main__': 958 if __name__ == '__main__':
928 sys.exit(main()) 959 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698