Index: base/debug/trace_event_argument.h |
diff --git a/base/debug/trace_event_argument.h b/base/debug/trace_event_argument.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6307ae47bf7152f445640d7466b02fc638d8b594 |
--- /dev/null |
+++ b/base/debug/trace_event_argument.h |
@@ -0,0 +1,174 @@ |
+// Copyright 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. |
+ |
+#ifndef BASE_DEBUG_TRACE_EVENT_ARGUMENT_H_ |
+#define BASE_DEBUG_TRACE_EVENT_ARGUMENT_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/debug/trace_event.h" |
+#include "base/memory/scoped_ptr.h" |
+ |
+namespace base { |
+ |
+class DictionaryValue; |
+class ListValue; |
+class StringValue; |
+class Value; |
+ |
+template <class T> |
+class TracedArray; |
+ |
+class BASE_EXPORT TracedValueBase { |
+ protected: |
+ TracedValueBase(); |
+ ~TracedValueBase(); |
+ |
+ void SetInteger(const char* name, int value); |
+ void SetDouble(const char* name, double); |
+ void SetBoolean(const char* name, bool value); |
+ void SetString(const char* name, const std::string& value); |
+ void BeginDictionaryNamed(const char* name); |
+ void BeginArrayNamed(const char* name); |
+ void EndCurrentDictionary(); |
+ |
+ void PushInteger(int); |
+ void PushDouble(double); |
+ void PushBoolean(bool); |
+ void PushString(const std::string&); |
+ void PushArray(); |
+ void PushDictionary(); |
+ void EndCurrentArray(); |
dsinclair
2014/07/10 13:32:14
nit: Move this up with EndCurrentDictionary() abov
yurys
2014/07/10 15:06:29
Done.
|
+ |
+ DictionaryValue* GetCurrentDictionary() const; |
+ ListValue* GetCurrentArray() const; |
+ |
+ std::vector<Value*> m_stack; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(TracedValueBase); |
+}; |
+ |
+template <class OwnerType> |
+class TracedDictionary : public TracedValueBase { |
+ public: |
+ OwnerType& EndDictionary() { |
+ DCHECK(m_stack.size() == nestingLevel); |
+ EndCurrentDictionary(); |
+ return *reinterpret_cast<OwnerType*>(this); |
+ } |
+ |
+ TracedDictionary<TracedDictionary<OwnerType> >& BeginDictionary( |
+ const char* name) { |
+ BeginDictionaryNamed(name); |
+ return *reinterpret_cast<TracedDictionary<TracedDictionary<OwnerType> >*>( |
+ this); |
+ } |
+ TracedArray<TracedDictionary<OwnerType> >& BeginArray(const char* name) { |
+ BeginArrayNamed(name); |
+ return *reinterpret_cast<TracedArray<TracedDictionary<OwnerType> >*>(this); |
+ } |
+ TracedDictionary<OwnerType>& SetInteger(const char* name, int value) { |
+ TracedValueBase::SetInteger(name, value); |
+ return *this; |
+ } |
+ TracedDictionary<OwnerType>& SetDouble(const char* name, double value) { |
+ TracedValueBase::SetDouble(name, value); |
+ return *this; |
+ } |
+ TracedDictionary<OwnerType>& SetBoolean(const char* name, bool value) { |
+ TracedValueBase::SetBoolean(name, value); |
+ return *this; |
+ } |
+ TracedDictionary<OwnerType>& SetString(const char* name, |
+ const std::string& value) { |
+ TracedValueBase::SetString(name, value); |
+ return *this; |
+ } |
+ |
+ static const size_t nestingLevel = OwnerType::nestingLevel + 1; |
+ |
+ private: |
+ TracedDictionary(); |
+ ~TracedDictionary(); |
+ DISALLOW_COPY_AND_ASSIGN(TracedDictionary); |
+}; |
+ |
+template <class OwnerType> |
+class TracedArray : public TracedValueBase { |
+ public: |
+ TracedDictionary<TracedArray<OwnerType> >& BeginDictionary() { |
+ PushDictionary(); |
+ return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >*>(this); |
+ } |
+ TracedArray<TracedArray<OwnerType> >& BeginArray() { |
+ PushArray(); |
+ return *reinterpret_cast<TracedArray<TracedArray<OwnerType> >*>(this); |
+ } |
+ OwnerType& EndArray() { |
+ DCHECK(m_stack.size() == nestingLevel); |
+ EndCurrentArray(); |
+ return *reinterpret_cast<OwnerType*>(this); |
+ } |
+ |
+ TracedArray<OwnerType>& PushInteger(int value) { |
+ TracedValueBase::PushInteger(value); |
+ return *this; |
+ } |
+ TracedArray<OwnerType>& PushDouble(double value) { |
+ TracedValueBase::PushDouble(value); |
+ return *this; |
+ } |
+ TracedArray<OwnerType>& PushBoolean(bool value) { |
+ TracedValueBase::PushBoolean(value); |
+ return *this; |
+ } |
+ TracedArray<OwnerType>& PushString(const std::string& value) { |
+ TracedValueBase::PushString(value); |
+ return *this; |
+ } |
+ |
+ static const size_t nestingLevel = OwnerType::nestingLevel + 1; |
+ |
+ private: |
+ TracedArray(); |
+ ~TracedArray(); |
+ DISALLOW_COPY_AND_ASSIGN(TracedArray); |
+}; |
+ |
+class BASE_EXPORT TracedValue : public TracedValueBase { |
+ public: |
+ TracedValue(); |
+ ~TracedValue(); |
+ |
+ TracedDictionary<TracedValue>& BeginDictionary(const char* name); |
+ TracedArray<TracedValue>& BeginArray(const char* name); |
+ TracedValue& SetInteger(const char* name, int value) { |
+ TracedValueBase::SetInteger(name, value); |
+ return *this; |
+ } |
+ TracedValue& SetDouble(const char* name, double value) { |
+ TracedValueBase::SetDouble(name, value); |
+ return *this; |
+ } |
+ TracedValue& SetBoolean(const char* name, bool value) { |
+ TracedValueBase::SetBoolean(name, value); |
+ return *this; |
+ } |
+ TracedValue& SetString(const char* name, const std::string& value) { |
+ TracedValueBase::SetString(name, value); |
+ return *this; |
+ } |
+ scoped_refptr<base::debug::ConvertableToTraceFormat> finish(); |
+ |
+ static const size_t nestingLevel = 1; |
caseq
2014/07/10 12:42:44
nit: kNestingLevel?
Also, since it's never used as
yurys
2014/07/10 12:50:50
std::vector::size will return size_t and we compar
|
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(TracedValue); |
+}; |
+ |
+} // namespace base |
+ |
+#endif // BASE_DEBUG_TRACE_EVENT_ARGUMENT_H_ |