| 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); |
| 372 stack.push_back(cur_list); | 375 stack.push_back(cur_list); |
| 373 cur_list = nullptr; | 376 cur_list = nullptr; |
| 374 cur_dict = new_dict; | |
| 375 } | 377 } |
| 376 } break; | 378 } break; |
| 377 | 379 |
| 378 case kTypeEndArray: | 380 case kTypeEndArray: |
| 379 case kTypeEndDict: { | 381 case kTypeEndDict: { |
| 380 if (stack.back()->GetAsDictionary(&cur_dict)) { | 382 if (stack.back()->GetAsDictionary(&cur_dict)) { |
| 381 cur_list = nullptr; | 383 cur_list = nullptr; |
| 382 } else if (stack.back()->GetAsList(&cur_list)) { | 384 } else if (stack.back()->GetAsList(&cur_list)) { |
| 383 cur_dict = nullptr; | 385 cur_dict = nullptr; |
| 384 } | 386 } |
| 385 stack.pop_back(); | 387 stack.pop_back(); |
| 386 } break; | 388 } break; |
| 387 | 389 |
| 388 case kTypeStartArray: { | 390 case kTypeStartArray: { |
| 389 auto* new_list = new ListValue(); | 391 auto* new_list = new ListValue(); |
| 390 if (cur_dict) { | 392 if (cur_dict) { |
| 391 cur_dict->SetWithoutPathExpansion(ReadKeyName(it), | 393 cur_dict->SetWithoutPathExpansion(ReadKeyName(it), |
| 392 WrapUnique(new_list)); | 394 WrapUnique(new_list)); |
| 393 stack.push_back(cur_dict); | 395 stack.push_back(cur_dict); |
| 394 cur_dict = nullptr; | 396 cur_dict = nullptr; |
| 395 cur_list = new_list; | 397 cur_list = new_list; |
| 396 } else { | 398 } else { |
| 397 cur_list->Append(WrapUnique(new_list)); | 399 cur_list->Append(WrapUnique(new_list)); |
| 398 stack.push_back(cur_list); | 400 stack.push_back(cur_list); |
| 399 cur_list = new_list; | 401 // |cur_list| is invalidated at this point, so it needs to be reset. |
| 402 cur_list->GetList(cur_list->GetSize() - 1, &cur_list); |
| 400 } | 403 } |
| 401 } break; | 404 } break; |
| 402 | 405 |
| 403 case kTypeBool: { | 406 case kTypeBool: { |
| 404 bool value; | 407 bool value; |
| 405 CHECK(it.ReadBool(&value)); | 408 CHECK(it.ReadBool(&value)); |
| 406 if (cur_dict) { | 409 if (cur_dict) { |
| 407 cur_dict->SetBooleanWithoutPathExpansion(ReadKeyName(it), value); | 410 cur_dict->SetBooleanWithoutPathExpansion(ReadKeyName(it), value); |
| 408 } else { | 411 } else { |
| 409 cur_list->AppendBoolean(value); | 412 cur_list->AppendBoolean(value); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 TraceEventMemoryOverhead* overhead) { | 467 TraceEventMemoryOverhead* overhead) { |
| 465 overhead->Add("TracedValue", | 468 overhead->Add("TracedValue", |
| 466 /* allocated size */ | 469 /* allocated size */ |
| 467 pickle_.GetTotalAllocatedSize(), | 470 pickle_.GetTotalAllocatedSize(), |
| 468 /* resident size */ | 471 /* resident size */ |
| 469 pickle_.size()); | 472 pickle_.size()); |
| 470 } | 473 } |
| 471 | 474 |
| 472 } // namespace trace_event | 475 } // namespace trace_event |
| 473 } // namespace base | 476 } // namespace base |
| OLD | NEW |