Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: extensions/common/value_builder.cc

Issue 1739183003: Make extensions::DictionaryBuilder and extensions::ListValue unmovable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 #include "extensions/common/value_builder.h" 5 #include "extensions/common/value_builder.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 11
12 namespace extensions { 12 namespace extensions {
13 13
14 // DictionaryBuilder 14 // DictionaryBuilder
15 15
16 DictionaryBuilder::DictionaryBuilder() : dict_(new base::DictionaryValue) {} 16 DictionaryBuilder::DictionaryBuilder() : dict_(new base::DictionaryValue) {}
17 17
18 DictionaryBuilder::DictionaryBuilder(const base::DictionaryValue& init) 18 DictionaryBuilder::DictionaryBuilder(const base::DictionaryValue& init)
19 : dict_(init.DeepCopy()) {} 19 : dict_(init.DeepCopy()) {}
20 20
21 DictionaryBuilder::~DictionaryBuilder() {} 21 DictionaryBuilder::~DictionaryBuilder() {}
22 22
23 DictionaryBuilder::DictionaryBuilder(DictionaryBuilder&& other)
24 : dict_(other.Build()) {}
25
26 DictionaryBuilder& DictionaryBuilder::operator=(DictionaryBuilder&& other) {
27 dict_ = other.Build();
28 return *this;
29 }
30
31 std::string DictionaryBuilder::ToJSON() const { 23 std::string DictionaryBuilder::ToJSON() const {
32 std::string json; 24 std::string json;
33 base::JSONWriter::WriteWithOptions( 25 base::JSONWriter::WriteWithOptions(
34 *dict_, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); 26 *dict_, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
35 return json; 27 return json;
36 } 28 }
37 29
38 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, 30 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
39 int in_value) { 31 int in_value) {
40 dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value)); 32 dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
(...skipping 12 matching lines...) Expand all
53 return *this; 45 return *this;
54 } 46 }
55 47
56 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, 48 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
57 const base::string16& in_value) { 49 const base::string16& in_value) {
58 dict_->SetWithoutPathExpansion(path, new base::StringValue(in_value)); 50 dict_->SetWithoutPathExpansion(path, new base::StringValue(in_value));
59 return *this; 51 return *this;
60 } 52 }
61 53
62 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path, 54 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
63 DictionaryBuilder in_value) {
64 dict_->SetWithoutPathExpansion(path, in_value.Build());
65 return *this;
66 }
67
68 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
69 ListBuilder in_value) {
70 dict_->SetWithoutPathExpansion(path, in_value.Build());
71 return *this;
72 }
73
74 DictionaryBuilder& DictionaryBuilder::Set(const std::string& path,
75 scoped_ptr<base::Value> in_value) { 55 scoped_ptr<base::Value> in_value) {
76 dict_->SetWithoutPathExpansion(path, std::move(in_value)); 56 dict_->SetWithoutPathExpansion(path, std::move(in_value));
77 return *this; 57 return *this;
78 } 58 }
79 59
80 DictionaryBuilder& DictionaryBuilder::SetBoolean( 60 DictionaryBuilder& DictionaryBuilder::SetBoolean(
81 const std::string& path, bool in_value) { 61 const std::string& path, bool in_value) {
82 dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value)); 62 dict_->SetWithoutPathExpansion(path, new base::FundamentalValue(in_value));
83 return *this; 63 return *this;
84 } 64 }
85 65
86 // ListBuilder 66 // ListBuilder
87 67
88 ListBuilder::ListBuilder() : list_(new base::ListValue) {} 68 ListBuilder::ListBuilder() : list_(new base::ListValue) {}
89 ListBuilder::ListBuilder(const base::ListValue& init) : list_(init.DeepCopy()) { 69 ListBuilder::ListBuilder(const base::ListValue& init) : list_(init.DeepCopy()) {
90 } 70 }
91 ListBuilder::~ListBuilder() {} 71 ListBuilder::~ListBuilder() {}
92 72
93 ListBuilder::ListBuilder(ListBuilder&& other)
94 : list_(other.Build()) {}
95
96 ListBuilder& ListBuilder::operator=(ListBuilder&& other) {
97 list_ = other.Build();
98 return *this;
99 }
100
101 ListBuilder& ListBuilder::Append(int in_value) { 73 ListBuilder& ListBuilder::Append(int in_value) {
102 list_->Append(new base::FundamentalValue(in_value)); 74 list_->Append(new base::FundamentalValue(in_value));
103 return *this; 75 return *this;
104 } 76 }
105 77
106 ListBuilder& ListBuilder::Append(double in_value) { 78 ListBuilder& ListBuilder::Append(double in_value) {
107 list_->Append(new base::FundamentalValue(in_value)); 79 list_->Append(new base::FundamentalValue(in_value));
108 return *this; 80 return *this;
109 } 81 }
110 82
111 ListBuilder& ListBuilder::Append(const std::string& in_value) { 83 ListBuilder& ListBuilder::Append(const std::string& in_value) {
112 list_->Append(new base::StringValue(in_value)); 84 list_->Append(new base::StringValue(in_value));
113 return *this; 85 return *this;
114 } 86 }
115 87
116 ListBuilder& ListBuilder::Append(const base::string16& in_value) { 88 ListBuilder& ListBuilder::Append(const base::string16& in_value) {
117 list_->Append(new base::StringValue(in_value)); 89 list_->Append(new base::StringValue(in_value));
118 return *this; 90 return *this;
119 } 91 }
120 92
121 ListBuilder& ListBuilder::Append(DictionaryBuilder in_value) { 93 ListBuilder& ListBuilder::Append(scoped_ptr<base::Value> in_value) {
122 list_->Append(in_value.Build()); 94 list_->Append(std::move(in_value));
123 return *this; 95 return *this;
124 } 96 }
125 97
126 ListBuilder& ListBuilder::Append(ListBuilder in_value) {
127 list_->Append(in_value.Build());
128 return *this;
129 }
130
131 ListBuilder& ListBuilder::AppendBoolean(bool in_value) { 98 ListBuilder& ListBuilder::AppendBoolean(bool in_value) {
132 list_->Append(new base::FundamentalValue(in_value)); 99 list_->Append(new base::FundamentalValue(in_value));
133 return *this; 100 return *this;
134 } 101 }
135 102
136 } // namespace extensions 103 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698