Relanding: Use std::unique_ptr instead of rtc::scoped_refptr in AsyncInvoker.
The AsyncClosures only ever have one thing referencing them, so they
should be using std::unique_ptr to manage ownership. Maybe this code was
written before std::unique_ptr was available.
Originally reverted because it made a change to ScopedMessageData
that wasn't backwards compatible, and applications using the rtc::Thread
infrastructure may be using it.
BUG=None
NOTRY=True
Review-Url: https://codereview.webrtc.org/2689233003
Cr-Commit-Position: refs/heads/master@{#16684}
diff --git a/webrtc/base/messagequeue.h b/webrtc/base/messagequeue.h
index 429a56a..df50f54 100644
--- a/webrtc/base/messagequeue.h
+++ b/webrtc/base/messagequeue.h
@@ -17,6 +17,7 @@
#include <list>
#include <memory>
#include <queue>
+#include <utility>
#include <vector>
#include "webrtc/base/basictypes.h"
@@ -98,10 +99,21 @@
template <class T>
class ScopedMessageData : public MessageData {
public:
- explicit ScopedMessageData(T* data) : data_(data) { }
+ 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.
const std::unique_ptr<T>& data() const { return data_; }
std::unique_ptr<T>& data() { return data_; }
+ const T& inner_data() const { return *data_; }
+ T& inner_data() { return *data_; }
+
private:
std::unique_ptr<T> data_;
};