1 // Copyright 2013 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.
5 #include "extensions/common/value_builder.h"
7 #include "base/json/json_writer.h"
13 DictionaryBuilder::DictionaryBuilder() : dict_(new base::DictionaryValue
) {}
15 DictionaryBuilder::DictionaryBuilder(const base::DictionaryValue
& init
)
16 : dict_(init
.DeepCopy()) {}
18 DictionaryBuilder::~DictionaryBuilder() {}
20 std::string
DictionaryBuilder::ToJSON() const {
22 base::JSONWriter::WriteWithOptions(
23 dict_
.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT
, &json
);
27 DictionaryBuilder
& DictionaryBuilder::Set(const std::string
& path
,
29 dict_
->SetWithoutPathExpansion(path
, new base::FundamentalValue(in_value
));
33 DictionaryBuilder
& DictionaryBuilder::Set(const std::string
& path
,
35 dict_
->SetWithoutPathExpansion(path
, new base::FundamentalValue(in_value
));
39 DictionaryBuilder
& DictionaryBuilder::Set(const std::string
& path
,
40 const std::string
& in_value
) {
41 dict_
->SetWithoutPathExpansion(path
, new base::StringValue(in_value
));
45 DictionaryBuilder
& DictionaryBuilder::Set(const std::string
& path
,
46 const base::string16
& in_value
) {
47 dict_
->SetWithoutPathExpansion(path
, new base::StringValue(in_value
));
51 DictionaryBuilder
& DictionaryBuilder::Set(const std::string
& path
,
52 DictionaryBuilder
& in_value
) {
53 dict_
->SetWithoutPathExpansion(path
, in_value
.Build().release());
57 DictionaryBuilder
& DictionaryBuilder::Set(const std::string
& path
,
58 ListBuilder
& in_value
) {
59 dict_
->SetWithoutPathExpansion(path
, in_value
.Build().release());
63 DictionaryBuilder
& DictionaryBuilder::SetBoolean(
64 const std::string
& path
, bool in_value
) {
65 dict_
->SetWithoutPathExpansion(path
, new base::FundamentalValue(in_value
));
71 ListBuilder::ListBuilder() : list_(new base::ListValue
) {}
72 ListBuilder::ListBuilder(const base::ListValue
& init
) : list_(init
.DeepCopy()) {
74 ListBuilder::~ListBuilder() {}
76 ListBuilder
& ListBuilder::Append(int in_value
) {
77 list_
->Append(new base::FundamentalValue(in_value
));
81 ListBuilder
& ListBuilder::Append(double in_value
) {
82 list_
->Append(new base::FundamentalValue(in_value
));
86 ListBuilder
& ListBuilder::Append(const std::string
& in_value
) {
87 list_
->Append(new base::StringValue(in_value
));
91 ListBuilder
& ListBuilder::Append(const base::string16
& in_value
) {
92 list_
->Append(new base::StringValue(in_value
));
96 ListBuilder
& ListBuilder::Append(DictionaryBuilder
& in_value
) {
97 list_
->Append(in_value
.Build().release());
101 ListBuilder
& ListBuilder::Append(ListBuilder
& in_value
) {
102 list_
->Append(in_value
.Build().release());
106 ListBuilder
& ListBuilder::AppendBoolean(bool in_value
) {
107 list_
->Append(new base::FundamentalValue(in_value
));
111 } // namespace extensions