Index: components/framelet/common/value_type_converters.cc |
diff --git a/components/framelet/common/value_type_converters.cc b/components/framelet/common/value_type_converters.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ef4d12a92c1d03959d9388e163e9f36e7333f2d5 |
--- /dev/null |
+++ b/components/framelet/common/value_type_converters.cc |
@@ -0,0 +1,77 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/framelet/common/value_type_converters.h" |
+ |
+#include "components/framelet/common/framelet.mojom.h" |
+ |
+using namespace framelet::mojom; |
+ |
+namespace mojo { |
+ |
+// static |
+int TypeConverter<int, ValuePtr>::Convert(const ValuePtr& input) { |
+ if (input->type == ValueType::INTEGER) |
+ return input->integer_value->value; |
+ return 0; |
+} |
+ |
+// static |
+ValuePtr TypeConverter<ValuePtr, int>::Convert(int input) { |
+ ValuePtr value(Value::New()); |
+ value->type = ValueType::INTEGER; |
+ value->integer_value = IntegerValue::New(); |
+ value->integer_value->value = input; |
+ return value; |
+} |
+ |
+// static |
+bool TypeConverter<bool, ValuePtr>::Convert(const ValuePtr& input) { |
+ if (input->type == ValueType::BOOLEAN) |
+ return input->boolean_value->value; |
+ return false; |
+} |
+ |
+// static |
+ValuePtr TypeConverter<ValuePtr, bool>::Convert(bool input) { |
+ ValuePtr value(Value::New()); |
+ value->type = ValueType::BOOLEAN; |
+ value->boolean_value = BooleanValue::New(); |
+ value->boolean_value->value = input; |
+ return value; |
+} |
+ |
+// static |
+ValuePtr TypeConverter<ValuePtr, std::string>::Convert( |
+ const std::string& input) { |
+ ValuePtr value(Value::New()); |
+ value->type = ValueType::STRING; |
+ value->string_value = StringValue::New(); |
+ value->string_value->value = mojo::String::From(input); |
+ return value; |
+} |
+ |
+base::Value* TypeConverter<base::Value*, ValuePtr>::Convert( |
+ const ValuePtr& input) { |
+ base::Value* value = nullptr; |
+ switch (input->type) { |
+ case ValueType::STRING: |
+ value = |
+ new base::StringValue(input->string_value->value.To<std::string>()); |
+ break; |
+ case ValueType::BOOLEAN: |
+ value = new base::FundamentalValue( |
+ static_cast<bool>(input->boolean_value->value)); |
+ break; |
+ case ValueType::INTEGER: |
+ value = new base::FundamentalValue( |
+ static_cast<int>(input->integer_value->value)); |
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
+ return value; |
+} |
+ |
+} // namespace mojo |