Home | History | Annotate | Download | only in trace_event
      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 <stddef.h>
      9 
     10 #include <string>
     11 #include <vector>
     12 
     13 #include "base/macros.h"
     14 #include "base/memory/scoped_ptr.h"
     15 #include "base/pickle.h"
     16 #include "base/strings/string_piece.h"
     17 #include "base/trace_event/trace_event_impl.h"
     18 
     19 namespace base {
     20 
     21 class Value;
     22 
     23 namespace trace_event {
     24 
     25 class BASE_EXPORT TracedValue : public ConvertableToTraceFormat {
     26  public:
     27   TracedValue();
     28   explicit TracedValue(size_t capacity);
     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   void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) override;
     64 
     65   // DEPRECATED: do not use, here only for legacy reasons. These methods causes
     66   // a copy-and-translation of the base::Value into the equivalent TracedValue.
     67   // TODO(primiano): migrate the (three) existing clients to the cheaper
     68   // SetValue(TracedValue) API. crbug.com/495628.
     69   void SetValue(const char* name, scoped_ptr<base::Value> value);
     70   void SetBaseValueWithCopiedName(base::StringPiece name,
     71                                   const base::Value& value);
     72   void AppendBaseValue(const base::Value& value);
     73 
     74   // Public for tests only.
     75   scoped_ptr<base::Value> ToBaseValue() const;
     76 
     77  private:
     78   ~TracedValue() override;
     79 
     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_
     94