Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
|
dsinclair
2013/07/23 14:56:29
These should probably be in base/debug with the ot
rterrazas
2013/08/01 08:01:26
Done.
| |
| 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_VALUE_H_ | |
| 6 #define BASE_TRACE_EVENT_VALUE_H_ | |
| 7 | |
| 8 #include <stack> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/debug/trace_event.h" | |
| 12 #include "base/format_macros.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/pickle.h" | |
| 15 #include "base/threading/non_thread_safe.h" | |
| 16 #include "base/traced_object.h" | |
| 17 | |
| 18 #define STATIC_STR(value) value, sizeof(value) | |
|
rterrazas
2013/07/21 22:23:49
I don't like this (Because I'm hiding the fact tha
dsinclair
2013/07/23 14:56:29
Let's drop this. It seems like the kind of thing t
| |
| 19 | |
| 20 namespace base { | |
| 21 | |
| 22 // TracedValue has several functions to push data that will be converted to | |
| 23 // JSON format without depending on base::Value objects. | |
|
dsinclair
2013/07/23 14:56:29
Remove the JSON and just say trace format. We don'
rterrazas
2013/08/01 08:01:26
Done.
| |
| 24 class BASE_EXPORT TracedValue : public base::debug::ConvertableToTraceFormat, | |
| 25 public base::NonThreadSafe { | |
|
dsinclair
2013/07/23 14:56:29
nit: indenting
rterrazas
2013/08/01 08:01:26
Done.
| |
| 26 public: | |
| 27 TracedValue(); | |
| 28 virtual ~TracedValue(); | |
| 29 | |
| 30 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE; | |
| 31 | |
| 32 // Begin a dictionary, that is a value within another dictionary. | |
| 33 void BeginDictionary(const char* key_in_parent_dict, int size_of_key); | |
|
nduca
2013/07/23 04:54:04
any way we can make this not require key_in_parent
rterrazas
2013/08/01 08:01:26
I thought about this also, and toyed with the idea
| |
| 34 // Begin a dictionary, it can either be a top-level structure or a value in | |
| 35 // an array. | |
| 36 void BeginDictionary(); | |
| 37 // Used for both kinds of BeginDictionary functions. | |
| 38 void EndDictionary(); | |
| 39 // Begin an array, that is a value within a dictonary. | |
| 40 void BeginArray(const char* key_in_parent_dict, int size_of_key); | |
| 41 // Begin an array, that is either a top-level structure or a value in an | |
| 42 // array. | |
| 43 void BeginArray(); | |
| 44 // Used for both kinds of BeginArray functions. | |
| 45 void EndArray(); | |
| 46 | |
| 47 // Put stuff in dictionary using statically allocated string keys. | |
| 48 void Push(const char* key, int size_of_key, const char* value, | |
|
nduca
2013/07/23 04:54:04
i think you can simplify this using the following
rterrazas
2013/08/01 08:01:26
Done.
| |
| 49 int size_of_value); | |
| 50 void Push(const char* key, int size_of_key, const std::string& value); | |
|
dsinclair
2013/07/23 14:56:29
Why do you need size_of_key? Is this the sizeof(ch
rterrazas
2013/08/01 08:01:26
It was more like sizeof buffer, but Nat's hint abo
| |
| 51 void Push(const char* key, int size_of_key, int value); | |
| 52 void Push(const char* key, int size_of_key, int64 value); | |
| 53 void Push(const char* key, int size_of_key, uint32 value); | |
| 54 void Push(const char* key, int size_of_key, uint64 value); | |
| 55 void Push(const char* key, int size_of_key, double value); | |
| 56 void Push(const char* key, int size_of_key, bool value); | |
| 57 void Push(const char* key, int size_of_key, const TracedObject& value); | |
| 58 | |
| 59 // Put stuff in an array. | |
| 60 void Push(const char* value, int size_of_key); | |
| 61 void Push(const std::string& value); | |
| 62 void Push(int value); | |
| 63 void Push(int64 value); | |
| 64 void Push(uint32 value); | |
| 65 void Push(uint64 value); | |
| 66 void Push(double value); | |
| 67 void Push(bool value); | |
| 68 void Push(const TracedObject& value); | |
| 69 | |
| 70 private: | |
| 71 // Push key/value should not be exposed, instead, the Push methods are | |
| 72 // exposed, to have them assert that we are in the right state before writing | |
| 73 // to the pickle. | |
| 74 void PushKey(const char* key, int size_of_key); | |
|
dsinclair
2013/07/23 14:56:29
Any reason why this isn't PushkeyToPickle to be co
rterrazas
2013/08/01 08:01:26
Done.
| |
| 75 void PushValueToPickle(const char* value, int size_of_value); | |
| 76 void PushValueToPickle(const std::string& value); | |
| 77 void PushValueToPickle(int value); | |
| 78 void PushValueToPickle(int64 value); | |
| 79 void PushValueToPickle(uint32 value); | |
| 80 void PushValueToPickle(uint64 value); | |
| 81 void PushValueToPickle(double value); | |
| 82 void PushValueToPickle(bool value); | |
| 83 void PushValueToPickle(const TracedObject& value); | |
| 84 | |
| 85 // Helper methods used in AppendAsTraceFormat(). | |
| 86 void AppendKeyAsRawPointer(std::string* out, PickleIterator* iter) const; | |
| 87 void AppendKeyAsString(std::string* out, | |
| 88 PickleIterator* iter) const; | |
| 89 void AppendValueAsRawPointer(std::string* out, PickleIterator* iter) const; | |
| 90 void AppendValueAsString(std::string* out, PickleIterator* iter) const; | |
| 91 void AppendValueAsInt32(std::string* out, PickleIterator* iter) const; | |
| 92 void AppendValueAsInt64(std::string* out, PickleIterator* iter) const; | |
| 93 void AppendValueAsUInt32(std::string* out, PickleIterator* iter) const; | |
| 94 void AppendValueAsUInt64(std::string* out, PickleIterator* iter) const; | |
| 95 void AppendValueAsFloat(std::string* out, PickleIterator* iter) const; | |
| 96 void AppendValueAsBool(std::string* out, PickleIterator* iter) const; | |
| 97 | |
| 98 Pickle pickle_; | |
| 99 enum Opcode { | |
| 100 BEGIN_DICTIONARY, | |
| 101 END_DICTIONARY, | |
| 102 BEGIN_ARRAY, | |
| 103 END_ARRAY, | |
| 104 KEY_AS_RAW_POINTER, | |
| 105 VALUE_AS_RAW_POINTER, | |
| 106 VALUE_AS_STRING, | |
| 107 INT32_VALUE, | |
| 108 INT64_VALUE, | |
| 109 UINT32_VALUE, | |
| 110 UINT64_VALUE, | |
| 111 FLOAT_VALUE, | |
| 112 BOOL_VALUE | |
| 113 }; | |
| 114 | |
| 115 static void AppendCommaInsideDictionary(std::string* out, int element_index); | |
| 116 static void AppendCommaInsideArray(std::string* out, | |
| 117 Opcode past_opcode, int element_index); | |
| 118 | |
| 119 // This is used to keep track of the operations that need to be closed, in | |
| 120 // in order to enforce concistency in the operations. | |
|
dsinclair
2013/07/23 14:56:29
nit: in in
nit: consistency
rterrazas
2013/08/01 08:01:26
Done.
| |
| 121 std::stack<Opcode> op_codes_; | |
|
dsinclair
2013/07/23 14:56:29
From reading the code, this isn't all the op_codes
rterrazas
2013/08/01 08:01:26
Done.
| |
| 122 | |
| 123 DISALLOW_COPY_AND_ASSIGN(TracedValue); | |
| 124 }; | |
| 125 | |
| 126 } // Closing namespace base. | |
|
dsinclair
2013/07/23 14:56:29
nit: // namespace base
rterrazas
2013/08/01 08:01:26
Done.
| |
| 127 | |
| 128 #endif // Endif for BASE_TRACE_EVENT_VALUE_H_. | |
|
dsinclair
2013/07/23 14:56:29
nit: remove comment.
rterrazas
2013/08/01 08:01:26
Done.
| |
| 129 | |
| OLD | NEW |