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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/Values.cpp

Issue 1745423002: DevTools: migrate protocol values from RefPtr to OwnPtr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "platform/inspector_protocol/Values.h" 5 #include "platform/inspector_protocol/Values.h"
6 6
7 #include "platform/Decimal.h" 7 #include "platform/Decimal.h"
8 #include "platform/inspector_protocol/Parser.h"
8 #include "wtf/MathExtras.h" 9 #include "wtf/MathExtras.h"
9 #include "wtf/text/StringBuilder.h" 10 #include "wtf/text/StringBuilder.h"
10 11
11 namespace blink { 12 namespace blink {
12 namespace protocol { 13 namespace protocol {
13 14
14 namespace { 15 namespace {
15 16
16 const char* const nullString = "null"; 17 const char* const nullString = "null";
17 const char* const trueString = "true"; 18 const char* const trueString = "true";
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 writeJSON(&result); 89 writeJSON(&result);
89 return result.toString(); 90 return result.toString();
90 } 91 }
91 92
92 void Value::writeJSON(StringBuilder* output) const 93 void Value::writeJSON(StringBuilder* output) const
93 { 94 {
94 ASSERT(m_type == TypeNull); 95 ASSERT(m_type == TypeNull);
95 output->append(nullString, 4); 96 output->append(nullString, 4);
96 } 97 }
97 98
99 PassOwnPtr<Value> Value::clone() const
100 {
101 return Value::null();
102 }
103
98 bool FundamentalValue::asBoolean(bool* output) const 104 bool FundamentalValue::asBoolean(bool* output) const
99 { 105 {
100 if (type() != TypeBoolean) 106 if (type() != TypeBoolean)
101 return false; 107 return false;
102 *output = m_boolValue; 108 *output = m_boolValue;
103 return true; 109 return true;
104 } 110 }
105 111
106 bool FundamentalValue::asNumber(double* output) const 112 bool FundamentalValue::asNumber(double* output) const
107 { 113 {
(...skipping 21 matching lines...) Expand all
129 output->append(falseString, 5); 135 output->append(falseString, 5);
130 } else if (type() == TypeNumber) { 136 } else if (type() == TypeNumber) {
131 if (!std::isfinite(m_doubleValue)) { 137 if (!std::isfinite(m_doubleValue)) {
132 output->append(nullString, 4); 138 output->append(nullString, 4);
133 return; 139 return;
134 } 140 }
135 output->append(Decimal::fromDouble(m_doubleValue).toString()); 141 output->append(Decimal::fromDouble(m_doubleValue).toString());
136 } 142 }
137 } 143 }
138 144
145 PassOwnPtr<Value> FundamentalValue::clone() const
146 {
147 return type() == TypeNumber ? FundamentalValue::create(m_doubleValue) : Fund amentalValue::create(m_boolValue);
148 }
149
139 bool StringValue::asString(String* output) const 150 bool StringValue::asString(String* output) const
140 { 151 {
141 *output = m_stringValue; 152 *output = m_stringValue;
142 return true; 153 return true;
143 } 154 }
144 155
145 void StringValue::writeJSON(StringBuilder* output) const 156 void StringValue::writeJSON(StringBuilder* output) const
146 { 157 {
147 ASSERT(type() == TypeString); 158 ASSERT(type() == TypeString);
148 doubleQuoteStringForJSON(m_stringValue, output); 159 doubleQuoteStringForJSON(m_stringValue, output);
149 } 160 }
150 161
162 PassOwnPtr<Value> StringValue::clone() const
163 {
164 return StringValue::create(m_stringValue);
165 }
166
151 DictionaryValue::~DictionaryValue() 167 DictionaryValue::~DictionaryValue()
152 { 168 {
153 } 169 }
154 170
155 void DictionaryValue::setBoolean(const String& name, bool value) 171 void DictionaryValue::setBoolean(const String& name, bool value)
156 { 172 {
157 setValue(name, FundamentalValue::create(value)); 173 setValue(name, FundamentalValue::create(value));
158 } 174 }
159 175
160 void DictionaryValue::setNumber(const String& name, double value) 176 void DictionaryValue::setNumber(const String& name, double value)
161 { 177 {
162 setValue(name, FundamentalValue::create(value)); 178 setValue(name, FundamentalValue::create(value));
163 } 179 }
164 180
165 void DictionaryValue::setString(const String& name, const String& value) 181 void DictionaryValue::setString(const String& name, const String& value)
166 { 182 {
167 setValue(name, StringValue::create(value)); 183 setValue(name, StringValue::create(value));
168 } 184 }
169 185
170 void DictionaryValue::setValue(const String& name, PassRefPtr<Value> value) 186 void DictionaryValue::setValue(const String& name, PassOwnPtr<Value> value)
171 { 187 {
172 ASSERT(value); 188 ASSERT(value);
173 if (m_data.set(name, value).isNewEntry) 189 if (m_data.set(name, value).isNewEntry)
174 m_order.append(name); 190 m_order.append(name);
175 } 191 }
176 192
177 void DictionaryValue::setObject(const String& name, PassRefPtr<DictionaryValue> value) 193 void DictionaryValue::setObject(const String& name, PassOwnPtr<DictionaryValue> value)
178 { 194 {
179 ASSERT(value); 195 ASSERT(value);
180 if (m_data.set(name, value).isNewEntry) 196 if (m_data.set(name, value).isNewEntry)
181 m_order.append(name); 197 m_order.append(name);
182 } 198 }
183 199
184 void DictionaryValue::setArray(const String& name, PassRefPtr<ListValue> value) 200 void DictionaryValue::setArray(const String& name, PassOwnPtr<ListValue> value)
185 { 201 {
186 ASSERT(value); 202 ASSERT(value);
187 if (m_data.set(name, value).isNewEntry) 203 if (m_data.set(name, value).isNewEntry)
188 m_order.append(name); 204 m_order.append(name);
189 } 205 }
190 206
191 DictionaryValue::iterator DictionaryValue::find(const String& name)
192 {
193 return m_data.find(name);
194 }
195
196 DictionaryValue::const_iterator DictionaryValue::find(const String& name) const
197 {
198 return m_data.find(name);
199 }
200
201 bool DictionaryValue::getBoolean(const String& name, bool* output) const 207 bool DictionaryValue::getBoolean(const String& name, bool* output) const
202 { 208 {
203 RefPtr<protocol::Value> value = get(name); 209 protocol::Value* value = get(name);
204 if (!value) 210 if (!value)
205 return false; 211 return false;
206 return value->asBoolean(output); 212 return value->asBoolean(output);
207 } 213 }
208 214
209 bool DictionaryValue::getString(const String& name, String* output) const 215 bool DictionaryValue::getString(const String& name, String* output) const
210 { 216 {
211 RefPtr<protocol::Value> value = get(name); 217 protocol::Value* value = get(name);
212 if (!value) 218 if (!value)
213 return false; 219 return false;
214 return value->asString(output); 220 return value->asString(output);
215 } 221 }
216 222
217 PassRefPtr<DictionaryValue> DictionaryValue::getObject(const String& name) const 223 DictionaryValue* DictionaryValue::getObject(const String& name) const
218 { 224 {
219 return DictionaryValue::cast(get(name)); 225 return DictionaryValue::cast(get(name));
220 } 226 }
221 227
222 PassRefPtr<protocol::ListValue> DictionaryValue::getArray(const String& name) co nst 228 protocol::ListValue* DictionaryValue::getArray(const String& name) const
223 { 229 {
224 return ListValue::cast(get(name)); 230 return ListValue::cast(get(name));
225 } 231 }
226 232
227 PassRefPtr<protocol::Value> DictionaryValue::get(const String& name) const 233 protocol::Value* DictionaryValue::get(const String& name) const
228 { 234 {
229 Dictionary::const_iterator it = m_data.find(name); 235 Dictionary::const_iterator it = m_data.find(name);
230 if (it == m_data.end()) 236 if (it == m_data.end())
231 return nullptr; 237 return nullptr;
232 return it->value; 238 return it->value.get();
233 } 239 }
234 240
235 bool DictionaryValue::booleanProperty(const String& name, bool defaultValue) con st 241 bool DictionaryValue::booleanProperty(const String& name, bool defaultValue) con st
236 { 242 {
237 bool result = defaultValue; 243 bool result = defaultValue;
238 getBoolean(name, &result); 244 getBoolean(name, &result);
239 return result; 245 return result;
240 } 246 }
241 247
242 void DictionaryValue::remove(const String& name) 248 void DictionaryValue::remove(const String& name)
(...skipping 15 matching lines...) Expand all
258 ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end()); 264 ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end());
259 if (i) 265 if (i)
260 output->append(','); 266 output->append(',');
261 doubleQuoteStringForJSON(it->key, output); 267 doubleQuoteStringForJSON(it->key, output);
262 output->append(':'); 268 output->append(':');
263 it->value->writeJSON(output); 269 it->value->writeJSON(output);
264 } 270 }
265 output->append('}'); 271 output->append('}');
266 } 272 }
267 273
274 PassOwnPtr<Value> DictionaryValue::clone() const
275 {
276 OwnPtr<DictionaryValue> result = DictionaryValue::create();
277 for (size_t i = 0; i < m_order.size(); ++i) {
278 Dictionary::const_iterator it = m_data.find(m_order[i]);
279 ASSERT(it != m_data.end());
280 result->setValue(it->key, it->value->clone());
281 }
282 return result.release();
283 }
284
268 DictionaryValue::DictionaryValue() 285 DictionaryValue::DictionaryValue()
269 : Value(TypeObject) 286 : Value(TypeObject)
270 , m_data() 287 , m_data()
271 , m_order() 288 , m_order()
272 { 289 {
273 } 290 }
274 291
275 ListValue::~ListValue() 292 ListValue::~ListValue()
276 { 293 {
277 } 294 }
278 295
279 void ListValue::writeJSON(StringBuilder* output) const 296 void ListValue::writeJSON(StringBuilder* output) const
280 { 297 {
281 output->append('['); 298 output->append('[');
282 for (Vector<RefPtr<protocol::Value>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it) { 299 for (Vector<OwnPtr<protocol::Value>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it) {
283 if (it != m_data.begin()) 300 if (it != m_data.begin())
284 output->append(','); 301 output->append(',');
285 (*it)->writeJSON(output); 302 (*it)->writeJSON(output);
286 } 303 }
287 output->append(']'); 304 output->append(']');
288 } 305 }
289 306
307 PassOwnPtr<Value> ListValue::clone() const
308 {
309 OwnPtr<ListValue> result = ListValue::create();
310 for (Vector<OwnPtr<protocol::Value>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it)
311 result->pushValue((*it)->clone());
312 return result.release();
313 }
314
290 ListValue::ListValue() 315 ListValue::ListValue()
291 : Value(TypeArray) 316 : Value(TypeArray)
292 , m_data() 317 , m_data()
293 { 318 {
294 } 319 }
295 320
296 void ListValue::pushValue(PassRefPtr<protocol::Value> value) 321 void ListValue::pushValue(PassOwnPtr<protocol::Value> value)
297 { 322 {
298 ASSERT(value); 323 ASSERT(value);
299 m_data.append(value); 324 m_data.append(value);
300 } 325 }
301 326
302 PassRefPtr<protocol::Value> ListValue::get(size_t index) 327 protocol::Value* ListValue::get(size_t index)
303 { 328 {
304 ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size()); 329 ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size());
305 return m_data[index]; 330 return m_data[index].get();
306 } 331 }
307 332
308 } // namespace protocol 333 } // namespace protocol
309 } // namespace blink 334 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698