Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef TracedValue_h | 5 #ifndef TracedValue_h |
| 6 #define TracedValue_h | 6 #define TracedValue_h |
| 7 | 7 |
| 8 #include "platform/EventTracer.h" | 8 #include "platform/EventTracer.h" |
| 9 | 9 |
| 10 #include "wtf/PassRefPtr.h" | 10 #include "wtf/PassRefPtr.h" |
| 11 #include "wtf/text/WTFString.h" | 11 #include "wtf/text/WTFString.h" |
| 12 | 12 |
| 13 namespace WebCore { | 13 namespace WebCore { |
| 14 class JSONArray; | 14 class JSONArray; |
| 15 class JSONObject; | 15 class JSONObject; |
| 16 class JSONValue; | 16 class JSONValue; |
| 17 class TracedArrayBase; | |
| 17 template<class T> class TracedArray; | 18 template<class T> class TracedArray; |
| 18 | 19 |
| 19 class PLATFORM_EXPORT TracedValueBase { | 20 class PLATFORM_EXPORT TracedValueBase { |
| 20 WTF_MAKE_NONCOPYABLE(TracedValueBase); | 21 WTF_MAKE_NONCOPYABLE(TracedValueBase); |
| 21 protected: | 22 protected: |
| 22 TracedValueBase(); | 23 TracedValueBase(); |
| 23 ~TracedValueBase(); | 24 ~TracedValueBase(); |
| 24 | 25 |
| 25 void setInteger(const char* name, int value); | 26 void setInteger(const char* name, int value); |
| 26 void setDouble(const char* name, double); | 27 void setDouble(const char* name, double); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 37 void pushArray(); | 38 void pushArray(); |
| 38 void pushDictionary(); | 39 void pushDictionary(); |
| 39 void endCurrentArray(); | 40 void endCurrentArray(); |
| 40 | 41 |
| 41 JSONObject* currentDictionary() const; | 42 JSONObject* currentDictionary() const; |
| 42 JSONArray* currentArray() const; | 43 JSONArray* currentArray() const; |
| 43 | 44 |
| 44 Vector<RefPtr<JSONValue> > m_stack; | 45 Vector<RefPtr<JSONValue> > m_stack; |
| 45 }; | 46 }; |
| 46 | 47 |
| 48 class TracedDictionaryBase : public TracedValueBase { | |
| 49 WTF_MAKE_NONCOPYABLE(TracedDictionaryBase); | |
| 50 public: | |
| 51 void endDictionary() | |
| 52 { | |
| 53 endCurrentDictionary(); | |
| 54 } | |
| 55 | |
| 56 TracedDictionaryBase& beginDictionary(const char* name) | |
| 57 { | |
| 58 beginDictionaryNamed(name); | |
| 59 return *this; | |
| 60 } | |
| 61 TracedArrayBase& beginArray(const char* name) | |
| 62 { | |
| 63 beginArrayNamed(name); | |
| 64 return *reinterpret_cast<TracedArrayBase*>(this); | |
| 65 } | |
| 66 TracedDictionaryBase& setInteger(const char* name, int value) | |
| 67 { | |
| 68 TracedValueBase::setInteger(name, value); | |
| 69 return *this; | |
| 70 } | |
| 71 TracedDictionaryBase& setDouble(const char* name, double value) | |
| 72 { | |
| 73 TracedValueBase::setDouble(name, value); | |
| 74 return *this; | |
| 75 } | |
| 76 TracedDictionaryBase& setBoolean(const char* name, bool value) | |
| 77 { | |
| 78 TracedValueBase::setBoolean(name, value); | |
| 79 return *this; | |
| 80 } | |
| 81 TracedDictionaryBase& setString(const char* name, const String& value) | |
| 82 { | |
| 83 TracedValueBase::setString(name, value); | |
| 84 return *this; | |
| 85 } | |
| 86 private: | |
| 87 TracedDictionaryBase(); | |
| 88 ~TracedDictionaryBase(); | |
| 89 }; | |
| 90 | |
| 47 template <class OwnerType> | 91 template <class OwnerType> |
| 48 class TracedDictionary : public TracedValueBase { | 92 class TracedDictionary : public TracedDictionaryBase { |
| 49 WTF_MAKE_NONCOPYABLE(TracedDictionary); | 93 WTF_MAKE_NONCOPYABLE(TracedDictionary); |
| 50 public: | 94 public: |
| 51 OwnerType& endDictionary() | 95 OwnerType& endDictionary() |
| 52 { | 96 { |
| 53 ASSERT(m_stack.size() == nestingLevel); | 97 ASSERT(m_stack.size() == nestingLevel); |
| 54 endCurrentDictionary(); | 98 TracedDictionaryBase::endDictionary(); |
| 55 return *reinterpret_cast<OwnerType*>(this); | 99 return *reinterpret_cast<OwnerType*>(this); |
| 56 } | 100 } |
| 57 | 101 |
| 58 TracedDictionary<TracedDictionary<OwnerType> >& beginDictionary(const char* name) | 102 TracedDictionary<TracedDictionary<OwnerType> >& beginDictionary(const char* name) |
| 59 { | 103 { |
| 60 beginDictionaryNamed(name); | 104 TracedDictionaryBase::beginDictionary(name); |
| 61 return *reinterpret_cast<TracedDictionary<TracedDictionary<OwnerType> >* >(this); | 105 return *reinterpret_cast<TracedDictionary<TracedDictionary<OwnerType> >* >(this); |
| 62 } | 106 } |
| 63 TracedArray<TracedDictionary<OwnerType> >& beginArray(const char* name) | 107 TracedArray<TracedDictionary<OwnerType> >& beginArray(const char* name) |
| 64 { | 108 { |
| 65 beginArrayNamed(name); | 109 TracedDictionaryBase::beginArray(name); |
| 66 return *reinterpret_cast<TracedArray<TracedDictionary<OwnerType> >* >(th is); | 110 return *reinterpret_cast<TracedArray<TracedDictionary<OwnerType> >* >(th is); |
| 67 } | 111 } |
| 68 TracedDictionary<OwnerType>& setInteger(const char* name, int value) | 112 TracedDictionary<OwnerType>& setInteger(const char* name, int value) |
| 69 { | 113 { |
| 70 TracedValueBase::setInteger(name, value); | 114 TracedDictionaryBase::setInteger(name, value); |
| 71 return *this; | 115 return *this; |
| 72 } | 116 } |
| 73 TracedDictionary<OwnerType>& setDouble(const char* name, double value) | 117 TracedDictionary<OwnerType>& setDouble(const char* name, double value) |
| 74 { | 118 { |
| 75 TracedValueBase::setDouble(name, value); | 119 TracedDictionaryBase::setDouble(name, value); |
| 76 return *this; | 120 return *this; |
| 77 } | 121 } |
| 78 TracedDictionary<OwnerType>& setBoolean(const char* name, bool value) | 122 TracedDictionary<OwnerType>& setBoolean(const char* name, bool value) |
| 79 { | 123 { |
| 80 TracedValueBase::setBoolean(name, value); | 124 TracedDictionaryBase::setBoolean(name, value); |
| 81 return *this; | 125 return *this; |
| 82 } | 126 } |
| 83 TracedDictionary<OwnerType>& setString(const char* name, const String& value ) | 127 TracedDictionary<OwnerType>& setString(const char* name, const String& value ) |
| 84 { | 128 { |
| 85 TracedValueBase::setString(name, value); | 129 TracedDictionaryBase::setString(name, value); |
| 86 return *this; | 130 return *this; |
| 87 } | 131 } |
| 88 | 132 |
| 89 static const size_t nestingLevel = OwnerType::nestingLevel + 1; | 133 static const size_t nestingLevel = OwnerType::nestingLevel + 1; |
| 90 | 134 |
| 91 private: | 135 private: |
| 92 TracedDictionary(); | 136 TracedDictionary(); |
| 93 ~TracedDictionary(); | 137 ~TracedDictionary(); |
| 94 }; | 138 }; |
| 95 | 139 |
| 140 class TracedArrayBase : public TracedValueBase { | |
| 141 WTF_MAKE_NONCOPYABLE(TracedArrayBase); | |
| 142 public: | |
| 143 TracedDictionaryBase& beginDictionary() | |
|
alph
2014/07/10 14:45:22
You could return TracedDictionary<TracedArrayBase>
yurys
2014/07/10 15:14:07
Sounds good to me too. It would help to resolve th
| |
| 144 { | |
| 145 pushDictionary(); | |
| 146 return *reinterpret_cast<TracedDictionaryBase*>(this); | |
| 147 } | |
| 148 TracedArrayBase& beginArray() | |
| 149 { | |
| 150 pushArray(); | |
| 151 return *this; | |
| 152 } | |
| 153 void endArray() | |
| 154 { | |
| 155 endCurrentArray(); | |
| 156 } | |
| 157 | |
| 158 TracedArrayBase& pushInteger(int value) | |
| 159 { | |
| 160 TracedValueBase::pushInteger(value); | |
| 161 return *this; | |
| 162 } | |
| 163 TracedArrayBase& pushDouble(double value) | |
| 164 { | |
| 165 TracedValueBase::pushDouble(value); | |
| 166 return *this; | |
| 167 } | |
| 168 TracedArrayBase& pushBoolean(bool value) | |
| 169 { | |
| 170 TracedValueBase::pushBoolean(value); | |
| 171 return *this; | |
| 172 } | |
| 173 TracedArrayBase& pushString(const String& value) | |
| 174 { | |
| 175 TracedValueBase::pushString(value); | |
| 176 return *this; | |
| 177 } | |
| 178 | |
| 179 private: | |
| 180 TracedArrayBase(); | |
| 181 ~TracedArrayBase(); | |
| 182 }; | |
| 183 | |
| 96 template <class OwnerType> | 184 template <class OwnerType> |
| 97 class TracedArray : public TracedValueBase { | 185 class TracedArray : public TracedArrayBase { |
| 98 WTF_MAKE_NONCOPYABLE(TracedArray); | 186 WTF_MAKE_NONCOPYABLE(TracedArray); |
| 99 public: | 187 public: |
| 100 TracedDictionary<TracedArray<OwnerType> >& beginDictionary() | 188 TracedDictionary<TracedArray<OwnerType> >& beginDictionary() |
| 101 { | 189 { |
| 102 pushDictionary(); | 190 TracedArrayBase::beginDictionary(); |
| 103 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(th is); | 191 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(th is); |
| 104 } | 192 } |
| 105 TracedDictionary<TracedArray<OwnerType> >& beginArray() | 193 TracedArray<TracedArray<OwnerType> >& beginArray() |
| 106 { | 194 { |
| 107 pushArray(); | 195 TracedArrayBase::beginArray(); |
| 108 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(th is); | 196 return *reinterpret_cast<TracedArray<TracedArray<OwnerType> >* >(this); |
| 109 } | 197 } |
| 110 OwnerType& endArray() | 198 OwnerType& endArray() |
| 111 { | 199 { |
| 112 ASSERT(m_stack.size() == nestingLevel); | 200 ASSERT(m_stack.size() == nestingLevel); |
| 113 endCurrentArray(); | 201 TracedArrayBase::endArray(); |
| 114 return *reinterpret_cast<OwnerType*>(this); | 202 return *reinterpret_cast<OwnerType*>(this); |
| 115 } | 203 } |
| 116 | 204 |
| 117 TracedArray<OwnerType>& pushInteger(int value) | 205 TracedArray<OwnerType>& pushInteger(int value) |
| 118 { | 206 { |
| 119 TracedValueBase::pushInteger(value); | 207 TracedArrayBase::pushInteger(value); |
| 120 return *this; | 208 return *this; |
| 121 } | 209 } |
| 122 TracedArray<OwnerType>& pushDouble(double value) | 210 TracedArray<OwnerType>& pushDouble(double value) |
| 123 { | 211 { |
| 124 TracedValueBase::pushDouble(value); | 212 TracedArrayBase::pushDouble(value); |
| 125 return *this; | 213 return *this; |
| 126 } | 214 } |
| 127 TracedArray<OwnerType>& pushBoolean(bool value) | 215 TracedArray<OwnerType>& pushBoolean(bool value) |
| 128 { | 216 { |
| 129 TracedValueBase::pushBoolean(value); | 217 TracedArrayBase::pushBoolean(value); |
| 130 return *this; | 218 return *this; |
| 131 } | 219 } |
| 132 TracedArray<OwnerType>& pushString(const String& value) | 220 TracedArray<OwnerType>& pushString(const String& value) |
| 133 { | 221 { |
| 134 TracedValueBase::pushString(value); | 222 TracedArrayBase::pushString(value); |
| 135 return *this; | 223 return *this; |
| 136 } | 224 } |
| 137 | 225 |
| 138 static const size_t nestingLevel = OwnerType::nestingLevel + 1; | 226 static const size_t nestingLevel = OwnerType::nestingLevel + 1; |
| 139 | 227 |
| 140 private: | 228 private: |
| 141 TracedArray(); | 229 TracedArray(); |
| 142 ~TracedArray(); | 230 ~TracedArray(); |
| 143 }; | 231 }; |
| 144 | 232 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 171 return *this; | 259 return *this; |
| 172 } | 260 } |
| 173 PassRefPtr<TraceEvent::ConvertableToTraceFormat> finish(); | 261 PassRefPtr<TraceEvent::ConvertableToTraceFormat> finish(); |
| 174 | 262 |
| 175 static const size_t nestingLevel = 1; | 263 static const size_t nestingLevel = 1; |
| 176 }; | 264 }; |
| 177 | 265 |
| 178 } // namespace WebCore | 266 } // namespace WebCore |
| 179 | 267 |
| 180 #endif // TracedValue_h | 268 #endif // TracedValue_h |
| OLD | NEW |