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

Side by Side Diff: components/tracing/core/proto_zero_message.cc

Issue 2158323005: tracing v2: Introduce handles for safe usage of ProtoZeroMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final nits Created 4 years, 5 months 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "components/tracing/core/proto_zero_message.h" 5 #include "components/tracing/core/proto_zero_message.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "components/tracing/core/proto_utils.h" 9 #include "components/tracing/core/proto_utils.h"
10 #include "components/tracing/core/proto_zero_message_handle.h"
10 11
11 #if !defined(ARCH_CPU_LITTLE_ENDIAN) 12 #if !defined(ARCH_CPU_LITTLE_ENDIAN)
12 // The memcpy() for float and double below needs to be adjusted if we want to 13 // The memcpy() for float and double below needs to be adjusted if we want to
13 // support big endian CPUs. There doesn't seem to be a compelling need today. 14 // support big endian CPUs. There doesn't seem to be a compelling need today.
14 #error big-endian CPUs not supported by this translation unit. 15 #error big-endian CPUs not supported by this translation unit.
15 #endif 16 #endif
16 17
17 namespace tracing { 18 namespace tracing {
18 namespace v2 { 19 namespace v2 {
19 20
(...skipping 17 matching lines...) Expand all
37 // This method is called to initialize both root and nested messages. 38 // This method is called to initialize both root and nested messages.
38 void ProtoZeroMessage::Reset(ScatteredStreamWriter* stream_writer) { 39 void ProtoZeroMessage::Reset(ScatteredStreamWriter* stream_writer) {
39 stream_writer_ = stream_writer; 40 stream_writer_ = stream_writer;
40 size_ = 0; 41 size_ = 0;
41 size_field_.reset(); 42 size_field_.reset();
42 size_already_written_ = 0; 43 size_already_written_ = 0;
43 nested_message_ = nullptr; 44 nested_message_ = nullptr;
44 nesting_depth_ = 0; 45 nesting_depth_ = 0;
45 #if DCHECK_IS_ON() 46 #if DCHECK_IS_ON()
46 sealed_ = false; 47 sealed_ = false;
48 handle_ = nullptr;
47 #endif 49 #endif
48 } 50 }
49 51
50 void ProtoZeroMessage::AppendVarIntU64(uint32_t field_id, uint64_t value) { 52 void ProtoZeroMessage::AppendVarIntU64(uint32_t field_id, uint64_t value) {
51 if (nested_message_) 53 if (nested_message_)
52 EndNestedMessage(); 54 EndNestedMessage();
53 55
54 uint8_t data[proto::GetMaxVarIntEncodedSize<uint32_t>() + 56 uint8_t data[proto::GetMaxVarIntEncodedSize<uint32_t>() +
55 proto::GetMaxVarIntEncodedSize<uint64_t>()]; 57 proto::GetMaxVarIntEncodedSize<uint64_t>()];
56 uint8_t* data_end; 58 uint8_t* data_end;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DCHECK_LT(size_, proto::kMaxMessageLength); 123 DCHECK_LT(size_, proto::kMaxMessageLength);
122 DCHECK_EQ(proto::kMessageLengthFieldSize, size_field_.size()); 124 DCHECK_EQ(proto::kMessageLengthFieldSize, size_field_.size());
123 proto::WriteRedundantVarIntU32<proto::kMessageLengthFieldSize>( 125 proto::WriteRedundantVarIntU32<proto::kMessageLengthFieldSize>(
124 static_cast<uint32_t>(size_ - size_already_written_), 126 static_cast<uint32_t>(size_ - size_already_written_),
125 size_field_.begin); 127 size_field_.begin);
126 size_field_.reset(); 128 size_field_.reset();
127 } 129 }
128 130
129 #if DCHECK_IS_ON() 131 #if DCHECK_IS_ON()
130 sealed_ = true; 132 sealed_ = true;
133 if (handle_)
134 handle_->reset_message();
131 #endif 135 #endif
132 136
133 return size_; 137 return size_;
134 } 138 }
135 139
136 void ProtoZeroMessage::BeginNestedMessageInternal(uint32_t field_id, 140 void ProtoZeroMessage::BeginNestedMessageInternal(uint32_t field_id,
137 ProtoZeroMessage* message) { 141 ProtoZeroMessage* message) {
138 if (nested_message_) 142 if (nested_message_)
139 EndNestedMessage(); 143 EndNestedMessage();
140 144
(...skipping 15 matching lines...) Expand all
156 nested_message_ = message; 160 nested_message_ = message;
157 } 161 }
158 162
159 void ProtoZeroMessage::EndNestedMessage() { 163 void ProtoZeroMessage::EndNestedMessage() {
160 size_ += nested_message_->Finalize(); 164 size_ += nested_message_->Finalize();
161 nested_message_ = nullptr; 165 nested_message_ = nullptr;
162 } 166 }
163 167
164 } // namespace v2 168 } // namespace v2
165 } // namespace tracing 169 } // namespace tracing
OLDNEW
« no previous file with comments | « components/tracing/core/proto_zero_message.h ('k') | components/tracing/core/proto_zero_message_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698