| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 template | 6 '''python %prog [options] platform 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 template is the path to a .json policy template file.''' | 10 template is the path to a .json policy template file.''' |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 namespace em = enterprise_management; | 245 namespace em = enterprise_management; |
| 246 | 246 |
| 247 Value* DecodeIntegerValue(google::protobuf::int64 value) { | 247 Value* DecodeIntegerValue(google::protobuf::int64 value) { |
| 248 if (value < std::numeric_limits<int>::min() || | 248 if (value < std::numeric_limits<int>::min() || |
| 249 value > std::numeric_limits<int>::max()) { | 249 value > std::numeric_limits<int>::max()) { |
| 250 LOG(WARNING) << "Integer value " << value | 250 LOG(WARNING) << "Integer value " << value |
| 251 << " out of numeric limits, ignoring."; | 251 << " out of numeric limits, ignoring."; |
| 252 return NULL; | 252 return NULL; |
| 253 } | 253 } |
| 254 | 254 |
| 255 return Value::CreateIntegerValue(static_cast<int>(value)); | 255 return base::NumberValue::New(static_cast<int>(value)); |
| 256 } | 256 } |
| 257 | 257 |
| 258 ListValue* DecodeStringList(const em::StringList& string_list) { | 258 ListValue* DecodeStringList(const em::StringList& string_list) { |
| 259 ListValue* list_value = new ListValue; | 259 ListValue* list_value = new ListValue; |
| 260 RepeatedPtrField<std::string>::const_iterator entry; | 260 RepeatedPtrField<std::string>::const_iterator entry; |
| 261 for (entry = string_list.entries().begin(); | 261 for (entry = string_list.entries().begin(); |
| 262 entry != string_list.entries().end(); ++entry) { | 262 entry != string_list.entries().end(); ++entry) { |
| 263 list_value->Append(Value::CreateStringValue(*entry)); | 263 list_value->Append(base::StringValue::New(*entry)); |
| 264 } | 264 } |
| 265 return list_value; | 265 return list_value; |
| 266 } | 266 } |
| 267 | 267 |
| 268 void DecodePolicy(const em::CloudPolicySettings& policy, | 268 void DecodePolicy(const em::CloudPolicySettings& policy, |
| 269 PolicyMap* mandatory, PolicyMap* recommended) { | 269 PolicyMap* mandatory, PolicyMap* recommended) { |
| 270 DCHECK(mandatory); | 270 DCHECK(mandatory); |
| 271 DCHECK(recommended); | 271 DCHECK(recommended); |
| 272 ''' | 272 ''' |
| 273 | 273 |
| 274 | 274 |
| 275 CPP_FOOT = '''} | 275 CPP_FOOT = '''} |
| 276 | 276 |
| 277 } // namespace policy | 277 } // namespace policy |
| 278 ''' | 278 ''' |
| 279 | 279 |
| 280 | 280 |
| 281 def _CreateValue(type): | 281 def _CreateValue(type): |
| 282 if type == 'main': | 282 if type == 'main': |
| 283 return "Value::CreateBooleanValue" | 283 return "base::BooleanValue::New" |
| 284 elif type in ('int', 'int-enum'): | 284 elif type in ('int', 'int-enum'): |
| 285 return "DecodeIntegerValue" | 285 return "DecodeIntegerValue" |
| 286 elif type in ('string', 'string-enum'): | 286 elif type in ('string', 'string-enum'): |
| 287 return "Value::CreateStringValue" | 287 return "base::StringValue::New" |
| 288 elif type == 'list': | 288 elif type == 'list': |
| 289 return "DecodeStringList" | 289 return "DecodeStringList" |
| 290 else: | 290 else: |
| 291 raise NotImplementedError() | 291 raise NotImplementedError() |
| 292 | 292 |
| 293 | 293 |
| 294 def _WritePolicyCode(file, policy): | 294 def _WritePolicyCode(file, policy): |
| 295 if policy.get('device_only', False): | 295 if policy.get('device_only', False): |
| 296 return | 296 return |
| 297 membername = policy['name'].lower() | 297 membername = policy['name'].lower() |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 for sub_policy in policy['policies']: | 329 for sub_policy in policy['policies']: |
| 330 _WritePolicyCode(f, sub_policy) | 330 _WritePolicyCode(f, sub_policy) |
| 331 else: | 331 else: |
| 332 _WritePolicyCode(f, policy) | 332 _WritePolicyCode(f, policy) |
| 333 f.write(CPP_FOOT) | 333 f.write(CPP_FOOT) |
| 334 | 334 |
| 335 | 335 |
| 336 #------------------ main() -----------------------------------------# | 336 #------------------ main() -----------------------------------------# |
| 337 if __name__ == '__main__': | 337 if __name__ == '__main__': |
| 338 main(); | 338 main(); |
| OLD | NEW |