| 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 09c8791abce0fb2d8a53afa1d9a3a6ad66e73454..89987001f5a4281a4016c3473bab997606f3fe5d 100755
|
| --- a/chrome/tools/build/generate_policy_source.py
|
| +++ b/chrome/tools/build/generate_policy_source.py
|
| @@ -25,13 +25,15 @@ 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
|
| # TODO(joaodasilva): refactor the 'dict' type into a more generic 'json' type
|
| # that can also be used to represent lists of other JSON objects.
|
| 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'),
|
| @@ -70,13 +72,14 @@ 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,
|
| PolicyDetails._RemovePlaceholders(policy['desc']).splitlines()))
|
| self.caption = PolicyDetails._RemovePlaceholders(policy['caption'])
|
| + self.max_size = policy.get('max_size', 0)
|
|
|
| items = policy.get('items')
|
| if items is None:
|
| @@ -202,6 +205,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')
|
| @@ -211,14 +215,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'
|
| @@ -245,6 +251,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'
|
| @@ -257,9 +267,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'
|
| @@ -434,7 +445,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"
|
| @@ -479,7 +492,9 @@ base::Value* DecodeJson(const std::string& json) {
|
| return root.release();
|
| }
|
|
|
| -void DecodePolicy(const em::CloudPolicySettings& policy, PolicyMap* map) {
|
| +void DecodePolicy(const em::CloudPolicySettings& policy,
|
| + base::WeakPtr<CloudExternalDataManager> external_data_manager,
|
| + PolicyMap* map) {
|
| '''
|
|
|
|
|
| @@ -498,12 +513,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 'DecodeJson(%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
|
| @@ -530,10 +551,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')
|
|
|