Cleaning up C++14 move into lambda TODOs.

Bug: webrtc:10945
Change-Id: I4d2f358b0e33b37e4b4f7bfcf3f6cd55e8d46bf9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153240
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29212}
This commit is contained in:
Sebastian Jansson
2019-09-17 20:29:59 +02:00
committed by Commit Bot
parent 368d002e48
commit 86314cfb5d
8 changed files with 83 additions and 172 deletions

View File

@ -36,26 +36,6 @@ constexpr size_t kMaxEventsInHistory = 10000;
// to prevent an attack via unreasonable memory use.
constexpr size_t kMaxEventsInConfigHistory = 1000;
// TODO(eladalon): This class exists because C++11 doesn't allow transferring a
// unique_ptr to a lambda (a copy constructor is required). We should get
// rid of this when we move to C++14.
template <typename T>
class ResourceOwningTask final : public QueuedTask {
public:
ResourceOwningTask(std::unique_ptr<T> resource,
std::function<void(std::unique_ptr<T>)> handler)
: resource_(std::move(resource)), handler_(handler) {}
bool Run() override {
handler_(std::move(resource_));
return true;
}
private:
std::unique_ptr<T> resource_;
std::function<void(std::unique_ptr<T>)> handler_;
};
std::unique_ptr<RtcEventLogEncoder> CreateEncoder(
RtcEventLog::EncodingType type) {
switch (type) {
@ -113,9 +93,11 @@ bool RtcEventLogImpl::StartLogging(std::unique_ptr<RtcEventLogOutput> output,
RTC_LOG(LS_INFO) << "Starting WebRTC event log. (Timestamp, UTC) = "
<< "(" << timestamp_us << ", " << utc_time_us << ").";
RTC_DCHECK_RUN_ON(&logging_state_checker_);
logging_state_started_ = true;
// Binding to |this| is safe because |this| outlives the |task_queue_|.
auto start = [this, output_period_ms, timestamp_us,
utc_time_us](std::unique_ptr<RtcEventLogOutput> output) {
task_queue_->PostTask([this, output_period_ms, timestamp_us, utc_time_us,
output = std::move(output)]() mutable {
RTC_DCHECK_RUN_ON(task_queue_.get());
RTC_DCHECK(output->IsActive());
output_period_ms_ = output_period_ms;
@ -123,13 +105,7 @@ bool RtcEventLogImpl::StartLogging(std::unique_ptr<RtcEventLogOutput> output,
num_config_events_written_ = 0;
WriteToOutput(event_encoder_->EncodeLogStart(timestamp_us, utc_time_us));
LogEventsFromMemoryToOutput();
};
RTC_DCHECK_RUN_ON(&logging_state_checker_);
logging_state_started_ = true;
task_queue_->PostTask(std::make_unique<ResourceOwningTask<RtcEventLogOutput>>(
std::move(output), start));
});
return true;
}
@ -168,15 +144,12 @@ void RtcEventLogImpl::Log(std::unique_ptr<RtcEvent> event) {
RTC_CHECK(event);
// Binding to |this| is safe because |this| outlives the |task_queue_|.
auto event_handler = [this](std::unique_ptr<RtcEvent> unencoded_event) {
task_queue_->PostTask([this, event = std::move(event)]() mutable {
RTC_DCHECK_RUN_ON(task_queue_.get());
LogToMemory(std::move(unencoded_event));
LogToMemory(std::move(event));
if (event_output_)
ScheduleOutput();
};
task_queue_->PostTask(std::make_unique<ResourceOwningTask<RtcEvent>>(
std::move(event), event_handler));
});
}
void RtcEventLogImpl::ScheduleOutput() {