Chromium Code Reviews| Index: Source/platform/TracedValue.cpp |
| diff --git a/Source/platform/TracedValue.cpp b/Source/platform/TracedValue.cpp |
| index b8b3697d0a526c1ad5fc476abdc695cfefcc2f9c..128fcb44ef60862d7dd59a5e1a6db804a43c86c7 100644 |
| --- a/Source/platform/TracedValue.cpp |
| +++ b/Source/platform/TracedValue.cpp |
| @@ -10,18 +10,178 @@ |
| namespace WebCore { |
| -TracedValue::TracedValue(PassRefPtr<JSONValue> value) |
| - : m_value(value) |
| +namespace { |
| + |
| +class ConvertibleToTraceFormatJSONValue : public TraceEvent::ConvertableToTraceFormat { |
| + WTF_MAKE_NONCOPYABLE(ConvertibleToTraceFormatJSONValue); |
| +public: |
| + explicit ConvertibleToTraceFormatJSONValue(PassRefPtr<JSONValue> value) : m_value(value) { } |
| + virtual String asTraceFormat() const OVERRIDE |
| + { |
| + return m_value->toJSONString(); |
| + } |
| + |
| +private: |
| + virtual ~ConvertibleToTraceFormatJSONValue() { } |
| + |
| + RefPtr<JSONValue> m_value; |
| +}; |
| + |
| +String threadSafeCopy(const String& string) |
|
alph
2014/06/25 14:07:25
static?
yurys
2014/06/25 14:08:40
It is in anonymous namespace.
|
| +{ |
| + RefPtr<StringImpl> copy(string.impl()); |
| + if (string.isSafeToSendToAnotherThread()) |
| + return string; |
| + return string.isolatedCopy(); |
| +} |
| + |
| +#ifdef ASSERT_ENABLED |
| +bool isJSONObject(JSONValue* value) |
| +{ |
| + RefPtr<JSONObject> object; |
| + return value->asObject(&object); |
| +} |
| +bool isJSONArray(JSONValue* value) |
| +{ |
| + RefPtr<JSONArray> array; |
| + return value->asArray(&array); |
| +} |
| +#endif |
| + |
| +} |
| + |
| +TracedValueBase::TracedValueBase() |
| +{ |
| +} |
| + |
| +TracedValueBase::~TracedValueBase() |
| +{ |
| +} |
| + |
| +void TracedValueBase::setInteger(const char* name, int value) |
| +{ |
| + currentDictionary()->setNumber(name, value); |
| +} |
| + |
| +void TracedValueBase::setDouble(const char* name, double value) |
| +{ |
| + currentDictionary()->setNumber(name, value); |
| +} |
| + |
| +void TracedValueBase::setBoolean(const char* name, bool value) |
| +{ |
| + currentDictionary()->setBoolean(name, value); |
| +} |
| + |
| +void TracedValueBase::setString(const char* name, const String& value) |
| +{ |
| + currentDictionary()->setString(name, threadSafeCopy(value)); |
| +} |
| + |
| +void TracedValueBase::beginDictionaryNamed(const char* name) |
| +{ |
| + RefPtr<JSONObject> dictionary = JSONObject::create(); |
| + currentDictionary()->setObject(name, dictionary); |
| + m_stack.append(dictionary); |
| +} |
| + |
| +void TracedValueBase::beginArrayNamed(const char* name) |
| +{ |
| + RefPtr<JSONArray> array = JSONArray::create(); |
| + currentDictionary()->setArray(name, array); |
| + m_stack.append(array); |
| +} |
| + |
| +void TracedValueBase::endCurrentDictionary() |
| +{ |
| + ASSERT(!m_stack.size() > 1); |
|
alph
2014/06/25 14:07:25
something is wrong here
yurys
2014/06/25 14:08:40
Already fixed.
|
| + ASSERT(currentDictionary()); |
| + m_stack.removeLast(); |
| +} |
| + |
| +void TracedValueBase::pushInteger(int value) |
| +{ |
| + currentArray()->pushInt(value); |
| +} |
| + |
| +void TracedValueBase::pushDouble(double value) |
| +{ |
| + currentArray()->pushNumber(value); |
| +} |
| + |
| +void TracedValueBase::pushBoolean(bool value) |
| +{ |
| + currentArray()->pushBoolean(value); |
| +} |
| + |
| +void TracedValueBase::pushString(const String& value) |
| +{ |
| + currentArray()->pushString(threadSafeCopy(value)); |
| +} |
| + |
| +void TracedValueBase::pushArray() |
| +{ |
| + RefPtr<JSONArray> array = JSONArray::create(); |
| + currentArray()->pushArray(array); |
| + m_stack.append(array); |
| +} |
| + |
| +void TracedValueBase::pushDictionary() |
| { |
| + RefPtr<JSONObject> dictionary = JSONObject::create(); |
| + currentArray()->pushObject(dictionary); |
| + m_stack.append(dictionary); |
| } |
| -String TracedValue::asTraceFormat() const |
| +void TracedValueBase::endCurrentArray() |
| { |
| - return m_value->toJSONString(); |
| + ASSERT(!m_stack.size() > 1); |
|
alph
2014/06/25 14:07:26
something is wrong here
yurys
2014/06/25 14:08:40
Also fixed.
|
| + ASSERT(currentArray()); |
| + m_stack.removeLast(); |
| +} |
| + |
| +JSONObject* TracedValueBase::currentDictionary() const |
| +{ |
| + ASSERT(!m_stack.isEmpty()); |
| + ASSERT(isJSONObject(m_stack.last().get())); |
| + return static_cast<JSONObject*>(m_stack.last().get()); |
| +} |
| + |
| +JSONArray* TracedValueBase::currentArray() const |
| +{ |
| + ASSERT(!m_stack.isEmpty()); |
| + ASSERT(isJSONArray(m_stack.last().get())); |
| + return static_cast<JSONArray*>(m_stack.last().get()); |
| +} |
| + |
| +TracedValue::TracedValue() |
| +{ |
| + m_stack.append(JSONObject::create()); |
| } |
| TracedValue::~TracedValue() |
| { |
| + ASSERT(m_stack.isEmpty()); |
| +} |
| + |
| +TracedDictionary<TracedValue>& TracedValue::beginDictionary(const char* name) |
| +{ |
| + beginDictionaryNamed(name); |
| + return *reinterpret_cast<TracedDictionary<TracedValue>* >(this); |
| +} |
| + |
| +TracedArray<TracedValue>& TracedValue::beginArray(const char* name) |
| +{ |
| + beginArrayNamed(name); |
| + return *reinterpret_cast<TracedArray<TracedValue>* >(this); |
| +} |
| + |
| +PassRefPtr<TraceEvent::ConvertableToTraceFormat> TracedValue::finish() |
| +{ |
| + ASSERT(m_stack.size() == 1); |
| + RefPtr<JSONValue> value(currentDictionary()); |
| + m_stack.clear(); |
| + return adoptRef(new ConvertibleToTraceFormatJSONValue(value)); |
| } |
| } |