Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / common / value_builder.cc
blob4011e702ac270f33bc8a15a8999d18a4aafaf040
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"
9 namespace extensions {
11 // DictionaryBuilder
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 {
21 std::string json;
22 base::JSONWriter::WriteWithOptions(
23 *dict_, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
24 return json;
27 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
28 int in_value) {
29 dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
30 return *this;
33 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
34 double in_value) {
35 dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
36 return *this;
39 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
40 const std::string& in_value) {
41 dict_->SetWithoutPathExpansion(path, new base::StringValue(in_value));
42 return *this;
45 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
46 const base::string16& in_value) {
47 dict_->SetWithoutPathExpansion(path, new base::StringValue(in_value));
48 return *this;
51 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
52 DictionaryBuilder& in_value) {
53 dict_->SetWithoutPathExpansion(path, in_value.Build().release());
54 return *this;
57 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
58 ListBuilder& in_value) {
59 dict_->SetWithoutPathExpansion(path, in_value.Build().release());
60 return *this;
63 DictionaryBuilder& DictionaryBuilder::SetBoolean(
64 const std::string& path, bool in_value) {
65 dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
66 return *this;
69 // ListBuilder
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));
78 return *this;
81 ListBuilder& ListBuilder::Append(double in_value) {
82 list_->Append(new base::FundamentalValue(in_value));
83 return *this;
86 ListBuilder& ListBuilder::Append(const std::string& in_value) {
87 list_->Append(new base::StringValue(in_value));
88 return *this;
91 ListBuilder& ListBuilder::Append(const base::string16& in_value) {
92 list_->Append(new base::StringValue(in_value));
93 return *this;
96 ListBuilder& ListBuilder::Append(DictionaryBuilder& in_value) {
97 list_->Append(in_value.Build().release());
98 return *this;
101 ListBuilder& ListBuilder::Append(ListBuilder& in_value) {
102 list_->Append(in_value.Build().release());
103 return *this;
106 ListBuilder& ListBuilder::AppendBoolean(bool in_value) {
107 list_->Append(new base::FundamentalValue(in_value));
108 return *this;
111 } // namespace extensions