Chromium Code Reviews| Index: chrome/tools/build/generate_policy_source.py |
| diff --git a/chrome/tools/build/generate_policy_source.py b/chrome/tools/build/generate_policy_source.py |
| index 3ad6d57fc0d133f8108145f08b70f399e150bff3..b006c88689b8ddccb79333b9de9fb612e01d9d9e 100755 |
| --- a/chrome/tools/build/generate_policy_source.py |
| +++ b/chrome/tools/build/generate_policy_source.py |
| @@ -25,11 +25,13 @@ class PolicyDetails: |
| """Parses a policy template and caches all its details.""" |
| # Maps policy types to a tuple with 3 other types: |
| - # - the equivalent base::Value::Type |
| + # - the equivalent base::Value::Type or 'TYPE_EXTERNAL' if the policy |
| + # references external data |
| # - the equivalent Protobuf field type |
| # - the name of one of the protobufs for shared policy types |
| TYPE_MAP = { |
| 'dict': ('TYPE_DICTIONARY', 'string', 'String'), |
| + 'external': ('TYPE_EXTERNAL', 'string', 'String'), |
| 'int': ('TYPE_INTEGER', 'int64', 'Integer'), |
| 'int-enum': ('TYPE_INTEGER', 'int64', 'Integer'), |
| 'list': ('TYPE_LIST', 'StringList', 'StringList'), |
| @@ -63,12 +65,13 @@ class PolicyDetails: |
| if not PolicyDetails.TYPE_MAP.has_key(policy['type']): |
| raise NotImplementedError('Unknown policy type for %s: %s' % |
| (policy['name'], policy['type'])) |
| - self.value_type, self.protobuf_type, self.policy_protobuf_type = \ |
| + self.policy_type, self.protobuf_type, self.policy_protobuf_type = \ |
| PolicyDetails.TYPE_MAP[policy['type']] |
| self.desc = '\n'.join( |
| map(str.strip, self._RemovePlaceholders(policy['desc']).splitlines())) |
| self.caption = self._RemovePlaceholders(policy['caption']) |
| + self.max_size = policy.get('max_size', 0) |
|
Joao da Silva
2013/07/19 11:15:15
Document "max_size" in the template
bartfab (slow)
2013/07/19 13:06:30
Done.
|
| PH_PATTERN = re.compile('<ph[^>]*>([^<]*|[^<]*<ex>([^<]*)</ex>[^<]*)</ph>') |
| @@ -187,6 +190,7 @@ def _WritePolicyConstantHeader(policies, os, f): |
| '\n' |
| '#include <string>\n' |
| '\n' |
| + '#include "base/basictypes.h"\n' |
| '#include "base/values.h"\n' |
| '\n' |
| 'namespace policy {\n\n') |
| @@ -196,14 +200,16 @@ def _WritePolicyConstantHeader(policies, os, f): |
| 'configuration resides.\n' |
| 'extern const wchar_t kRegistryChromePolicyKey[];\n') |
| - f.write('// Lists policy types mapped to their names and expected types.\n' |
| - '// Used to initialize ConfigurationPolicyProviders.\n' |
| + f.write('// Lists metadata such as name, expected type and id for all\n' |
| + '// policies. Used to initialize ConfigurationPolicyProviders and\n' |
| + '// CloudExternalDataManagers.\n' |
| 'struct PolicyDefinitionList {\n' |
| ' struct Entry {\n' |
| ' const char* name;\n' |
| ' base::Value::Type value_type;\n' |
| ' bool device_policy;\n' |
| ' int id;\n' |
| + ' size_t max_external_data_size;\n' |
| ' };\n' |
| '\n' |
| ' const Entry* begin;\n' |
| @@ -230,6 +236,10 @@ def _WritePolicyConstantHeader(policies, os, f): |
| #------------------ policy constants source ------------------------# |
| +def _GetValueType(policy_type): |
| + return policy_type if policy_type != 'TYPE_EXTERNAL' else 'TYPE_DICTIONARY' |
| + |
| + |
| def _WritePolicyConstantSource(policies, os, f): |
| f.write('#include "base/basictypes.h"\n' |
| '#include "base/logging.h"\n' |
| @@ -242,9 +252,10 @@ def _WritePolicyConstantSource(policies, os, f): |
| f.write('const PolicyDefinitionList::Entry kEntries[] = {\n') |
| for policy in policies: |
| if policy.is_supported: |
| - f.write(' { key::k%s, base::Value::%s, %s, %s },\n' % |
| - (policy.name, policy.value_type, |
| - 'true' if policy.is_device_only else 'false', policy.id)) |
| + f.write(' { key::k%s, base::Value::%s, %s, %s, %s },\n' % |
| + (policy.name, _GetValueType(policy.policy_type), |
| + 'true' if policy.is_device_only else 'false', policy.id, |
| + policy.max_size)) |
| f.write('};\n\n') |
| f.write('const PolicyDefinitionList kChromePolicyList = {\n' |
| @@ -415,7 +426,9 @@ CPP_HEAD = ''' |
| #include "base/json/json_reader.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "base/values.h" |
| +#include "chrome/browser/policy/cloud/cloud_external_data_manager.h" |
| #include "chrome/browser/policy/external_data_fetcher.h" |
| #include "chrome/browser/policy/policy_map.h" |
| #include "policy/policy_constants.h" |
| @@ -462,7 +475,9 @@ base::DictionaryValue* DecodeDictionaryValue(const std::string& json) { |
| return dict; |
| } |
| -void DecodePolicy(const em::CloudPolicySettings& policy, PolicyMap* map) { |
| +void DecodePolicy(const em::CloudPolicySettings& policy, |
| + base::WeakPtr<CloudExternalDataManager> external_data_manager, |
| + PolicyMap* map) { |
| ''' |
| @@ -481,12 +496,18 @@ def _CreateValue(type, arg): |
| return 'base::Value::CreateStringValue(%s)' % arg |
| elif type == 'TYPE_LIST': |
| return 'DecodeStringList(%s)' % arg |
| - elif type == 'TYPE_DICTIONARY': |
| + elif type == 'TYPE_DICTIONARY' or type == 'TYPE_EXTERNAL': |
| return 'DecodeDictionaryValue(%s)' % arg |
| else: |
| raise NotImplementedError('Unknown type %s' % type) |
| +def _CreateExternalDataFetcher(type, name): |
| + if type == 'TYPE_EXTERNAL': |
| + return 'new ExternalDataFetcher(external_data_manager, key::k%s)' % name |
| + return 'NULL' |
| + |
| + |
| def _WritePolicyCode(f, policy): |
| membername = policy.name.lower() |
| proto_type = '%sPolicyProto' % policy.policy_protobuf_type |
| @@ -513,10 +534,12 @@ def _WritePolicyCode(f, policy): |
| ' }\n' |
| ' if (do_set) {\n') |
| f.write(' base::Value* value = %s;\n' % |
| - (_CreateValue(policy.value_type, 'policy_proto.value()'))) |
| + (_CreateValue(policy.policy_type, 'policy_proto.value()'))) |
| + f.write(' ExternalDataFetcher* external_data_fetcher = %s;\n' % |
| + _CreateExternalDataFetcher(policy.policy_type, policy.name)) |
| f.write(' map->Set(key::k%s, level, POLICY_SCOPE_USER,\n' % |
| policy.name) |
| - f.write(' value, NULL);\n') |
| + f.write(' value, external_data_fetcher);\n') |
| f.write(' }\n' |
| ' }\n' |
| ' }\n') |