Update pc/ to use C++ lambdas instead of rtc::Bind
(and a subclass of QueuedTask in one place, where needed for move
semantics).
Bug: webrtc:11339
Change-Id: I109de41a8753f177db1bbb8d21b6744eb3ad2de0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/201734
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33021}
diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc
index 5292008..c9a337d 100644
--- a/pc/rtc_stats_collector.cc
+++ b/pc/rtc_stats_collector.cc
@@ -1060,9 +1060,30 @@
// reentrancy problems.
std::vector<RequestInfo> requests;
requests.swap(requests_);
- signaling_thread_->PostTask(
- RTC_FROM_HERE, rtc::Bind(&RTCStatsCollector::DeliverCachedReport, this,
- cached_report_, std::move(requests)));
+
+ // Task subclass to take ownership of the requests.
+ // TODO(nisse): Delete when we can use C++14, and do lambda capture with
+ // std::move.
+ class DeliveryTask : public QueuedTask {
+ public:
+ DeliveryTask(rtc::scoped_refptr<RTCStatsCollector> collector,
+ rtc::scoped_refptr<const RTCStatsReport> cached_report,
+ std::vector<RequestInfo> requests)
+ : collector_(collector),
+ cached_report_(cached_report),
+ requests_(std::move(requests)) {}
+ bool Run() override {
+ collector_->DeliverCachedReport(cached_report_, std::move(requests_));
+ return true;
+ }
+
+ private:
+ rtc::scoped_refptr<RTCStatsCollector> collector_;
+ rtc::scoped_refptr<const RTCStatsReport> cached_report_;
+ std::vector<RequestInfo> requests_;
+ };
+ signaling_thread_->PostTask(std::make_unique<DeliveryTask>(
+ this, cached_report_, std::move(requests)));
} else if (!num_pending_partial_reports_) {
// Only start gathering stats if we're not already gathering stats. In the
// case of already gathering stats, |callback_| will be invoked when there
@@ -1088,10 +1109,10 @@
// ProducePartialResultsOnNetworkThread() has signaled the
// |network_report_event_|.
network_report_event_.Reset();
- network_thread_->PostTask(
- RTC_FROM_HERE,
- rtc::Bind(&RTCStatsCollector::ProducePartialResultsOnNetworkThread,
- this, timestamp_us));
+ rtc::scoped_refptr<RTCStatsCollector> collector(this);
+ network_thread_->PostTask(RTC_FROM_HERE, [collector, timestamp_us] {
+ collector->ProducePartialResultsOnNetworkThread(timestamp_us);
+ });
ProducePartialResultsOnSignalingThread(timestamp_us);
}
}
@@ -1160,8 +1181,9 @@
// Signal that it is now safe to touch |network_report_| on the signaling
// thread, and post a task to merge it into the final results.
network_report_event_.Set();
+ rtc::scoped_refptr<RTCStatsCollector> collector(this);
signaling_thread_->PostTask(
- RTC_FROM_HERE, rtc::Bind(&RTCStatsCollector::MergeNetworkReport_s, this));
+ RTC_FROM_HERE, [collector] { collector->MergeNetworkReport_s(); });
}
void RTCStatsCollector::ProducePartialResultsOnNetworkThreadImpl(