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

Unified Diff: ui/accelerated_widget_mac/window_resize_helper_mac.cc

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: s/base::ResetAndReturn/std::move/ Created 3 years, 9 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: ui/accelerated_widget_mac/window_resize_helper_mac.cc
diff --git a/ui/accelerated_widget_mac/window_resize_helper_mac.cc b/ui/accelerated_widget_mac/window_resize_helper_mac.cc
index b64e09b01d1f6cff4fe155e37a7b0c45ad40115f..a84e823d95f2a8824d0f6db23760be43edda2587 100644
--- a/ui/accelerated_widget_mac/window_resize_helper_mac.cc
+++ b/ui/accelerated_widget_mac/window_resize_helper_mac.cc
@@ -7,9 +7,11 @@
#include <stdint.h>
#include <list>
+#include <utility>
#include "base/bind.h"
#include "base/callback.h"
+#include "base/callback_helpers.h"
#include "base/macros.h"
#include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h"
@@ -31,7 +33,7 @@ typedef base::Callback<void(base::WaitableEvent*, base::TimeDelta)>
// yet, to avoid running them twice.
class WrappedTask {
public:
- WrappedTask(const base::Closure& closure, base::TimeDelta delay);
+ WrappedTask(base::Closure closure, base::TimeDelta delay);
~WrappedTask();
bool ShouldRunBefore(const WrappedTask& other);
void Run();
@@ -73,11 +75,11 @@ class PumpableTaskRunner : public base::SingleThreadTaskRunner {
// base::SingleThreadTaskRunner implementation:
bool PostDelayedTask(const tracked_objects::Location& from_here,
- const base::Closure& task,
+ base::Closure task,
base::TimeDelta delay) override;
bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
- const base::Closure& task,
+ base::Closure task,
base::TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override;
@@ -113,8 +115,8 @@ base::LazyInstance<WindowResizeHelperMac>::Leaky g_window_resize_helper =
////////////////////////////////////////////////////////////////////////////////
// WrappedTask
-WrappedTask::WrappedTask(const base::Closure& closure, base::TimeDelta delay)
- : closure_(closure),
+WrappedTask::WrappedTask(base::Closure closure, base::TimeDelta delay)
+ : closure_(std::move(closure)),
can_run_time_(base::TimeTicks::Now() + delay),
has_run_(false),
sequence_number_(0) {}
@@ -142,7 +144,7 @@ void WrappedTask::Run() {
return;
RemoveFromTaskRunnerQueue();
has_run_ = true;
- closure_.Run();
+ std::move(closure_).Run();
}
void WrappedTask::AddToTaskRunnerQueue(
@@ -259,15 +261,15 @@ bool PumpableTaskRunner::EnqueueAndPostWrappedTask(
bool PumpableTaskRunner::PostDelayedTask(
const tracked_objects::Location& from_here,
- const base::Closure& task,
+ base::Closure task,
base::TimeDelta delay) {
- return EnqueueAndPostWrappedTask(from_here, new WrappedTask(task, delay),
- delay);
+ return EnqueueAndPostWrappedTask(
+ from_here, new WrappedTask(std::move(task), delay), delay);
}
bool PumpableTaskRunner::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
- const base::Closure& task,
+ base::Closure task,
base::TimeDelta delay) {
// The correctness of non-nestable events hasn't been proven for this
// structure.

Powered by Google App Engine
This is Rietveld 408576698