1*1a96fba6SXin Li // Copyright 2015 The Android Open Source Project 2*1a96fba6SXin Li // 3*1a96fba6SXin Li // Licensed under the Apache License, Version 2.0 (the "License"); 4*1a96fba6SXin Li // you may not use this file except in compliance with the License. 5*1a96fba6SXin Li // You may obtain a copy of the License at 6*1a96fba6SXin Li // 7*1a96fba6SXin Li // http://www.apache.org/licenses/LICENSE-2.0 8*1a96fba6SXin Li // 9*1a96fba6SXin Li // Unless required by applicable law or agreed to in writing, software 10*1a96fba6SXin Li // distributed under the License is distributed on an "AS IS" BASIS, 11*1a96fba6SXin Li // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*1a96fba6SXin Li // See the License for the specific language governing permissions and 13*1a96fba6SXin Li // limitations under the License. 14*1a96fba6SXin Li 15*1a96fba6SXin Li #include <brillo/value_conversion.h> 16*1a96fba6SXin Li 17*1a96fba6SXin Li #include <string> 18*1a96fba6SXin Li #include <vector> 19*1a96fba6SXin Li 20*1a96fba6SXin Li namespace brillo { 21*1a96fba6SXin Li FromValue(const base::Value & in_value,std::unique_ptr<base::ListValue> * out_value)22*1a96fba6SXin Libool FromValue(const base::Value& in_value, 23*1a96fba6SXin Li std::unique_ptr<base::ListValue>* out_value) { 24*1a96fba6SXin Li const base::ListValue* list = nullptr; 25*1a96fba6SXin Li if (!in_value.GetAsList(&list)) 26*1a96fba6SXin Li return false; 27*1a96fba6SXin Li *out_value = list->CreateDeepCopy(); 28*1a96fba6SXin Li return true; 29*1a96fba6SXin Li } 30*1a96fba6SXin Li FromValue(const base::Value & in_value,std::unique_ptr<base::DictionaryValue> * out_value)31*1a96fba6SXin Libool FromValue(const base::Value& in_value, 32*1a96fba6SXin Li std::unique_ptr<base::DictionaryValue>* out_value) { 33*1a96fba6SXin Li const base::DictionaryValue* dict = nullptr; 34*1a96fba6SXin Li if (!in_value.GetAsDictionary(&dict)) 35*1a96fba6SXin Li return false; 36*1a96fba6SXin Li *out_value = dict->CreateDeepCopy(); 37*1a96fba6SXin Li return true; 38*1a96fba6SXin Li } 39*1a96fba6SXin Li ToValue(int value)40*1a96fba6SXin Listd::unique_ptr<base::Value> ToValue(int value) { 41*1a96fba6SXin Li return std::make_unique<base::Value>(value); 42*1a96fba6SXin Li } 43*1a96fba6SXin Li ToValue(bool value)44*1a96fba6SXin Listd::unique_ptr<base::Value> ToValue(bool value) { 45*1a96fba6SXin Li return std::make_unique<base::Value>(value); 46*1a96fba6SXin Li } 47*1a96fba6SXin Li ToValue(double value)48*1a96fba6SXin Listd::unique_ptr<base::Value> ToValue(double value) { 49*1a96fba6SXin Li return std::make_unique<base::Value>(value); 50*1a96fba6SXin Li } 51*1a96fba6SXin Li ToValue(const char * value)52*1a96fba6SXin Listd::unique_ptr<base::Value> ToValue(const char* value) { 53*1a96fba6SXin Li return std::make_unique<base::Value>(value); 54*1a96fba6SXin Li } 55*1a96fba6SXin Li ToValue(const std::string & value)56*1a96fba6SXin Listd::unique_ptr<base::Value> ToValue(const std::string& value) { 57*1a96fba6SXin Li return std::make_unique<base::Value>(value); 58*1a96fba6SXin Li } 59*1a96fba6SXin Li 60*1a96fba6SXin Li } // namespace brillo 61