Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: components/framelet/common/value_type_converters.cc

Issue 1602663003: Framelet Prototype 2016 using Mojo IPC Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Disabled oilpan Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/framelet/common/value_type_converters.h ('k') | components/framelet/renderer/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « components/framelet/common/value_type_converters.h ('k') | components/framelet/renderer/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698