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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 291 |
292 | 292 |
293 #------------------ policy constants header ------------------------# | 293 #------------------ policy constants header ------------------------# |
294 | 294 |
295 def _WritePolicyConstantHeader(policies, os, f, riskTags): | 295 def _WritePolicyConstantHeader(policies, os, f, riskTags): |
296 f.write('#ifndef CHROME_COMMON_POLICY_CONSTANTS_H_\n' | 296 f.write('#ifndef CHROME_COMMON_POLICY_CONSTANTS_H_\n' |
297 '#define CHROME_COMMON_POLICY_CONSTANTS_H_\n' | 297 '#define CHROME_COMMON_POLICY_CONSTANTS_H_\n' |
298 '\n' | 298 '\n' |
299 '#include <string>\n' | 299 '#include <string>\n' |
300 '\n' | 300 '\n' |
301 '#include "base/basictypes.h"\n' | |
302 '#include "base/values.h"\n' | 301 '#include "base/values.h"\n' |
303 '#include "components/policy/core/common/policy_details.h"\n' | 302 '#include "components/policy/core/common/policy_details.h"\n' |
304 '#include "components/policy/core/common/policy_map.h"\n' | 303 '#include "components/policy/core/common/policy_map.h"\n' |
305 '\n' | 304 '\n' |
306 'namespace policy {\n' | 305 'namespace policy {\n' |
307 '\n' | 306 '\n' |
308 'namespace internal {\n' | 307 'namespace internal {\n' |
309 'struct SchemaData;\n' | 308 'struct SchemaData;\n' |
310 '}\n\n') | 309 '}\n\n') |
311 | 310 |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 raise RuntimeError('Tag ' + tag['name'] + ' has no description!') | 850 raise RuntimeError('Tag ' + tag['name'] + ' has no description!') |
852 if tag.get('user-description', None) == None: | 851 if tag.get('user-description', None) == None: |
853 raise RuntimeError('Tag ' + tag['name'] + ' has no user-description!') | 852 raise RuntimeError('Tag ' + tag['name'] + ' has no user-description!') |
854 self.enum_for_tag[tag['name']] = "RISK_TAG_" + \ | 853 self.enum_for_tag[tag['name']] = "RISK_TAG_" + \ |
855 tag['name'].replace("-","_").upper() | 854 tag['name'].replace("-","_").upper() |
856 | 855 |
857 def _WritePolicyRiskTagHeader(policies, os, f, riskTags): | 856 def _WritePolicyRiskTagHeader(policies, os, f, riskTags): |
858 f.write('#ifndef CHROME_COMMON_POLICY_RISK_TAG_H_\n' | 857 f.write('#ifndef CHROME_COMMON_POLICY_RISK_TAG_H_\n' |
859 '#define CHROME_COMMON_POLICY_RISK_TAG_H_\n' | 858 '#define CHROME_COMMON_POLICY_RISK_TAG_H_\n' |
860 '\n' | 859 '\n' |
861 '#include "base/basictypes.h"\n' | 860 '#include <stddef.h>\n' |
862 '\n' | 861 '\n' |
863 'namespace policy {\n' | 862 'namespace policy {\n' |
864 '\n' + \ | 863 '\n' + \ |
865 '// The tag of a policy indicates which impact a policy can have on\n' | 864 '// The tag of a policy indicates which impact a policy can have on\n' |
866 '// a user\'s privacy and/or security. Ordered descending by \n' | 865 '// a user\'s privacy and/or security. Ordered descending by \n' |
867 '// impact.\n' | 866 '// impact.\n' |
868 '// The explanation of the single tags is stated in\n' | 867 '// The explanation of the single tags is stated in\n' |
869 '// policy_templates.json within the \'risk_tag_definitions\' tag.' | 868 '// policy_templates.json within the \'risk_tag_definitions\' tag.' |
870 '\n' + riskTags.GenerateEnum() + '\n' | 869 '\n' + riskTags.GenerateEnum() + '\n' |
871 '// This constant describes how many risk tags were used by the\n' | 870 '// This constant describes how many risk tags were used by the\n' |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 policy.id + RESERVED_IDS)) | 992 policy.id + RESERVED_IDS)) |
994 f.write('}\n\n') | 993 f.write('}\n\n') |
995 | 994 |
996 | 995 |
997 #------------------ protobuf decoder -------------------------------# | 996 #------------------ protobuf decoder -------------------------------# |
998 | 997 |
999 CPP_HEAD = ''' | 998 CPP_HEAD = ''' |
1000 #include <limits> | 999 #include <limits> |
1001 #include <string> | 1000 #include <string> |
1002 | 1001 |
1003 #include "base/basictypes.h" | |
1004 #include "base/callback.h" | 1002 #include "base/callback.h" |
1005 #include "base/json/json_reader.h" | 1003 #include "base/json/json_reader.h" |
1006 #include "base/logging.h" | 1004 #include "base/logging.h" |
1007 #include "base/memory/scoped_ptr.h" | 1005 #include "base/memory/scoped_ptr.h" |
1008 #include "base/memory/weak_ptr.h" | 1006 #include "base/memory/weak_ptr.h" |
1009 #include "base/values.h" | 1007 #include "base/values.h" |
1010 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" | 1008 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" |
1011 #include "components/policy/core/common/external_data_fetcher.h" | 1009 #include "components/policy/core/common/external_data_fetcher.h" |
1012 #include "components/policy/core/common/policy_map.h" | 1010 #include "components/policy/core/common/policy_map.h" |
1013 #include "components/policy/core/common/policy_types.h" | 1011 #include "components/policy/core/common/policy_types.h" |
1014 #include "policy/policy_constants.h" | 1012 #include "policy/policy_constants.h" |
1015 #include "policy/proto/cloud_policy.pb.h" | 1013 #include "policy/proto/cloud_policy.pb.h" |
1016 | 1014 |
1017 using google::protobuf::RepeatedPtrField; | 1015 using google::protobuf::RepeatedPtrField; |
1018 | 1016 |
1019 namespace policy { | 1017 namespace policy { |
1020 | 1018 |
1021 namespace em = enterprise_management; | 1019 namespace em = enterprise_management; |
1022 | 1020 |
1023 base::Value* DecodeIntegerValue(google::protobuf::int64 value) { | 1021 base::Value* DecodeIntegerValue(google::protobuf::int64 value) { |
1024 if (value < std::numeric_limits<int>::min() || | 1022 if (value < std::numeric_limits<int>::min() || |
1025 value > std::numeric_limits<int>::max()) { | 1023 value > std::numeric_limits<int>::max()) { |
1026 LOG(WARNING) << "Integer value " << value | 1024 LOG(WARNING) << "Integer value " << value |
1027 << " out of numeric limits, ignoring."; | 1025 << " out of numeric limits, ignoring."; |
1028 return NULL; | 1026 return nullptr; |
1029 } | 1027 } |
1030 | 1028 |
1031 return new base::FundamentalValue(static_cast<int>(value)); | 1029 return new base::FundamentalValue(static_cast<int>(value)); |
1032 } | 1030 } |
1033 | 1031 |
1034 base::ListValue* DecodeStringList(const em::StringList& string_list) { | 1032 base::ListValue* DecodeStringList(const em::StringList& string_list) { |
1035 base::ListValue* list_value = new base::ListValue; | 1033 base::ListValue* list_value = new base::ListValue; |
1036 RepeatedPtrField<std::string>::const_iterator entry; | 1034 RepeatedPtrField<std::string>::const_iterator entry; |
1037 for (entry = string_list.entries().begin(); | 1035 for (entry = string_list.entries().begin(); |
1038 entry != string_list.entries().end(); ++entry) { | 1036 entry != string_list.entries().end(); ++entry) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 # _WriteAppRestrictions body | 1161 # _WriteAppRestrictions body |
1164 f.write('<restrictions xmlns:android="' | 1162 f.write('<restrictions xmlns:android="' |
1165 'http://schemas.android.com/apk/res/android">\n\n') | 1163 'http://schemas.android.com/apk/res/android">\n\n') |
1166 for policy in policies: | 1164 for policy in policies: |
1167 if policy.is_supported and policy.restriction_type != 'invalid': | 1165 if policy.is_supported and policy.restriction_type != 'invalid': |
1168 WriteAppRestriction(policy) | 1166 WriteAppRestriction(policy) |
1169 f.write('</restrictions>') | 1167 f.write('</restrictions>') |
1170 | 1168 |
1171 if __name__ == '__main__': | 1169 if __name__ == '__main__': |
1172 sys.exit(main()) | 1170 sys.exit(main()) |
OLD | NEW |