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

Unified Diff: components/tracing/core/proto_zero_message_handle.h

Issue 2240043004: Tracing V2: Fully-functional plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix use after free in tests Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: components/tracing/core/proto_zero_message_handle.h
diff --git a/components/tracing/core/proto_zero_message_handle.h b/components/tracing/core/proto_zero_message_handle.h
index 2f83ec9638f0d400a96eec74c159c0730eab62f7..d02763f644b30fb06e561e411ed752e280897d3d 100644
--- a/components/tracing/core/proto_zero_message_handle.h
+++ b/components/tracing/core/proto_zero_message_handle.h
@@ -5,6 +5,12 @@
#ifndef COMPONENTS_TRACING_CORE_PROTO_ZERO_MESSAGE_HANDLE_H_
#define COMPONENTS_TRACING_CORE_PROTO_ZERO_MESSAGE_HANDLE_H_
+#include <stdint.h>
+
+#include <set>
+#include <string>
+
+#include "base/logging.h"
#include "base/macros.h"
#include "components/tracing/tracing_export.h"
@@ -32,6 +38,12 @@ class TRACING_EXPORT ProtoZeroMessageHandleBase {
ProtoZeroMessageHandleBase(ProtoZeroMessageHandleBase&& other);
ProtoZeroMessageHandleBase& operator=(ProtoZeroMessageHandleBase&& other);
+ inline void SealField(uint32_t field_id) {
+ DCHECK(sealed_fields_.count(field_id) == 0) <<
+ "Field (" + std::to_string(field_id) + ") can't be sealed again.";
+ sealed_fields_.insert(field_id);
+ }
+
protected:
explicit ProtoZeroMessageHandleBase(ProtoZeroMessage*);
ProtoZeroMessage& operator*() const { return *message_; }
@@ -40,16 +52,20 @@ class TRACING_EXPORT ProtoZeroMessageHandleBase {
private:
friend class ProtoZeroMessage;
- void reset_message() { message_ = nullptr; }
+ void reset_message() {
+ message_ = nullptr;
+ sealed_fields_.clear();
+ }
void Move(ProtoZeroMessageHandleBase* other);
ProtoZeroMessage* message_;
+ std::set<uint32_t> sealed_fields_;
alph 2016/08/22 22:48:35 nit: unordered_set
kraynov 2016/08/23 12:43:49 Done.
DISALLOW_COPY_AND_ASSIGN(ProtoZeroMessageHandleBase);
};
template <typename T>
-class ProtoZeroMessageHandle : ProtoZeroMessageHandleBase {
+class ProtoZeroMessageHandle : public ProtoZeroMessageHandleBase {
public:
explicit ProtoZeroMessageHandle(T* message)
: ProtoZeroMessageHandleBase(message) {}

Powered by Google App Engine
This is Rietveld 408576698