Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1695)

Unified Diff: device/bluetooth/test/bluetooth_test_win.cc

Issue 2434783002: Use OnceClosure in TestPendingTask (Closed)
Patch Set: fix Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/test/bluetooth_test_win.cc
diff --git a/device/bluetooth/test/bluetooth_test_win.cc b/device/bluetooth/test/bluetooth_test_win.cc
index 5bbdebfc4dbb43ccb46b0a48927b5ba7677c92e1..66bca947dad23eaa1f0fe4b12ac83edd52c4a9cd 100644
--- a/device/bluetooth/test/bluetooth_test_win.cc
+++ b/device/bluetooth/test/bluetooth_test_win.cc
@@ -18,6 +18,15 @@
namespace {
+// TODO(tzik): Remove this after base::TaskRunner migrates from base::Closure to
+// base::OnceClosure.
+base::RepeatingClosure UnsafeConvertOnceClosureToRepeating(
+ base::OnceClosure closure) {
+ return base::BindRepeating(
+ [](base::OnceClosure closure) { std::move(closure).Run(); },
+ base::Passed(&closure));
+}
+
BLUETOOTH_ADDRESS CanonicalStringToBLUETOOTH_ADDRESS(
std::string device_address) {
BLUETOOTH_ADDRESS win_addr;
@@ -476,20 +485,24 @@ void BluetoothTestWin::RunPendingTasksUntilCallback() {
int original_callback_count = callback_count_;
int original_error_callback_count = error_callback_count_;
do {
- base::TestPendingTask task = tasks.front();
+ base::TestPendingTask task = std::move(tasks.front());
tasks.pop_front();
- task.task.Run();
+ std::move(task.task).Run();
base::RunLoop().RunUntilIdle();
} while (tasks.size() && callback_count_ == original_callback_count &&
error_callback_count_ == original_error_callback_count);
// Put the rest of pending tasks back to Bluetooth task runner.
- for (const auto& task : tasks) {
+ for (auto& task : tasks) {
if (task.delay.is_zero()) {
- bluetooth_task_runner_->PostTask(task.location, task.task);
+ bluetooth_task_runner_->PostTask(
+ task.location,
+ UnsafeConvertOnceClosureToRepeating(std::move(task.task)));
} else {
- bluetooth_task_runner_->PostDelayedTask(task.location, task.task,
- task.delay);
+ bluetooth_task_runner_->PostDelayedTask(
+ task.location,
+ UnsafeConvertOnceClosureToRepeating(std::move(task.task)),
+ task.delay);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698