Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(861)

Side by Side Diff: base/trace_event/trace_event_argument.h

Issue 1451943002: Make base::trace_event::TracedValue use StringPiece where possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/trace_event/trace_event_argument.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/pickle.h"
13 #include "base/strings/string_piece.h"
13 #include "base/trace_event/trace_event_impl.h" 14 #include "base/trace_event/trace_event_impl.h"
14 15
15 namespace base { 16 namespace base {
16 17
17 class Value; 18 class Value;
18 19
19 namespace trace_event { 20 namespace trace_event {
20 21
21 class BASE_EXPORT TracedValue : public ConvertableToTraceFormat { 22 class BASE_EXPORT TracedValue : public ConvertableToTraceFormat {
22 public: 23 public:
23 TracedValue(); 24 TracedValue();
24 explicit TracedValue(size_t capacity); 25 explicit TracedValue(size_t capacity);
25 26
26 void EndDictionary(); 27 void EndDictionary();
27 void EndArray(); 28 void EndArray();
28 29
29 // These methods assume that |name| is a long lived "quoted" string. 30 // These methods assume that |name| is a long lived "quoted" string.
30 void SetInteger(const char* name, int value); 31 void SetInteger(const char* name, int value);
31 void SetDouble(const char* name, double value); 32 void SetDouble(const char* name, double value);
32 void SetBoolean(const char* name, bool value); 33 void SetBoolean(const char* name, bool value);
33 void SetString(const char* name, const std::string& value); 34 void SetString(const char* name, base::StringPiece value);
34 void SetValue(const char* name, const TracedValue& value); 35 void SetValue(const char* name, const TracedValue& value);
35 void BeginDictionary(const char* name); 36 void BeginDictionary(const char* name);
36 void BeginArray(const char* name); 37 void BeginArray(const char* name);
37 38
38 // These, instead, can be safely passed a temporary string. 39 // These, instead, can be safely passed a temporary string.
39 void SetIntegerWithCopiedName(const std::string& name, int value); 40 void SetIntegerWithCopiedName(base::StringPiece name, int value);
40 void SetDoubleWithCopiedName(const std::string& name, double value); 41 void SetDoubleWithCopiedName(base::StringPiece name, double value);
41 void SetBooleanWithCopiedName(const std::string& name, bool value); 42 void SetBooleanWithCopiedName(base::StringPiece name, bool value);
42 void SetStringWithCopiedName(const std::string& name, 43 void SetStringWithCopiedName(base::StringPiece name,
43 const std::string& value); 44 base::StringPiece value);
44 void SetValueWithCopiedName(const std::string& name, 45 void SetValueWithCopiedName(base::StringPiece name,
45 const TracedValue& value); 46 const TracedValue& value);
46 void BeginDictionaryWithCopiedName(const std::string& name); 47 void BeginDictionaryWithCopiedName(base::StringPiece name);
47 void BeginArrayWithCopiedName(const std::string& name); 48 void BeginArrayWithCopiedName(base::StringPiece name);
48 49
49 void AppendInteger(int); 50 void AppendInteger(int);
50 void AppendDouble(double); 51 void AppendDouble(double);
51 void AppendBoolean(bool); 52 void AppendBoolean(bool);
52 void AppendString(const std::string&); 53 void AppendString(base::StringPiece);
53 void BeginArray(); 54 void BeginArray();
54 void BeginDictionary(); 55 void BeginDictionary();
55 56
56 // ConvertableToTraceFormat implementation. 57 // ConvertableToTraceFormat implementation.
57 void AppendAsTraceFormat(std::string* out) const override; 58 void AppendAsTraceFormat(std::string* out) const override;
58 59
59 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) override; 60 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) override;
60 61
61 // DEPRECATED: do not use, here only for legacy reasons. These methods causes 62 // 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 // a copy-and-translation of the base::Value into the equivalent TracedValue.
63 // TODO(primiano): migrate the (three) existing clients to the cheaper 64 // TODO(primiano): migrate the (three) existing clients to the cheaper
64 // SetValue(TracedValue) API. crbug.com/495628. 65 // SetValue(TracedValue) API. crbug.com/495628.
65 void SetValue(const char* name, scoped_ptr<base::Value> value); 66 void SetValue(const char* name, scoped_ptr<base::Value> value);
66 void SetBaseValueWithCopiedName(const std::string& name, 67 void SetBaseValueWithCopiedName(base::StringPiece name,
67 const base::Value& value); 68 const base::Value& value);
68 void AppendBaseValue(const base::Value& value); 69 void AppendBaseValue(const base::Value& value);
69 70
70 // Public for tests only. 71 // Public for tests only.
71 scoped_ptr<base::Value> ToBaseValue() const; 72 scoped_ptr<base::Value> ToBaseValue() const;
72 73
73 private: 74 private:
74 ~TracedValue() override; 75 ~TracedValue() override;
75 76
76 Pickle pickle_; 77 Pickle pickle_;
77 78
78 #ifndef NDEBUG 79 #ifndef NDEBUG
79 // In debug builds checks the pairings of {Start,End}{Dictionary,Array} 80 // In debug builds checks the pairings of {Start,End}{Dictionary,Array}
80 std::vector<bool> nesting_stack_; 81 std::vector<bool> nesting_stack_;
81 #endif 82 #endif
82 83
83 DISALLOW_COPY_AND_ASSIGN(TracedValue); 84 DISALLOW_COPY_AND_ASSIGN(TracedValue);
84 }; 85 };
85 86
86 } // namespace trace_event 87 } // namespace trace_event
87 } // namespace base 88 } // namespace base
88 89
89 #endif // BASE_TRACE_EVENT_TRACE_EVENT_ARGUMENT_H_ 90 #endif // BASE_TRACE_EVENT_TRACE_EVENT_ARGUMENT_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/trace_event_argument.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698