OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef HEADLESS_PUBLIC_INTERNAL_VALUE_CONVERSIONS_H_ | 5 #ifndef HEADLESS_PUBLIC_INTERNAL_VALUE_CONVERSIONS_H_ |
6 #define HEADLESS_PUBLIC_INTERNAL_VALUE_CONVERSIONS_H_ | 6 #define HEADLESS_PUBLIC_INTERNAL_VALUE_CONVERSIONS_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 const std::vector<T>*) { | 60 const std::vector<T>*) { |
61 std::unique_ptr<base::ListValue> result(new base::ListValue()); | 61 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
62 for (const auto& it : vector) | 62 for (const auto& it : vector) |
63 result->Append(ToValue(it)); | 63 result->Append(ToValue(it)); |
64 return std::move(result); | 64 return std::move(result); |
65 } | 65 } |
66 | 66 |
67 template <typename T> | 67 template <typename T> |
68 std::unique_ptr<base::Value> ToValueImpl(const std::unique_ptr<T>& value, | 68 std::unique_ptr<base::Value> ToValueImpl(const std::unique_ptr<T>& value, |
69 std::unique_ptr<T>*) { | 69 std::unique_ptr<T>*) { |
70 return ToValue(value.get()); | 70 return ToValue(*value); |
71 } | 71 } |
72 | 72 |
73 // FromValue specializations for basic types. | 73 // FromValue specializations for basic types. |
74 template <> | 74 template <> |
75 struct FromValue<bool> { | 75 struct FromValue<bool> { |
76 static bool Parse(const base::Value& value, ErrorReporter* errors) { | 76 static bool Parse(const base::Value& value, ErrorReporter* errors) { |
77 bool result = false; | 77 bool result = false; |
78 if (!value.GetAsBoolean(&result)) | 78 if (!value.GetAsBoolean(&result)) |
79 errors->AddError("boolean value expected"); | 79 errors->AddError("boolean value expected"); |
80 return result; | 80 return result; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 result.push_back(FromValue<T>::Parse(*item, errors)); | 154 result.push_back(FromValue<T>::Parse(*item, errors)); |
155 errors->Pop(); | 155 errors->Pop(); |
156 return result; | 156 return result; |
157 } | 157 } |
158 }; | 158 }; |
159 | 159 |
160 } // namespace internal | 160 } // namespace internal |
161 } // namespace headless | 161 } // namespace headless |
162 | 162 |
163 #endif // HEADLESS_PUBLIC_INTERNAL_VALUE_CONVERSIONS_H_ | 163 #endif // HEADLESS_PUBLIC_INTERNAL_VALUE_CONVERSIONS_H_ |
OLD | NEW |