Add ScopedMessageData::Release.

This CL removes an unused ScopedMessageData ctor and introduces
ScopedMessageData::Release which is the first step in order to remove
the data() methods that return a reference to a std::unique_ptr (which
is an anti-pattern).

Bug: None
Change-Id: I8f3c3fcfebd127c07fe0b667ca3442a20f458f0c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226870
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34563}
This commit is contained in:
Mirko Bonadei 2021-07-24 21:50:24 +02:00 committed by WebRTC LUCI CQ
parent 36de9dfb6e
commit 179b46b5ae
2 changed files with 3 additions and 4 deletions

View File

@ -1032,7 +1032,7 @@ void Thread::ClearCurrentTaskQueue() {
void Thread::QueuedTaskHandler::OnMessage(Message* msg) {
RTC_DCHECK(msg);
auto* data = static_cast<ScopedMessageData<webrtc::QueuedTask>*>(msg->pdata);
std::unique_ptr<webrtc::QueuedTask> task = std::move(data->data());
std::unique_ptr<webrtc::QueuedTask> task(data->Release());
// Thread expects handler to own Message::pdata when OnMessage is called
// Since MessageData is no longer needed, delete it.
delete data;

View File

@ -47,9 +47,6 @@ class ScopedMessageData : public MessageData {
explicit ScopedMessageData(std::unique_ptr<T> data)
: data_(std::move(data)) {}
// Deprecated.
// TODO(deadbeef): Remove this once downstream applications stop using it.
explicit ScopedMessageData(T* data) : data_(data) {}
// Deprecated.
// TODO(deadbeef): Returning a reference to a unique ptr? Why. Get rid of
// this once downstream applications stop using it, then rename inner_data to
// just data.
@ -59,6 +56,8 @@ class ScopedMessageData : public MessageData {
const T& inner_data() const { return *data_; }
T& inner_data() { return *data_; }
T* Release() { return data_.release(); }
private:
std::unique_ptr<T> data_;
};