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

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

Issue 2271653004: Reland of tracing v2: Introduce TraceBufferWriter (https://codereview.chromium.org/2196663002) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix undefined behavior of move ctor that caused revert on Win 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 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_handle.h" 5 #include "components/tracing/core/proto_zero_message_handle.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "components/tracing/core/proto_zero_message.h" 8 #include "components/tracing/core/proto_zero_message.h"
9 9
10 namespace tracing { 10 namespace tracing {
(...skipping 24 matching lines...) Expand all
35 FinalizeMessageIfSet(message_); 35 FinalizeMessageIfSet(message_);
36 } 36 }
37 37
38 ProtoZeroMessageHandleBase::ProtoZeroMessageHandleBase( 38 ProtoZeroMessageHandleBase::ProtoZeroMessageHandleBase(
39 ProtoZeroMessageHandleBase&& other) { 39 ProtoZeroMessageHandleBase&& other) {
40 Move(&other); 40 Move(&other);
41 } 41 }
42 42
43 ProtoZeroMessageHandleBase& ProtoZeroMessageHandleBase::operator=( 43 ProtoZeroMessageHandleBase& ProtoZeroMessageHandleBase::operator=(
44 ProtoZeroMessageHandleBase&& other) { 44 ProtoZeroMessageHandleBase&& other) {
45 // If the current handle was pointing to a message and is being reset to a new
46 // one, finalize the old message.
47 FinalizeMessageIfSet(message_);
48
45 Move(&other); 49 Move(&other);
46 return *this; 50 return *this;
47 } 51 }
48 52
49 void ProtoZeroMessageHandleBase::Move(ProtoZeroMessageHandleBase* other) { 53 void ProtoZeroMessageHandleBase::Move(ProtoZeroMessageHandleBase* other) {
50 // If the current handle was pointing to a message and is being reset to a new
51 // one, finalize the old message.
52 FinalizeMessageIfSet(message_);
53
54 // In theory other->message_ could be nullptr, if |other| is a handle that has 54 // In theory other->message_ could be nullptr, if |other| is a handle that has
55 // been std::move-d (and hence empty). There isn't a legitimate use case for 55 // been std::move-d (and hence empty). There isn't a legitimate use case for
56 // doing so, though. Therefore this case is deliberately ignored (if hit, it 56 // doing so, though. Therefore this case is deliberately ignored (if hit, it
57 // will manifest as a segfault when dereferencing |message_| below) to avoid a 57 // will manifest as a segfault when dereferencing |message_| below) to avoid a
58 // useless null-check. 58 // useless null-check.
59 message_ = other->message_; 59 message_ = other->message_;
60 other->message_ = nullptr; 60 other->message_ = nullptr;
61 #if DCHECK_IS_ON() 61 #if DCHECK_IS_ON()
62 message_->set_handle(this); 62 message_->set_handle(this);
63 #endif 63 #endif
64 } 64 }
65 65
66 } // namespace v2 66 } // namespace v2
67 } // namespace tracing 67 } // namespace tracing
OLDNEW
« no previous file with comments | « components/tracing/core/proto_zero_message.cc ('k') | components/tracing/core/scattered_stream_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698