OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "base/trace_event/trace_event_argument.h" | 5 #include "base/trace_event/trace_event_argument.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 SetBaseValueWithCopiedName(it.key(), it.value()); | 282 SetBaseValueWithCopiedName(it.key(), it.value()); |
283 } | 283 } |
284 EndDictionary(); | 284 EndDictionary(); |
285 } break; | 285 } break; |
286 | 286 |
287 case base::Value::Type::LIST: { | 287 case base::Value::Type::LIST: { |
288 const ListValue* list_value; | 288 const ListValue* list_value; |
289 value.GetAsList(&list_value); | 289 value.GetAsList(&list_value); |
290 BeginArrayWithCopiedName(name); | 290 BeginArrayWithCopiedName(name); |
291 for (const auto& base_value : *list_value) | 291 for (const auto& base_value : *list_value) |
292 AppendBaseValue(base_value); | 292 AppendBaseValue(*base_value); |
293 EndArray(); | 293 EndArray(); |
294 } break; | 294 } break; |
295 } | 295 } |
296 } | 296 } |
297 | 297 |
298 void TracedValue::AppendBaseValue(const base::Value& value) { | 298 void TracedValue::AppendBaseValue(const base::Value& value) { |
299 DCHECK_CURRENT_CONTAINER_IS(kStackTypeArray); | 299 DCHECK_CURRENT_CONTAINER_IS(kStackTypeArray); |
300 switch (value.GetType()) { | 300 switch (value.GetType()) { |
301 case base::Value::Type::NONE: | 301 case base::Value::Type::NONE: |
302 case base::Value::Type::BINARY: | 302 case base::Value::Type::BINARY: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 SetBaseValueWithCopiedName(it.key(), it.value()); | 336 SetBaseValueWithCopiedName(it.key(), it.value()); |
337 } | 337 } |
338 EndDictionary(); | 338 EndDictionary(); |
339 } break; | 339 } break; |
340 | 340 |
341 case base::Value::Type::LIST: { | 341 case base::Value::Type::LIST: { |
342 const ListValue* list_value; | 342 const ListValue* list_value; |
343 value.GetAsList(&list_value); | 343 value.GetAsList(&list_value); |
344 BeginArray(); | 344 BeginArray(); |
345 for (const auto& base_value : *list_value) | 345 for (const auto& base_value : *list_value) |
346 AppendBaseValue(base_value); | 346 AppendBaseValue(*base_value); |
347 EndArray(); | 347 EndArray(); |
348 } break; | 348 } break; |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 std::unique_ptr<base::Value> TracedValue::ToBaseValue() const { | 352 std::unique_ptr<base::Value> TracedValue::ToBaseValue() const { |
353 std::unique_ptr<DictionaryValue> root(new DictionaryValue); | 353 std::unique_ptr<DictionaryValue> root(new DictionaryValue); |
354 DictionaryValue* cur_dict = root.get(); | 354 DictionaryValue* cur_dict = root.get(); |
355 ListValue* cur_list = nullptr; | 355 ListValue* cur_list = nullptr; |
356 std::vector<Value*> stack; | 356 std::vector<Value*> stack; |
357 PickleIterator it(pickle_); | 357 PickleIterator it(pickle_); |
358 const char* type; | 358 const char* type; |
359 | 359 |
360 while (it.ReadBytes(&type, 1)) { | 360 while (it.ReadBytes(&type, 1)) { |
361 DCHECK((cur_dict && !cur_list) || (cur_list && !cur_dict)); | 361 DCHECK((cur_dict && !cur_list) || (cur_list && !cur_dict)); |
362 switch (*type) { | 362 switch (*type) { |
363 case kTypeStartDict: { | 363 case kTypeStartDict: { |
364 auto* new_dict = new DictionaryValue(); | 364 auto* new_dict = new DictionaryValue(); |
365 if (cur_dict) { | 365 if (cur_dict) { |
366 cur_dict->SetWithoutPathExpansion(ReadKeyName(it), | 366 cur_dict->SetWithoutPathExpansion(ReadKeyName(it), |
367 WrapUnique(new_dict)); | 367 WrapUnique(new_dict)); |
368 stack.push_back(cur_dict); | 368 stack.push_back(cur_dict); |
369 cur_dict = new_dict; | 369 cur_dict = new_dict; |
370 } else { | 370 } else { |
371 cur_list->Append(WrapUnique(new_dict)); | 371 cur_list->Append(WrapUnique(new_dict)); |
372 // |new_dict| is invalidated at this point, so |cur_dict| needs to be | |
373 // reset. | |
374 cur_list->GetDictionary(cur_list->GetSize() - 1, &cur_dict); | |
375 stack.push_back(cur_list); | 372 stack.push_back(cur_list); |
376 cur_list = nullptr; | 373 cur_list = nullptr; |
| 374 cur_dict = new_dict; |
377 } | 375 } |
378 } break; | 376 } break; |
379 | 377 |
380 case kTypeEndArray: | 378 case kTypeEndArray: |
381 case kTypeEndDict: { | 379 case kTypeEndDict: { |
382 if (stack.back()->GetAsDictionary(&cur_dict)) { | 380 if (stack.back()->GetAsDictionary(&cur_dict)) { |
383 cur_list = nullptr; | 381 cur_list = nullptr; |
384 } else if (stack.back()->GetAsList(&cur_list)) { | 382 } else if (stack.back()->GetAsList(&cur_list)) { |
385 cur_dict = nullptr; | 383 cur_dict = nullptr; |
386 } | 384 } |
387 stack.pop_back(); | 385 stack.pop_back(); |
388 } break; | 386 } break; |
389 | 387 |
390 case kTypeStartArray: { | 388 case kTypeStartArray: { |
391 auto* new_list = new ListValue(); | 389 auto* new_list = new ListValue(); |
392 if (cur_dict) { | 390 if (cur_dict) { |
393 cur_dict->SetWithoutPathExpansion(ReadKeyName(it), | 391 cur_dict->SetWithoutPathExpansion(ReadKeyName(it), |
394 WrapUnique(new_list)); | 392 WrapUnique(new_list)); |
395 stack.push_back(cur_dict); | 393 stack.push_back(cur_dict); |
396 cur_dict = nullptr; | 394 cur_dict = nullptr; |
397 cur_list = new_list; | 395 cur_list = new_list; |
398 } else { | 396 } else { |
399 cur_list->Append(WrapUnique(new_list)); | 397 cur_list->Append(WrapUnique(new_list)); |
400 stack.push_back(cur_list); | 398 stack.push_back(cur_list); |
401 // |cur_list| is invalidated at this point, so it needs to be reset. | 399 cur_list = new_list; |
402 cur_list->GetList(cur_list->GetSize() - 1, &cur_list); | |
403 } | 400 } |
404 } break; | 401 } break; |
405 | 402 |
406 case kTypeBool: { | 403 case kTypeBool: { |
407 bool value; | 404 bool value; |
408 CHECK(it.ReadBool(&value)); | 405 CHECK(it.ReadBool(&value)); |
409 if (cur_dict) { | 406 if (cur_dict) { |
410 cur_dict->SetBooleanWithoutPathExpansion(ReadKeyName(it), value); | 407 cur_dict->SetBooleanWithoutPathExpansion(ReadKeyName(it), value); |
411 } else { | 408 } else { |
412 cur_list->AppendBoolean(value); | 409 cur_list->AppendBoolean(value); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 TraceEventMemoryOverhead* overhead) { | 464 TraceEventMemoryOverhead* overhead) { |
468 overhead->Add("TracedValue", | 465 overhead->Add("TracedValue", |
469 /* allocated size */ | 466 /* allocated size */ |
470 pickle_.GetTotalAllocatedSize(), | 467 pickle_.GetTotalAllocatedSize(), |
471 /* resident size */ | 468 /* resident size */ |
472 pickle_.size()); | 469 pickle_.size()); |
473 } | 470 } |
474 | 471 |
475 } // namespace trace_event | 472 } // namespace trace_event |
476 } // namespace base | 473 } // namespace base |
OLD | NEW |