Chromium Code Reviews| Index: base/debug/trace_event_argument.cc |
| diff --git a/base/debug/trace_event_argument.cc b/base/debug/trace_event_argument.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..af4a064fb234282f3055a9cfcb4a2dc064eec1cf |
| --- /dev/null |
| +++ b/base/debug/trace_event_argument.cc |
| @@ -0,0 +1,117 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/debug/trace_event_argument.h" |
| + |
| +#include "base/json/json_writer.h" |
| +#include "base/values.h" |
| + |
| +namespace base { |
| +namespace debug { |
| + |
| +TracedValue::TracedValue() { |
| + stack_.push_back(new DictionaryValue()); |
| +} |
| + |
| +TracedValue::~TracedValue() { |
| + DCHECK(stack_.size() == 1); |
|
willchan no longer on Chromium
2014/07/30 15:56:16
You should use DCHECK_EQ() and DCHECK_GT() and tho
yurys
2014/07/31 12:06:09
Done.
|
| +} |
| + |
| +void TracedValue::SetInteger(const char* name, int value) { |
| + GetCurrentDictionary()->SetInteger(name, value); |
| +} |
| + |
| +void TracedValue::SetDouble(const char* name, double value) { |
| + GetCurrentDictionary()->SetDouble(name, value); |
| +} |
| + |
| +void TracedValue::SetBoolean(const char* name, bool value) { |
| + GetCurrentDictionary()->SetBoolean(name, value); |
| +} |
| + |
| +void TracedValue::SetString(const char* name, const std::string& value) { |
| + GetCurrentDictionary()->SetString(name, value); |
| +} |
| + |
| +void TracedValue::SetValue(const char* name, base::Value* value) { |
| + GetCurrentDictionary()->Set(name, value); |
| +} |
| + |
| +void TracedValue::BeginDictionary(const char* name) { |
| + base::DictionaryValue* dictionary = new base::DictionaryValue(); |
| + GetCurrentDictionary()->Set(name, dictionary); |
| + stack_.push_back(dictionary); |
| +} |
| + |
| +void TracedValue::BeginArray(const char* name) { |
| + base::ListValue* array = new base::ListValue(); |
| + GetCurrentDictionary()->Set(name, array); |
| + stack_.push_back(array); |
| +} |
| + |
| +void TracedValue::EndDictionary() { |
| + DCHECK(stack_.size() > 1); |
| + DCHECK(GetCurrentDictionary()); |
| + stack_.pop_back(); |
| +} |
| + |
| +void TracedValue::AppendInteger(int value) { |
| + GetCurrentArray()->AppendInteger(value); |
| +} |
| + |
| +void TracedValue::AppendDouble(double value) { |
| + GetCurrentArray()->AppendDouble(value); |
| +} |
| + |
| +void TracedValue::AppendBoolean(bool value) { |
| + GetCurrentArray()->AppendBoolean(value); |
| +} |
| + |
| +void TracedValue::AppendString(const std::string& value) { |
| + GetCurrentArray()->AppendString(value); |
| +} |
| + |
| +void TracedValue::BeginArray() { |
| + ListValue* array = new ListValue(); |
| + GetCurrentArray()->Append(array); |
| + stack_.push_back(array); |
| +} |
| + |
| +void TracedValue::BeginDictionary() { |
| + DictionaryValue* dictionary = new DictionaryValue(); |
| + GetCurrentArray()->Append(dictionary); |
| + stack_.push_back(dictionary); |
| +} |
| + |
| +void TracedValue::EndArray() { |
| + DCHECK(stack_.size() > 1); |
| + DCHECK(GetCurrentArray()); |
| + stack_.pop_back(); |
| +} |
| + |
| +DictionaryValue* TracedValue::GetCurrentDictionary() { |
| + DCHECK(!stack_.empty()); |
| + DictionaryValue* dictionary = NULL; |
| + stack_.back()->GetAsDictionary(&dictionary); |
| + DCHECK(dictionary); |
| + return dictionary; |
| +} |
| + |
| +ListValue* TracedValue::GetCurrentArray() { |
| + DCHECK(!stack_.empty()); |
| + ListValue* list = NULL; |
| + stack_.back()->GetAsList(&list); |
| + DCHECK(list); |
| + return list; |
| +} |
| + |
| +void TracedValue::AppendAsTraceFormat(std::string* out) const { |
| + DCHECK(stack_.size() == 1); |
| + std::string tmp; |
| + base::JSONWriter::Write(stack_.front(), &tmp); |
| + *out += tmp; |
| +} |
| + |
| +} // namespace debug |
| +} // namespace base |