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