OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_DEBUG_TRACE_EVENT_ARGUMENT_H_ |
| 6 #define BASE_DEBUG_TRACE_EVENT_ARGUMENT_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/debug/trace_event.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 |
| 14 namespace base { |
| 15 |
| 16 class DictionaryValue; |
| 17 class ListValue; |
| 18 class StringValue; |
| 19 class Value; |
| 20 |
| 21 template <class T> |
| 22 class TracedArray; |
| 23 |
| 24 class BASE_EXPORT TracedValueBase { |
| 25 protected: |
| 26 TracedValueBase(); |
| 27 ~TracedValueBase(); |
| 28 |
| 29 void SetInteger(const char* name, int value); |
| 30 void SetDouble(const char* name, double); |
| 31 void SetBoolean(const char* name, bool value); |
| 32 void SetString(const char* name, const std::string& value); |
| 33 void BeginDictionaryNamed(const char* name); |
| 34 void BeginArrayNamed(const char* name); |
| 35 void EndCurrentDictionary(); |
| 36 |
| 37 void PushInteger(int); |
| 38 void PushDouble(double); |
| 39 void PushBoolean(bool); |
| 40 void PushString(const std::string&); |
| 41 void PushArray(); |
| 42 void PushDictionary(); |
| 43 void EndCurrentArray(); |
| 44 |
| 45 DictionaryValue* GetCurrentDictionary() const; |
| 46 ListValue* GetCurrentArray() const; |
| 47 |
| 48 std::vector<Value*> m_stack; |
| 49 |
| 50 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(TracedValueBase); |
| 52 }; |
| 53 |
| 54 template <class OwnerType> |
| 55 class TracedDictionary : public TracedValueBase { |
| 56 public: |
| 57 OwnerType& EndDictionary() { |
| 58 DCHECK(m_stack.size() == nestingLevel); |
| 59 EndCurrentDictionary(); |
| 60 return *reinterpret_cast<OwnerType*>(this); |
| 61 } |
| 62 |
| 63 TracedDictionary<TracedDictionary<OwnerType> >& BeginDictionary( |
| 64 const char* name) { |
| 65 BeginDictionaryNamed(name); |
| 66 return *reinterpret_cast<TracedDictionary<TracedDictionary<OwnerType> >*>( |
| 67 this); |
| 68 } |
| 69 TracedArray<TracedDictionary<OwnerType> >& BeginArray(const char* name) { |
| 70 BeginArrayNamed(name); |
| 71 return *reinterpret_cast<TracedArray<TracedDictionary<OwnerType> >*>(this); |
| 72 } |
| 73 TracedDictionary<OwnerType>& SetInteger(const char* name, int value) { |
| 74 TracedValueBase::SetInteger(name, value); |
| 75 return *this; |
| 76 } |
| 77 TracedDictionary<OwnerType>& SetDouble(const char* name, double value) { |
| 78 TracedValueBase::SetDouble(name, value); |
| 79 return *this; |
| 80 } |
| 81 TracedDictionary<OwnerType>& SetBoolean(const char* name, bool value) { |
| 82 TracedValueBase::SetBoolean(name, value); |
| 83 return *this; |
| 84 } |
| 85 TracedDictionary<OwnerType>& SetString(const char* name, |
| 86 const std::string& value) { |
| 87 TracedValueBase::SetString(name, value); |
| 88 return *this; |
| 89 } |
| 90 |
| 91 static const size_t nestingLevel = OwnerType::nestingLevel + 1; |
| 92 |
| 93 private: |
| 94 TracedDictionary(); |
| 95 ~TracedDictionary(); |
| 96 DISALLOW_COPY_AND_ASSIGN(TracedDictionary); |
| 97 }; |
| 98 |
| 99 template <class OwnerType> |
| 100 class TracedArray : public TracedValueBase { |
| 101 public: |
| 102 TracedDictionary<TracedArray<OwnerType> >& BeginDictionary() { |
| 103 PushDictionary(); |
| 104 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >*>(this); |
| 105 } |
| 106 TracedDictionary<TracedArray<OwnerType> >& BeginArray() { |
| 107 PushArray(); |
| 108 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >*>(this); |
| 109 } |
| 110 OwnerType& EndArray() { |
| 111 DCHECK(m_stack.size() == nestingLevel); |
| 112 EndCurrentArray(); |
| 113 return *reinterpret_cast<OwnerType*>(this); |
| 114 } |
| 115 |
| 116 TracedArray<OwnerType>& PushInteger(int value) { |
| 117 TracedValueBase::PushInteger(value); |
| 118 return *this; |
| 119 } |
| 120 TracedArray<OwnerType>& PushDouble(double value) { |
| 121 TracedValueBase::PushDouble(value); |
| 122 return *this; |
| 123 } |
| 124 TracedArray<OwnerType>& PushBoolean(bool value) { |
| 125 TracedValueBase::PushBoolean(value); |
| 126 return *this; |
| 127 } |
| 128 TracedArray<OwnerType>& PushString(const std::string& value) { |
| 129 TracedValueBase::PushString(value); |
| 130 return *this; |
| 131 } |
| 132 |
| 133 static const size_t nestingLevel = OwnerType::nestingLevel + 1; |
| 134 |
| 135 private: |
| 136 TracedArray(); |
| 137 ~TracedArray(); |
| 138 DISALLOW_COPY_AND_ASSIGN(TracedArray); |
| 139 }; |
| 140 |
| 141 class BASE_EXPORT TracedValue : public TracedValueBase { |
| 142 public: |
| 143 TracedValue(); |
| 144 ~TracedValue(); |
| 145 |
| 146 TracedDictionary<TracedValue>& BeginDictionary(const char* name); |
| 147 TracedArray<TracedValue>& BeginArray(const char* name); |
| 148 TracedValue& SetInteger(const char* name, int value) { |
| 149 TracedValueBase::SetInteger(name, value); |
| 150 return *this; |
| 151 } |
| 152 TracedValue& SetDouble(const char* name, double value) { |
| 153 TracedValueBase::SetDouble(name, value); |
| 154 return *this; |
| 155 } |
| 156 TracedValue& SetBoolean(const char* name, bool value) { |
| 157 TracedValueBase::SetBoolean(name, value); |
| 158 return *this; |
| 159 } |
| 160 TracedValue& SetString(const char* name, const std::string& value) { |
| 161 TracedValueBase::SetString(name, value); |
| 162 return *this; |
| 163 } |
| 164 scoped_refptr<base::debug::ConvertableToTraceFormat> finish(); |
| 165 |
| 166 static const size_t nestingLevel = 1; |
| 167 |
| 168 private: |
| 169 DISALLOW_COPY_AND_ASSIGN(TracedValue); |
| 170 }; |
| 171 |
| 172 } // namespace base |
| 173 |
| 174 #endif // BASE_DEBUG_TRACE_EVENT_ARGUMENT_H_ |
OLD | NEW |