1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/sync/js_arg_list.h" 6 7 #include "base/json/json_writer.h" 8 #include "base/memory/scoped_ptr.h" 9 10 namespace browser_sync { 11 JsArgList()12JsArgList::JsArgList() : args_(new SharedListValue()) {} 13 JsArgList(const ListValue & args)14JsArgList::JsArgList(const ListValue& args) 15 : args_(new SharedListValue(args)) {} 16 JsArgList(const std::vector<const Value * > & args)17JsArgList::JsArgList(const std::vector<const Value*>& args) 18 : args_(new SharedListValue(args)) {} 19 ~JsArgList()20JsArgList::~JsArgList() {} 21 Get() const22const ListValue& JsArgList::Get() const { 23 return args_->Get(); 24 } 25 ToString() const26std::string JsArgList::ToString() const { 27 std::string str; 28 base::JSONWriter::Write(&Get(), false, &str); 29 return str; 30 } 31 SharedListValue()32JsArgList::SharedListValue::SharedListValue() {} 33 SharedListValue(const ListValue & list_value)34JsArgList::SharedListValue::SharedListValue(const ListValue& list_value) { 35 // Go through contortions to copy the list since ListValues are not 36 // copyable. 37 scoped_ptr<ListValue> list_value_copy(list_value.DeepCopy()); 38 list_value_.Swap(list_value_copy.get()); 39 } 40 SharedListValue(const std::vector<const Value * > & value_list)41JsArgList::SharedListValue::SharedListValue( 42 const std::vector<const Value*>& value_list) { 43 for (std::vector<const Value*>::const_iterator it = value_list.begin(); 44 it != value_list.end(); ++it) { 45 list_value_.Append((*it)->DeepCopy()); 46 } 47 } 48 Get() const49const ListValue& JsArgList::SharedListValue::Get() const { 50 return list_value_; 51 } 52 ~SharedListValue()53JsArgList::SharedListValue::~SharedListValue() {} 54 55 } // namespace browser_sync 56