Chromium Code Reviews| Index: base/debug/trace_event_argument.h |
| diff --git a/base/debug/trace_event_argument.h b/base/debug/trace_event_argument.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..eee2dccdf3b47c61729e7d751a3ab6a2f9a50203 |
| --- /dev/null |
| +++ b/base/debug/trace_event_argument.h |
| @@ -0,0 +1,272 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_DEBUG_TRACE_EVENT_ARGUMENT_H_ |
| +#define BASE_DEBUG_TRACE_EVENT_ARGUMENT_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/debug/trace_event.h" |
| +#include "base/memory/scoped_ptr.h" |
| + |
| +namespace base { |
| + |
| +class DictionaryValue; |
| +class ListValue; |
| +class StringValue; |
| +class TracedArrayBase; |
| +class Value; |
| + |
| +template<class T> class TracedArray; |
| +template<class T> class TracedDictionary; |
| + |
| +class BASE_EXPORT TracedValueBase { |
| + protected: |
| + TracedValueBase(); |
| + ~TracedValueBase(); |
| + |
| + void EndCurrentDictionary(); |
| + void EndCurrentArray(); |
| + |
| + void SetInteger(const char* name, int value); |
| + void SetDouble(const char* name, double); |
| + void SetBoolean(const char* name, bool value); |
| + void SetString(const char* name, const std::string& value); |
| + void BeginDictionaryNamed(const char* name); |
| + void BeginArrayNamed(const char* name); |
| + |
| + void PushInteger(int); |
| + void PushDouble(double); |
| + void PushBoolean(bool); |
| + void PushString(const std::string&); |
| + void PushArray(); |
| + void PushDictionary(); |
| + |
| + DictionaryValue* GetCurrentDictionary() const; |
| + ListValue* GetCurrentArray() const; |
| + |
| + 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
|
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TracedValueBase); |
| +}; |
| + |
| +class BASE_EXPORT TracedDictionaryBase : public TracedValueBase { |
| +private: |
| + typedef TracedDictionaryBase SelfType; |
| +public: |
| + void EndDictionary() |
| + { |
| + EndCurrentDictionary(); |
| + } |
| + |
| + TracedDictionary<SelfType>& BeginDictionary(const char* name) |
| + { |
| + BeginDictionaryNamed(name); |
| + return *reinterpret_cast<TracedDictionary<SelfType>*>(this); |
| + } |
| + TracedArray<SelfType>& BeginArray(const char* name) |
| + { |
| + BeginArrayNamed(name); |
| + return *reinterpret_cast<TracedArray<SelfType>*>(this); |
| + } |
| + SelfType& SetInteger(const char* name, int value) |
| + { |
| + TracedValueBase::SetInteger(name, value); |
| + return *this; |
| + } |
| + SelfType& SetDouble(const char* name, double value) |
| + { |
| + TracedValueBase::SetDouble(name, value); |
| + return *this; |
| + } |
| + SelfType& SetBoolean(const char* name, bool value) |
| + { |
| + TracedValueBase::SetBoolean(name, value); |
| + return *this; |
| + } |
| + SelfType& SetString(const char* name, const std::string& value) |
| + { |
| + TracedValueBase::SetString(name, value); |
| + return *this; |
| + } |
| +private: |
| + TracedDictionaryBase(); |
| + ~TracedDictionaryBase(); |
| + DISALLOW_COPY_AND_ASSIGN(TracedDictionaryBase); |
| +}; |
| + |
| +template <class OwnerType> |
| +class TracedDictionary : public TracedDictionaryBase { |
| + private: |
| + typedef TracedDictionary<OwnerType> SelfType; |
| + public: |
| + OwnerType& EndDictionary() { |
| + DCHECK(m_stack.size() == nestingLevel); |
| + TracedDictionaryBase::EndDictionary(); |
| + return *reinterpret_cast<OwnerType*>(this); |
| + } |
| + |
| + TracedDictionary<SelfType >& BeginDictionary( |
| + const char* name) { |
| + TracedDictionaryBase::BeginDictionary(name); |
| + return *reinterpret_cast<TracedDictionary<SelfType>*>(this); |
| + } |
| + TracedArray<SelfType >& BeginArray(const char* name) { |
| + TracedDictionaryBase::BeginArray(name); |
| + return *reinterpret_cast<TracedArray<SelfType>*>(this); |
| + } |
| + SelfType& SetInteger(const char* name, int value) { |
| + TracedDictionaryBase::SetInteger(name, value); |
| + return *this; |
| + } |
| + SelfType& SetDouble(const char* name, double value) { |
| + TracedDictionaryBase::SetDouble(name, value); |
| + return *this; |
| + } |
| + SelfType& SetBoolean(const char* name, bool value) { |
| + TracedDictionaryBase::SetBoolean(name, value); |
| + return *this; |
| + } |
| + SelfType& SetString(const char* name, const std::string& value) { |
| + TracedDictionaryBase::SetString(name, value); |
| + return *this; |
| + } |
| + |
| + 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.
|
| + |
| + private: |
| + TracedDictionary(); |
| + ~TracedDictionary(); |
| + DISALLOW_COPY_AND_ASSIGN(TracedDictionary); |
| +}; |
| + |
| +class BASE_EXPORT TracedArrayBase : public TracedValueBase { |
| +private: |
| + typedef TracedArrayBase SelfType; |
| +public: |
| + void EndArray() |
| + { |
| + EndCurrentArray(); |
| + } |
| + |
| + TracedDictionary<SelfType>& BeginDictionary() |
| + { |
| + PushDictionary(); |
| + return *reinterpret_cast<TracedDictionary<SelfType>*>(this); |
| + } |
| + TracedArray<SelfType>& BeginArray() |
| + { |
| + PushArray(); |
| + return *reinterpret_cast<TracedArray<SelfType>*>(this); |
| + } |
| + |
| + SelfType& PushInteger(int value) |
| + { |
| + TracedValueBase::PushInteger(value); |
| + return *this; |
| + } |
| + SelfType& PushDouble(double value) |
| + { |
| + TracedValueBase::PushDouble(value); |
| + return *this; |
| + } |
| + SelfType& PushBoolean(bool value) |
| + { |
| + TracedValueBase::PushBoolean(value); |
| + return *this; |
| + } |
| + SelfType& PushString(const std::string& value) |
| + { |
| + TracedValueBase::PushString(value); |
| + return *this; |
| + } |
| + |
| +private: |
| + TracedArrayBase(); |
| + ~TracedArrayBase(); |
| + DISALLOW_COPY_AND_ASSIGN(TracedArrayBase); |
| +}; |
| + |
| +template <class OwnerType> |
| +class TracedArray : public TracedArrayBase { |
| + private: |
| + typedef TracedArray<OwnerType> SelfType; |
| + public: |
| + OwnerType& EndArray() { |
| + DCHECK(m_stack.size() == nestingLevel); |
| + TracedArrayBase::EndArray(); |
| + return *reinterpret_cast<OwnerType*>(this); |
| + } |
| + TracedDictionary<SelfType>& BeginDictionary() { |
| + TracedArrayBase::BeginDictionary(); |
| + return *reinterpret_cast<TracedDictionary<SelfType>*>(this); |
| + } |
| + TracedArray<SelfType>& BeginArray() { |
| + TracedArrayBase::BeginArray(); |
| + return *reinterpret_cast<TracedArray<SelfType>*>(this); |
| + } |
| + |
| + SelfType& PushInteger(int value) { |
| + TracedArrayBase::PushInteger(value); |
| + return *this; |
| + } |
| + SelfType& PushDouble(double value) { |
| + TracedArrayBase::PushDouble(value); |
| + return *this; |
| + } |
| + SelfType& PushBoolean(bool value) { |
| + TracedArrayBase::PushBoolean(value); |
| + return *this; |
| + } |
| + SelfType& PushString(const std::string& value) { |
| + TracedArrayBase::PushString(value); |
| + return *this; |
| + } |
| + |
| + static const size_t nestingLevel = OwnerType::nestingLevel + 1; |
| + |
| + private: |
| + TracedArray(); |
| + ~TracedArray(); |
| + DISALLOW_COPY_AND_ASSIGN(TracedArray); |
| +}; |
| + |
| +class BASE_EXPORT TracedValue : public TracedValueBase { |
| + private: |
| + typedef TracedValue SelfType; |
| + public: |
| + TracedValue(); |
| + ~TracedValue(); |
| + |
| + TracedDictionary<SelfType>& BeginDictionary(const char* name); |
| + TracedArray<SelfType>& BeginArray(const char* name); |
| + SelfType& SetInteger(const char* name, int value) { |
| + TracedValueBase::SetInteger(name, value); |
| + return *this; |
| + } |
| + SelfType& SetDouble(const char* name, double value) { |
| + TracedValueBase::SetDouble(name, value); |
| + return *this; |
| + } |
| + SelfType& SetBoolean(const char* name, bool value) { |
| + TracedValueBase::SetBoolean(name, value); |
| + return *this; |
| + } |
| + SelfType& SetString(const char* name, const std::string& value) { |
| + TracedValueBase::SetString(name, value); |
| + return *this; |
| + } |
| + 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.
|
| + |
| + static const size_t nestingLevel = 1; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TracedValue); |
| +}; |
| + |
| +} // namespace base |
| + |
| +#endif // BASE_DEBUG_TRACE_EVENT_ARGUMENT_H_ |