Chromium Code Reviews| 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 TracedArrayBase; | |
| 20 class Value; | |
| 21 | |
| 22 template<class T> class TracedArray; | |
| 23 template<class T> class TracedDictionary; | |
| 24 | |
| 25 class BASE_EXPORT TracedValueBase { | |
| 26 protected: | |
| 27 TracedValueBase(); | |
| 28 ~TracedValueBase(); | |
| 29 | |
| 30 void EndCurrentDictionary(); | |
| 31 void EndCurrentArray(); | |
| 32 | |
| 33 void SetInteger(const char* name, int value); | |
| 34 void SetDouble(const char* name, double); | |
| 35 void SetBoolean(const char* name, bool value); | |
| 36 void SetString(const char* name, const std::string& value); | |
| 37 void BeginDictionaryNamed(const char* name); | |
| 38 void BeginArrayNamed(const char* name); | |
| 39 | |
| 40 void PushInteger(int); | |
| 41 void PushDouble(double); | |
| 42 void PushBoolean(bool); | |
| 43 void PushString(const std::string&); | |
| 44 void PushArray(); | |
| 45 void PushDictionary(); | |
| 46 | |
| 47 DictionaryValue* GetCurrentDictionary() const; | |
| 48 ListValue* GetCurrentArray() const; | |
| 49 | |
| 50 std::vector<Value*> m_stack; | |
|
willchan no longer on Chromium
2014/07/14 15:21:46
Should be private and named stack_ instead of m_st
yurys
2014/07/14 16:16:30
It is used in the descendants. I can make it priva
willchan no longer on Chromium
2014/07/14 16:49:22
https://engdoc.corp.google.com/eng/doc/devguide/cp
willchan no longer on Chromium
2014/07/14 16:50:39
Oops, meant to use the public link :)
http://goog
| |
| 51 | |
| 52 private: | |
| 53 DISALLOW_COPY_AND_ASSIGN(TracedValueBase); | |
| 54 }; | |
| 55 | |
| 56 class BASE_EXPORT TracedDictionaryBase : public TracedValueBase { | |
| 57 private: | |
| 58 typedef TracedDictionaryBase SelfType; | |
| 59 public: | |
| 60 void EndDictionary() | |
| 61 { | |
| 62 EndCurrentDictionary(); | |
| 63 } | |
| 64 | |
| 65 TracedDictionary<SelfType>& BeginDictionary(const char* name) | |
| 66 { | |
| 67 BeginDictionaryNamed(name); | |
| 68 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); | |
| 69 } | |
| 70 TracedArray<SelfType>& BeginArray(const char* name) | |
| 71 { | |
| 72 BeginArrayNamed(name); | |
| 73 return *reinterpret_cast<TracedArray<SelfType>*>(this); | |
| 74 } | |
| 75 SelfType& SetInteger(const char* name, int value) | |
| 76 { | |
| 77 TracedValueBase::SetInteger(name, value); | |
| 78 return *this; | |
| 79 } | |
| 80 SelfType& SetDouble(const char* name, double value) | |
| 81 { | |
| 82 TracedValueBase::SetDouble(name, value); | |
| 83 return *this; | |
| 84 } | |
| 85 SelfType& SetBoolean(const char* name, bool value) | |
| 86 { | |
| 87 TracedValueBase::SetBoolean(name, value); | |
| 88 return *this; | |
| 89 } | |
| 90 SelfType& SetString(const char* name, const std::string& value) | |
| 91 { | |
| 92 TracedValueBase::SetString(name, value); | |
| 93 return *this; | |
| 94 } | |
| 95 private: | |
| 96 TracedDictionaryBase(); | |
| 97 ~TracedDictionaryBase(); | |
| 98 DISALLOW_COPY_AND_ASSIGN(TracedDictionaryBase); | |
| 99 }; | |
| 100 | |
| 101 template <class OwnerType> | |
| 102 class TracedDictionary : public TracedDictionaryBase { | |
| 103 private: | |
| 104 typedef TracedDictionary<OwnerType> SelfType; | |
| 105 public: | |
| 106 OwnerType& EndDictionary() { | |
| 107 DCHECK(m_stack.size() == nestingLevel); | |
| 108 TracedDictionaryBase::EndDictionary(); | |
| 109 return *reinterpret_cast<OwnerType*>(this); | |
| 110 } | |
| 111 | |
| 112 TracedDictionary<SelfType >& BeginDictionary( | |
| 113 const char* name) { | |
| 114 TracedDictionaryBase::BeginDictionary(name); | |
| 115 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); | |
| 116 } | |
| 117 TracedArray<SelfType >& BeginArray(const char* name) { | |
| 118 TracedDictionaryBase::BeginArray(name); | |
| 119 return *reinterpret_cast<TracedArray<SelfType>*>(this); | |
| 120 } | |
| 121 SelfType& SetInteger(const char* name, int value) { | |
| 122 TracedDictionaryBase::SetInteger(name, value); | |
| 123 return *this; | |
| 124 } | |
| 125 SelfType& SetDouble(const char* name, double value) { | |
| 126 TracedDictionaryBase::SetDouble(name, value); | |
| 127 return *this; | |
| 128 } | |
| 129 SelfType& SetBoolean(const char* name, bool value) { | |
| 130 TracedDictionaryBase::SetBoolean(name, value); | |
| 131 return *this; | |
| 132 } | |
| 133 SelfType& SetString(const char* name, const std::string& value) { | |
| 134 TracedDictionaryBase::SetString(name, value); | |
| 135 return *this; | |
| 136 } | |
| 137 | |
| 138 static const size_t nestingLevel = OwnerType::nestingLevel + 1; | |
|
willchan no longer on Chromium
2014/07/14 15:21:46
kNestingLevel
yurys
2014/07/14 16:16:30
Done.
| |
| 139 | |
| 140 private: | |
| 141 TracedDictionary(); | |
| 142 ~TracedDictionary(); | |
| 143 DISALLOW_COPY_AND_ASSIGN(TracedDictionary); | |
| 144 }; | |
| 145 | |
| 146 class BASE_EXPORT TracedArrayBase : public TracedValueBase { | |
| 147 private: | |
| 148 typedef TracedArrayBase SelfType; | |
| 149 public: | |
| 150 void EndArray() | |
| 151 { | |
| 152 EndCurrentArray(); | |
| 153 } | |
| 154 | |
| 155 TracedDictionary<SelfType>& BeginDictionary() | |
| 156 { | |
| 157 PushDictionary(); | |
| 158 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); | |
| 159 } | |
| 160 TracedArray<SelfType>& BeginArray() | |
| 161 { | |
| 162 PushArray(); | |
| 163 return *reinterpret_cast<TracedArray<SelfType>*>(this); | |
| 164 } | |
| 165 | |
| 166 SelfType& PushInteger(int value) | |
| 167 { | |
| 168 TracedValueBase::PushInteger(value); | |
| 169 return *this; | |
| 170 } | |
| 171 SelfType& PushDouble(double value) | |
| 172 { | |
| 173 TracedValueBase::PushDouble(value); | |
| 174 return *this; | |
| 175 } | |
| 176 SelfType& PushBoolean(bool value) | |
| 177 { | |
| 178 TracedValueBase::PushBoolean(value); | |
| 179 return *this; | |
| 180 } | |
| 181 SelfType& PushString(const std::string& value) | |
| 182 { | |
| 183 TracedValueBase::PushString(value); | |
| 184 return *this; | |
| 185 } | |
| 186 | |
| 187 private: | |
| 188 TracedArrayBase(); | |
| 189 ~TracedArrayBase(); | |
| 190 DISALLOW_COPY_AND_ASSIGN(TracedArrayBase); | |
| 191 }; | |
| 192 | |
| 193 template <class OwnerType> | |
| 194 class TracedArray : public TracedArrayBase { | |
| 195 private: | |
| 196 typedef TracedArray<OwnerType> SelfType; | |
| 197 public: | |
| 198 OwnerType& EndArray() { | |
| 199 DCHECK(m_stack.size() == nestingLevel); | |
| 200 TracedArrayBase::EndArray(); | |
| 201 return *reinterpret_cast<OwnerType*>(this); | |
| 202 } | |
| 203 TracedDictionary<SelfType>& BeginDictionary() { | |
| 204 TracedArrayBase::BeginDictionary(); | |
| 205 return *reinterpret_cast<TracedDictionary<SelfType>*>(this); | |
| 206 } | |
| 207 TracedArray<SelfType>& BeginArray() { | |
| 208 TracedArrayBase::BeginArray(); | |
| 209 return *reinterpret_cast<TracedArray<SelfType>*>(this); | |
| 210 } | |
| 211 | |
| 212 SelfType& PushInteger(int value) { | |
| 213 TracedArrayBase::PushInteger(value); | |
| 214 return *this; | |
| 215 } | |
| 216 SelfType& PushDouble(double value) { | |
| 217 TracedArrayBase::PushDouble(value); | |
| 218 return *this; | |
| 219 } | |
| 220 SelfType& PushBoolean(bool value) { | |
| 221 TracedArrayBase::PushBoolean(value); | |
| 222 return *this; | |
| 223 } | |
| 224 SelfType& PushString(const std::string& value) { | |
| 225 TracedArrayBase::PushString(value); | |
| 226 return *this; | |
| 227 } | |
| 228 | |
| 229 static const size_t nestingLevel = OwnerType::nestingLevel + 1; | |
| 230 | |
| 231 private: | |
| 232 TracedArray(); | |
| 233 ~TracedArray(); | |
| 234 DISALLOW_COPY_AND_ASSIGN(TracedArray); | |
| 235 }; | |
| 236 | |
| 237 class BASE_EXPORT TracedValue : public TracedValueBase { | |
| 238 private: | |
| 239 typedef TracedValue SelfType; | |
| 240 public: | |
| 241 TracedValue(); | |
| 242 ~TracedValue(); | |
| 243 | |
| 244 TracedDictionary<SelfType>& BeginDictionary(const char* name); | |
| 245 TracedArray<SelfType>& BeginArray(const char* name); | |
| 246 SelfType& SetInteger(const char* name, int value) { | |
| 247 TracedValueBase::SetInteger(name, value); | |
| 248 return *this; | |
| 249 } | |
| 250 SelfType& SetDouble(const char* name, double value) { | |
| 251 TracedValueBase::SetDouble(name, value); | |
| 252 return *this; | |
| 253 } | |
| 254 SelfType& SetBoolean(const char* name, bool value) { | |
| 255 TracedValueBase::SetBoolean(name, value); | |
| 256 return *this; | |
| 257 } | |
| 258 SelfType& SetString(const char* name, const std::string& value) { | |
| 259 TracedValueBase::SetString(name, value); | |
| 260 return *this; | |
| 261 } | |
| 262 scoped_refptr<base::debug::ConvertableToTraceFormat> finish(); | |
|
willchan no longer on Chromium
2014/07/14 15:21:46
Finish()
yurys
2014/07/14 16:16:30
Done.
| |
| 263 | |
| 264 static const size_t nestingLevel = 1; | |
| 265 | |
| 266 private: | |
| 267 DISALLOW_COPY_AND_ASSIGN(TracedValue); | |
| 268 }; | |
| 269 | |
| 270 } // namespace base | |
| 271 | |
| 272 #endif // BASE_DEBUG_TRACE_EVENT_ARGUMENT_H_ | |
| OLD | NEW |