| 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 BASE_TRACE_EVENT_TRACE_EVENT_ARGUMENT_H_ | 5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_ARGUMENT_H_ |
| 6 #define BASE_TRACE_EVENT_TRACE_EVENT_ARGUMENT_H_ | 6 #define BASE_TRACE_EVENT_TRACE_EVENT_ARGUMENT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/pickle.h" |
| 12 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 class DictionaryValue; | 16 |
| 16 class ListValue; | |
| 17 class Value; | 17 class Value; |
| 18 | 18 |
| 19 namespace trace_event { | 19 namespace trace_event { |
| 20 | 20 |
| 21 class BASE_EXPORT TracedValue : public ConvertableToTraceFormat { | 21 class BASE_EXPORT TracedValue : public ConvertableToTraceFormat { |
| 22 public: | 22 public: |
| 23 TracedValue(); | 23 TracedValue(); |
| 24 explicit TracedValue(size_t capacity); |
| 24 | 25 |
| 25 void EndDictionary(); | 26 void EndDictionary(); |
| 26 void EndArray(); | 27 void EndArray(); |
| 27 | 28 |
| 29 // These methods assume that |name| is a long lived "quoted" string. |
| 28 void SetInteger(const char* name, int value); | 30 void SetInteger(const char* name, int value); |
| 29 void SetDouble(const char* name, double value); | 31 void SetDouble(const char* name, double value); |
| 30 void SetBoolean(const char* name, bool value); | 32 void SetBoolean(const char* name, bool value); |
| 31 void SetString(const char* name, const std::string& value); | 33 void SetString(const char* name, const std::string& value); |
| 32 void SetValue(const char* name, scoped_ptr<Value> value); | 34 void SetValue(const char* name, const TracedValue& value); |
| 33 void BeginDictionary(const char* name); | 35 void BeginDictionary(const char* name); |
| 34 void BeginArray(const char* name); | 36 void BeginArray(const char* name); |
| 35 | 37 |
| 38 // These, instead, can be safely passed a temporary string. |
| 39 void SetIntegerWithCopiedName(const std::string& name, int value); |
| 40 void SetDoubleWithCopiedName(const std::string& name, double value); |
| 41 void SetBooleanWithCopiedName(const std::string& name, bool value); |
| 42 void SetStringWithCopiedName(const std::string& name, |
| 43 const std::string& value); |
| 44 void SetValueWithCopiedName(const std::string& name, |
| 45 const TracedValue& value); |
| 46 void BeginDictionaryWithCopiedName(const std::string& name); |
| 47 void BeginArrayWithCopiedName(const std::string& name); |
| 48 |
| 36 void AppendInteger(int); | 49 void AppendInteger(int); |
| 37 void AppendDouble(double); | 50 void AppendDouble(double); |
| 38 void AppendBoolean(bool); | 51 void AppendBoolean(bool); |
| 39 void AppendString(const std::string&); | 52 void AppendString(const std::string&); |
| 40 void BeginArray(); | 53 void BeginArray(); |
| 41 void BeginDictionary(); | 54 void BeginDictionary(); |
| 42 | 55 |
| 56 // ConvertableToTraceFormat implementation. |
| 43 void AppendAsTraceFormat(std::string* out) const override; | 57 void AppendAsTraceFormat(std::string* out) const override; |
| 44 | 58 |
| 59 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) override; |
| 60 |
| 61 // DEPRECATED: do not use, here only for legacy reasons. These methods causes |
| 62 // a copy-and-translation of the base::Value into the equivalent TracedValue. |
| 63 // TODO(primiano): migrate the (three) existing clients to the cheaper |
| 64 // SetValue(TracedValue) API. crbug.com/495628. |
| 65 void SetValue(const char* name, scoped_ptr<base::Value> value); |
| 66 void SetBaseValueWithCopiedName(const std::string& name, |
| 67 const base::Value& value); |
| 68 void AppendBaseValue(const base::Value& value); |
| 69 |
| 70 // Public for tests only. |
| 71 scoped_ptr<base::Value> ToBaseValue() const; |
| 72 |
| 45 private: | 73 private: |
| 46 ~TracedValue() override; | 74 ~TracedValue() override; |
| 47 | 75 |
| 48 DictionaryValue* GetCurrentDictionary(); | 76 Pickle pickle_; |
| 49 ListValue* GetCurrentArray(); | |
| 50 | 77 |
| 51 scoped_ptr<base::Value> root_; | 78 #ifndef NDEBUG |
| 52 std::vector<Value*> stack_; // Weak references. | 79 // In debug builds checks the pairings of {Start,End}{Dictionary,Array} |
| 80 std::vector<bool> nesting_stack_; |
| 81 #endif |
| 82 |
| 53 DISALLOW_COPY_AND_ASSIGN(TracedValue); | 83 DISALLOW_COPY_AND_ASSIGN(TracedValue); |
| 54 }; | 84 }; |
| 55 | 85 |
| 56 } // namespace trace_event | 86 } // namespace trace_event |
| 57 } // namespace base | 87 } // namespace base |
| 58 | 88 |
| 59 #endif // BASE_TRACE_EVENT_TRACE_EVENT_ARGUMENT_H_ | 89 #endif // BASE_TRACE_EVENT_TRACE_EVENT_ARGUMENT_H_ |
| OLD | NEW |