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

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

Issue 2656713008: cros: Ensure quick unlock is disabled by default for enterprise policy. (Closed)
Patch Set: Created 3 years, 10 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/resources/policy_templates.json ('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 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 might be either int or string. An int type suggests that it's a resolved 653 might be either int or string. An int type suggests that it's a resolved
654 index, but for string type it's unresolved. Resolving a reference is as 654 index, but for string type it's unresolved. Resolving a reference is as
655 simple as looking up for corresponding ID in self.id_map, and replace the 655 simple as looking up for corresponding ID in self.id_map, and replace the
656 old index with the mapped index. 656 old index with the mapped index.
657 """ 657 """
658 self.schema_nodes = map(partial(self.ResolveID, 1), self.schema_nodes) 658 self.schema_nodes = map(partial(self.ResolveID, 1), self.schema_nodes)
659 self.property_nodes = map(partial(self.ResolveID, 1), self.property_nodes) 659 self.property_nodes = map(partial(self.ResolveID, 1), self.property_nodes)
660 self.properties_nodes = map(partial(self.ResolveID, 3), 660 self.properties_nodes = map(partial(self.ResolveID, 3),
661 self.properties_nodes) 661 self.properties_nodes)
662 662
663 def _GenerateDefaultValue(value):
664 """Converts a JSON object into a base::Value entry. Returns a tuple, the first
665 entry being a list of declaration statements to define the variable, the
666 second entry being a way to access the variable.
667
668 If no definition is needed, the first return value will be an empty list. If
669 any error occurs, the second return value will be None (ie, no way to fetch
670 the value).
671
672 |value|: The deserialized value to convert to base::Value."""
673 if type(value) == bool or type(value) == int:
674 return [], 'base::MakeUnique<base::FundamentalValue>(%s)' %\
675 json.dumps(value)
676 elif type(value) == str:
677 return [], 'base::MakeUnique<base::StringValue>("%s")' % value
678 elif type(value) == list:
679 setup = ['auto default_value = base::MakeUnique<base::ListValue>();']
680 for entry in value:
681 decl, fetch = _GenerateDefaultValue(entry)
682 # Nested lists are not supported.
683 if decl:
684 return [], None
685 setup.append('default_value->Append(%s);' % fetch)
686 return setup, 'std::move(default_value)'
687 return [], None
688
663 def _WritePolicyConstantSource(policies, os, f, riskTags): 689 def _WritePolicyConstantSource(policies, os, f, riskTags):
664 f.write('#include "components/policy/policy_constants.h"\n' 690 f.write('#include "components/policy/policy_constants.h"\n'
665 '\n' 691 '\n'
666 '#include <algorithm>\n' 692 '#include <algorithm>\n'
667 '#include <climits>\n' 693 '#include <climits>\n'
668 '\n' 694 '\n'
669 '#include "base/logging.h"\n' 695 '#include "base/logging.h"\n'
670 '#include "base/memory/ptr_util.h"\n' 696 '#include "base/memory/ptr_util.h"\n'
671 '#include "components/policy/core/common/policy_types.h"\n' 697 '#include "components/policy/core/common/policy_types.h"\n'
672 '#include "components/policy/core/common/schema_internal.h"\n' 698 '#include "components/policy/core/common/schema_internal.h"\n'
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 756
731 f.write('const internal::SchemaData* GetChromeSchemaData() {\n' 757 f.write('const internal::SchemaData* GetChromeSchemaData() {\n'
732 ' return &kChromeSchemaData;\n' 758 ' return &kChromeSchemaData;\n'
733 '}\n\n') 759 '}\n\n')
734 760
735 f.write('#if defined (OS_CHROMEOS)\n' 761 f.write('#if defined (OS_CHROMEOS)\n'
736 'void SetEnterpriseUsersDefaults(PolicyMap* policy_map) {\n') 762 'void SetEnterpriseUsersDefaults(PolicyMap* policy_map) {\n')
737 763
738 for policy in policies: 764 for policy in policies:
739 if policy.has_enterprise_default: 765 if policy.has_enterprise_default:
740 if policy.policy_type == 'Type::BOOLEAN': 766 declare_default_stmts, fetch_default =\
741 creation_expression = 'new base::FundamentalValue(%s)' %\ 767 _GenerateDefaultValue(policy.enterprise_default)
742 ('true' if policy.enterprise_default else 'false') 768 if not fetch_default:
743 elif policy.policy_type == 'Type::INTEGER':
744 creation_expression = 'new base::FundamentalValue(%s)' %\
745 policy.enterprise_default
746 elif policy.policy_type == 'Type::STRING':
747 creation_expression = 'new base::StringValue("%s")' %\
748 policy.enterprise_default
749 else:
750 raise RuntimeError('Type %s of policy %s is not supported at ' 769 raise RuntimeError('Type %s of policy %s is not supported at '
751 'enterprise defaults' % (policy.policy_type, 770 'enterprise defaults' % (policy.policy_type,
752 policy.name)) 771 policy.name))
772
773 # Convert declare_default_stmts to a string with the correct identation.
774 if declare_default_stmts:
775 declare_default = ' %s\n' % '\n '.join(declare_default_stmts)
776 else:
777 declare_default = ''
778
753 f.write(' if (!policy_map->Get(key::k%s)) {\n' 779 f.write(' if (!policy_map->Get(key::k%s)) {\n'
780 '%s'
754 ' policy_map->Set(key::k%s,\n' 781 ' policy_map->Set(key::k%s,\n'
755 ' POLICY_LEVEL_MANDATORY,\n' 782 ' POLICY_LEVEL_MANDATORY,\n'
756 ' POLICY_SCOPE_USER,\n' 783 ' POLICY_SCOPE_USER,\n'
757 ' POLICY_SOURCE_ENTERPRISE_DEFAULT,\n' 784 ' POLICY_SOURCE_ENTERPRISE_DEFAULT,\n'
758 ' base::WrapUnique(%s),\n' 785 ' %s,\n'
759 ' NULL);\n' 786 ' nullptr);\n'
760 ' }\n' % (policy.name, policy.name, creation_expression)) 787 ' }\n' % (policy.name, declare_default, policy.name,
788 fetch_default))
761 789
762 f.write('}\n' 790 f.write('}\n'
763 '#endif\n\n') 791 '#endif\n\n')
764 792
765 f.write('const PolicyDetails* GetChromePolicyDetails(' 793 f.write('const PolicyDetails* GetChromePolicyDetails('
766 'const std::string& policy) {\n' 794 'const std::string& policy) {\n'
767 ' // First index in kPropertyNodes of the Chrome policies.\n' 795 ' // First index in kPropertyNodes of the Chrome policies.\n'
768 ' static const int begin_index = %s;\n' 796 ' static const int begin_index = %s;\n'
769 ' // One-past-the-end of the Chrome policies in kPropertyNodes.\n' 797 ' // One-past-the-end of the Chrome policies in kPropertyNodes.\n'
770 ' static const int end_index = %s;\n' % 798 ' static const int end_index = %s;\n' %
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 f.write('<restrictions xmlns:android="' 1200 f.write('<restrictions xmlns:android="'
1173 'http://schemas.android.com/apk/res/android">\n\n') 1201 'http://schemas.android.com/apk/res/android">\n\n')
1174 for policy in policies: 1202 for policy in policies:
1175 if (policy.is_supported and policy.restriction_type != 'invalid' and 1203 if (policy.is_supported and policy.restriction_type != 'invalid' and
1176 not policy.is_deprecated and not policy.is_future): 1204 not policy.is_deprecated and not policy.is_future):
1177 WriteAppRestriction(policy) 1205 WriteAppRestriction(policy)
1178 f.write('</restrictions>') 1206 f.write('</restrictions>')
1179 1207
1180 if __name__ == '__main__': 1208 if __name__ == '__main__':
1181 sys.exit(main()) 1209 sys.exit(main())
OLDNEW
« no previous file with comments | « components/policy/resources/policy_templates.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698