| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 '#include "base/logging.h"\n' | 237 '#include "base/logging.h"\n' |
| 238 '#include "policy/policy_constants.h"\n' | 238 '#include "policy/policy_constants.h"\n' |
| 239 '\n' | 239 '\n' |
| 240 'namespace policy {\n\n') | 240 'namespace policy {\n\n') |
| 241 | 241 |
| 242 f.write('namespace {\n\n') | 242 f.write('namespace {\n\n') |
| 243 | 243 |
| 244 f.write('const PolicyDefinitionList::Entry kEntries[] = {\n') | 244 f.write('const PolicyDefinitionList::Entry kEntries[] = {\n') |
| 245 for policy in policies: | 245 for policy in policies: |
| 246 if policy.is_supported: | 246 if policy.is_supported: |
| 247 f.write(' { key::k%s, Value::%s, %s, %s },\n' % | 247 f.write(' { key::k%s, base::Value::%s, %s, %s },\n' % |
| 248 (policy.name, policy.value_type, | 248 (policy.name, policy.value_type, |
| 249 'true' if policy.is_device_only else 'false', policy.id)) | 249 'true' if policy.is_device_only else 'false', policy.id)) |
| 250 f.write('};\n\n') | 250 f.write('};\n\n') |
| 251 | 251 |
| 252 f.write('const PolicyDefinitionList kChromePolicyList = {\n' | 252 f.write('const PolicyDefinitionList kChromePolicyList = {\n' |
| 253 ' kEntries,\n' | 253 ' kEntries,\n' |
| 254 ' kEntries + arraysize(kEntries),\n' | 254 ' kEntries + arraysize(kEntries),\n' |
| 255 '};\n\n') | 255 '};\n\n') |
| 256 | 256 |
| 257 has_deprecated_policies = any( | 257 has_deprecated_policies = any( |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 #include "chrome/browser/policy/policy_map.h" | 417 #include "chrome/browser/policy/policy_map.h" |
| 418 #include "policy/policy_constants.h" | 418 #include "policy/policy_constants.h" |
| 419 #include "policy/proto/cloud_policy.pb.h" | 419 #include "policy/proto/cloud_policy.pb.h" |
| 420 | 420 |
| 421 using google::protobuf::RepeatedPtrField; | 421 using google::protobuf::RepeatedPtrField; |
| 422 | 422 |
| 423 namespace policy { | 423 namespace policy { |
| 424 | 424 |
| 425 namespace em = enterprise_management; | 425 namespace em = enterprise_management; |
| 426 | 426 |
| 427 Value* DecodeIntegerValue(google::protobuf::int64 value) { | 427 base::Value* DecodeIntegerValue(google::protobuf::int64 value) { |
| 428 if (value < std::numeric_limits<int>::min() || | 428 if (value < std::numeric_limits<int>::min() || |
| 429 value > std::numeric_limits<int>::max()) { | 429 value > std::numeric_limits<int>::max()) { |
| 430 LOG(WARNING) << "Integer value " << value | 430 LOG(WARNING) << "Integer value " << value |
| 431 << " out of numeric limits, ignoring."; | 431 << " out of numeric limits, ignoring."; |
| 432 return NULL; | 432 return NULL; |
| 433 } | 433 } |
| 434 | 434 |
| 435 return Value::CreateIntegerValue(static_cast<int>(value)); | 435 return base::Value::CreateIntegerValue(static_cast<int>(value)); |
| 436 } | 436 } |
| 437 | 437 |
| 438 ListValue* DecodeStringList(const em::StringList& string_list) { | 438 base::ListValue* DecodeStringList(const em::StringList& string_list) { |
| 439 ListValue* list_value = new ListValue; | 439 base::ListValue* list_value = new base::ListValue; |
| 440 RepeatedPtrField<std::string>::const_iterator entry; | 440 RepeatedPtrField<std::string>::const_iterator entry; |
| 441 for (entry = string_list.entries().begin(); | 441 for (entry = string_list.entries().begin(); |
| 442 entry != string_list.entries().end(); ++entry) { | 442 entry != string_list.entries().end(); ++entry) { |
| 443 list_value->Append(Value::CreateStringValue(*entry)); | 443 list_value->Append(base::Value::CreateStringValue(*entry)); |
| 444 } | 444 } |
| 445 return list_value; | 445 return list_value; |
| 446 } | 446 } |
| 447 | 447 |
| 448 void DecodePolicy(const em::CloudPolicySettings& policy, PolicyMap* map) { | 448 void DecodePolicy(const em::CloudPolicySettings& policy, PolicyMap* map) { |
| 449 ''' | 449 ''' |
| 450 | 450 |
| 451 | 451 |
| 452 CPP_FOOT = '''} | 452 CPP_FOOT = '''} |
| 453 | 453 |
| 454 } // namespace policy | 454 } // namespace policy |
| 455 ''' | 455 ''' |
| 456 | 456 |
| 457 | 457 |
| 458 def _CreateValue(type, arg): | 458 def _CreateValue(type, arg): |
| 459 if type == 'TYPE_BOOLEAN': | 459 if type == 'TYPE_BOOLEAN': |
| 460 return 'Value::CreateBooleanValue(%s)' % arg | 460 return 'base::Value::CreateBooleanValue(%s)' % arg |
| 461 elif type == 'TYPE_INTEGER': | 461 elif type == 'TYPE_INTEGER': |
| 462 return 'DecodeIntegerValue(%s)' % arg | 462 return 'DecodeIntegerValue(%s)' % arg |
| 463 elif type == 'TYPE_STRING': | 463 elif type == 'TYPE_STRING': |
| 464 return 'Value::CreateStringValue(%s)' % arg | 464 return 'base::Value::CreateStringValue(%s)' % arg |
| 465 elif type == 'TYPE_LIST': | 465 elif type == 'TYPE_LIST': |
| 466 return 'DecodeStringList(%s)' % arg | 466 return 'DecodeStringList(%s)' % arg |
| 467 elif type == 'TYPE_DICTIONARY': | 467 elif type == 'TYPE_DICTIONARY': |
| 468 # TODO(joaodasilva): decode 'dict' types. http://crbug.com/108997 | 468 # TODO(joaodasilva): decode 'dict' types. http://crbug.com/108997 |
| 469 return 'new DictionaryValue()' | 469 return 'new base::DictionaryValue()' |
| 470 else: | 470 else: |
| 471 raise NotImplementedError('Unknown type %s' % type) | 471 raise NotImplementedError('Unknown type %s' % type) |
| 472 | 472 |
| 473 | 473 |
| 474 def _WritePolicyCode(f, policy): | 474 def _WritePolicyCode(f, policy): |
| 475 membername = policy.name.lower() | 475 membername = policy.name.lower() |
| 476 proto_type = '%sPolicyProto' % policy.policy_protobuf_type | 476 proto_type = '%sPolicyProto' % policy.policy_protobuf_type |
| 477 f.write(' if (policy.has_%s()) {\n' % membername) | 477 f.write(' if (policy.has_%s()) {\n' % membername) |
| 478 f.write(' const em::%s& policy_proto = policy.%s();\n' % | 478 f.write(' const em::%s& policy_proto = policy.%s();\n' % |
| 479 (proto_type, membername)) | 479 (proto_type, membername)) |
| 480 f.write(' if (policy_proto.has_value()) {\n') | 480 f.write(' if (policy_proto.has_value()) {\n') |
| 481 f.write(' PolicyLevel level = POLICY_LEVEL_MANDATORY;\n' | 481 f.write(' PolicyLevel level = POLICY_LEVEL_MANDATORY;\n' |
| 482 ' bool do_set = true;\n' | 482 ' bool do_set = true;\n' |
| 483 ' if (policy_proto.has_policy_options()) {\n' | 483 ' if (policy_proto.has_policy_options()) {\n' |
| 484 ' do_set = false;\n' | 484 ' do_set = false;\n' |
| 485 ' switch(policy_proto.policy_options().mode()) {\n' | 485 ' switch(policy_proto.policy_options().mode()) {\n' |
| 486 ' case em::PolicyOptions::MANDATORY:\n' | 486 ' case em::PolicyOptions::MANDATORY:\n' |
| 487 ' do_set = true;\n' | 487 ' do_set = true;\n' |
| 488 ' level = POLICY_LEVEL_MANDATORY;\n' | 488 ' level = POLICY_LEVEL_MANDATORY;\n' |
| 489 ' break;\n' | 489 ' break;\n' |
| 490 ' case em::PolicyOptions::RECOMMENDED:\n' | 490 ' case em::PolicyOptions::RECOMMENDED:\n' |
| 491 ' do_set = true;\n' | 491 ' do_set = true;\n' |
| 492 ' level = POLICY_LEVEL_RECOMMENDED;\n' | 492 ' level = POLICY_LEVEL_RECOMMENDED;\n' |
| 493 ' break;\n' | 493 ' break;\n' |
| 494 ' case em::PolicyOptions::UNSET:\n' | 494 ' case em::PolicyOptions::UNSET:\n' |
| 495 ' break;\n' | 495 ' break;\n' |
| 496 ' }\n' | 496 ' }\n' |
| 497 ' }\n' | 497 ' }\n' |
| 498 ' if (do_set) {\n') | 498 ' if (do_set) {\n') |
| 499 f.write(' Value* value = %s;\n' % | 499 f.write(' base::Value* value = %s;\n' % |
| 500 (_CreateValue(policy.value_type, 'policy_proto.value()'))) | 500 (_CreateValue(policy.value_type, 'policy_proto.value()'))) |
| 501 f.write(' map->Set(key::k%s, level, POLICY_SCOPE_USER, value);\n' % | 501 f.write(' map->Set(key::k%s, level, POLICY_SCOPE_USER, value);\n' % |
| 502 policy.name) | 502 policy.name) |
| 503 f.write(' }\n' | 503 f.write(' }\n' |
| 504 ' }\n' | 504 ' }\n' |
| 505 ' }\n') | 505 ' }\n') |
| 506 | 506 |
| 507 | 507 |
| 508 def _WriteCloudPolicyDecoder(policies, os, f): | 508 def _WriteCloudPolicyDecoder(policies, os, f): |
| 509 f.write(CPP_HEAD) | 509 f.write(CPP_HEAD) |
| 510 for policy in policies: | 510 for policy in policies: |
| 511 if policy.is_supported and not policy.is_device_only: | 511 if policy.is_supported and not policy.is_device_only: |
| 512 _WritePolicyCode(f, policy) | 512 _WritePolicyCode(f, policy) |
| 513 f.write(CPP_FOOT) | 513 f.write(CPP_FOOT) |
| 514 | 514 |
| 515 | 515 |
| 516 if __name__ == '__main__': | 516 if __name__ == '__main__': |
| 517 sys.exit(main()) | 517 sys.exit(main()) |
| OLD | NEW |