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; | |
| 15 class JSONObject; | |
| 14 class JSONValue; | 16 class JSONValue; |
| 17 template<class T> class TracedArray; | |
| 15 | 18 |
| 16 class PLATFORM_EXPORT TracedValue : public TraceEvent::ConvertableToTraceFormat { | 19 class PLATFORM_EXPORT TracedValueBase { |
| 20 WTF_MAKE_NONCOPYABLE(TracedValueBase); | |
| 21 protected: | |
| 22 TracedValueBase(); | |
| 23 ~TracedValueBase(); | |
| 24 | |
| 25 void setInteger(const char* name, int value); | |
|
caseq
2014/06/25 14:27:25
Can we put these methods on TracedDictionary...
yurys
2014/06/25 14:57:40
TracedDictionary is a template which means that th
| |
| 26 void setDouble(const char* name, double); | |
| 27 void setBoolean(const char* name, bool value); | |
| 28 void setString(const char* name, const String& value); | |
| 29 void beginDictionaryNamed(const char* name); | |
| 30 void beginArrayNamed(const char* name); | |
| 31 void endCurrentDictionary(); | |
| 32 | |
| 33 void pushInteger(int); | |
|
caseq
2014/06/25 14:27:25
... and these to TracedArray instead?
yurys
2014/06/25 14:57:40
I'd like to avoid this for the same reason as abov
| |
| 34 void pushDouble(double); | |
| 35 void pushBoolean(bool); | |
| 36 void pushString(const String&); | |
| 37 void pushArray(); | |
| 38 void pushDictionary(); | |
| 39 void endCurrentArray(); | |
| 40 | |
| 41 JSONObject* currentDictionary() const; | |
| 42 JSONArray* currentArray() const; | |
| 43 | |
| 44 Vector<RefPtr<JSONValue> > m_stack; | |
| 45 }; | |
| 46 | |
| 47 template <class OwnerType> | |
| 48 class PLATFORM_EXPORT TracedDictionary : public TracedValueBase { | |
| 49 WTF_MAKE_NONCOPYABLE(TracedDictionary); | |
| 50 public: | |
| 51 OwnerType& endDictionary() | |
| 52 { | |
| 53 endCurrentDictionary(); | |
| 54 return *reinterpret_cast<OwnerType*>(this); | |
| 55 } | |
| 56 | |
| 57 TracedDictionary<TracedDictionary<OwnerType> >& beginDictionary(const char* name) | |
| 58 { | |
| 59 beginDictionaryNamed(name); | |
| 60 return *reinterpret_cast<TracedDictionary<TracedDictionary<OwnerType> >* >(this); | |
| 61 } | |
| 62 TracedArray<TracedDictionary<OwnerType> >& beginArray(const char* name) | |
| 63 { | |
| 64 beginArrayNamed(name); | |
| 65 return *reinterpret_cast<TracedArray<TracedDictionary<OwnerType> >* >(th is); | |
| 66 } | |
| 67 TracedDictionary<OwnerType>& setInteger(const char* name, int value) | |
| 68 { | |
| 69 TracedValueBase::setInteger(name, value); | |
| 70 return *this; | |
| 71 } | |
| 72 TracedDictionary<OwnerType>& setDouble(const char* name, double value) | |
| 73 { | |
| 74 TracedValueBase::setDouble(name, value); | |
| 75 return *this; | |
| 76 } | |
| 77 TracedDictionary<OwnerType>& setBoolean(const char* name, bool value) | |
| 78 { | |
| 79 TracedValueBase::setBoolean(name, value); | |
| 80 return *this; | |
| 81 } | |
| 82 TracedDictionary<OwnerType>& setString(const char* name, const String& value ) | |
| 83 { | |
| 84 TracedValueBase::setString(name, value); | |
| 85 return *this; | |
| 86 } | |
| 87 | |
| 88 private: | |
| 89 TracedDictionary(); | |
| 90 ~TracedDictionary(); | |
| 91 }; | |
| 92 | |
| 93 template <class OwnerType> | |
| 94 class PLATFORM_EXPORT TracedArray : public TracedValueBase { | |
| 95 WTF_MAKE_NONCOPYABLE(TracedArray); | |
| 96 public: | |
| 97 TracedDictionary<TracedArray<OwnerType> >& beginDictionary() | |
| 98 { | |
| 99 pushDictionary(); | |
| 100 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(th is); | |
| 101 } | |
| 102 TracedDictionary<TracedArray<OwnerType> >& beginArray() | |
| 103 { | |
| 104 pushArray(); | |
| 105 return *reinterpret_cast<TracedDictionary<TracedArray<OwnerType> >* >(th is); | |
| 106 } | |
| 107 OwnerType& endArray() | |
| 108 { | |
| 109 endCurrentArray(); | |
| 110 return *reinterpret_cast<OwnerType*>(this); | |
| 111 } | |
| 112 | |
| 113 TracedArray<OwnerType>& pushInteger(int value) | |
| 114 { | |
| 115 TracedValueBase::pushInteger(value); | |
| 116 return *this; | |
| 117 } | |
| 118 TracedArray<OwnerType>& pushDouble(double value) | |
| 119 { | |
| 120 TracedValueBase::pushDouble(value); | |
| 121 return *this; | |
| 122 } | |
| 123 TracedArray<OwnerType>& pushBoolean(bool value) | |
| 124 { | |
| 125 TracedValueBase::pushBoolean(value); | |
| 126 return *this; | |
| 127 } | |
| 128 TracedArray<OwnerType>& pushString(const String& value) | |
| 129 { | |
| 130 TracedValueBase::pushString(value); | |
| 131 return *this; | |
| 132 } | |
| 133 | |
| 134 private: | |
| 135 TracedArray(); | |
| 136 ~TracedArray(); | |
| 137 }; | |
| 138 | |
| 139 class PLATFORM_EXPORT TracedValue : public TracedValueBase { | |
|
caseq
2014/06/25 14:27:25
Can we inherit from TracedDictionary instead?
yurys
2014/06/25 14:57:40
I don't think so it has different implementation o
| |
| 17 WTF_MAKE_NONCOPYABLE(TracedValue); | 140 WTF_MAKE_NONCOPYABLE(TracedValue); |
| 18 public: | 141 public: |
| 19 static PassRefPtr<TraceEvent::ConvertableToTraceFormat> fromJSONValue(PassRe fPtr<JSONValue> value) | 142 TracedValue(); |
| 143 ~TracedValue(); | |
| 144 | |
| 145 TracedDictionary<TracedValue>& beginDictionary(const char* name); | |
| 146 TracedArray<TracedValue>& beginArray(const char* name); | |
| 147 TracedValue& setInteger(const char* name, int value) | |
| 20 { | 148 { |
| 21 return adoptRef(new TracedValue(value)); | 149 TracedValueBase::setInteger(name, value); |
| 150 return *this; | |
| 22 } | 151 } |
| 23 | 152 TracedValue& setDouble(const char* name, double value) |
| 24 String asTraceFormat() const OVERRIDE; | 153 { |
| 25 | 154 TracedValueBase::setDouble(name, value); |
| 26 private: | 155 return *this; |
| 27 explicit TracedValue(PassRefPtr<JSONValue>); | 156 } |
| 28 virtual ~TracedValue(); | 157 TracedValue& setBoolean(const char* name, bool value) |
| 29 | 158 { |
| 30 RefPtr<JSONValue> m_value; | 159 TracedValueBase::setBoolean(name, value); |
| 160 return *this; | |
| 161 } | |
| 162 TracedValue& setString(const char* name, const String& value) | |
| 163 { | |
| 164 TracedValueBase::setString(name, value); | |
| 165 return *this; | |
| 166 } | |
| 167 PassRefPtr<TraceEvent::ConvertableToTraceFormat> finish(); | |
| 31 }; | 168 }; |
| 32 | 169 |
| 33 } // namespace WebCore | 170 } // namespace WebCore |
| 34 | 171 |
| 35 #endif // TracedValue_h | 172 #endif // TracedValue_h |
| OLD | NEW |