| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |