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

Side by Side Diff: ui/accelerated_widget_mac/window_resize_helper_mac.cc

Issue 2637843002: Migrate base::TaskRunner from Closure to OnceClosure (Closed)
Patch Set: rebase Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" 5 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <list> 9 #include <list>
10 #include <utility> 10 #include <utility>
(...skipping 14 matching lines...) Expand all
25 typedef std::list<WrappedTask*> WrappedTaskQueue; 25 typedef std::list<WrappedTask*> WrappedTaskQueue;
26 typedef base::Callback<void(base::WaitableEvent*, base::TimeDelta)> 26 typedef base::Callback<void(base::WaitableEvent*, base::TimeDelta)>
27 EventTimedWaitCallback; 27 EventTimedWaitCallback;
28 28
29 // A wrapper for IPCs and tasks that we may potentially execute in 29 // A wrapper for IPCs and tasks that we may potentially execute in
30 // WaitForSingleTaskToRun. Because these tasks are sent to two places to run, 30 // WaitForSingleTaskToRun. Because these tasks are sent to two places to run,
31 // we to wrap them in this structure and track whether or not they have run 31 // we to wrap them in this structure and track whether or not they have run
32 // yet, to avoid running them twice. 32 // yet, to avoid running them twice.
33 class WrappedTask { 33 class WrappedTask {
34 public: 34 public:
35 WrappedTask(base::Closure closure, base::TimeDelta delay); 35 WrappedTask(base::OnceClosure closure, base::TimeDelta delay);
36 ~WrappedTask(); 36 ~WrappedTask();
37 bool ShouldRunBefore(const WrappedTask& other); 37 bool ShouldRunBefore(const WrappedTask& other);
38 void Run(); 38 void Run();
39 void AddToTaskRunnerQueue(PumpableTaskRunner* pumpable_task_runner); 39 void AddToTaskRunnerQueue(PumpableTaskRunner* pumpable_task_runner);
40 void RemoveFromTaskRunnerQueue(); 40 void RemoveFromTaskRunnerQueue();
41 const base::TimeTicks& can_run_time() const { return can_run_time_; } 41 const base::TimeTicks& can_run_time() const { return can_run_time_; }
42 42
43 private: 43 private:
44 base::Closure closure_; 44 base::OnceClosure closure_;
45 base::TimeTicks can_run_time_; 45 base::TimeTicks can_run_time_;
46 bool has_run_; 46 bool has_run_;
47 uint64_t sequence_number_; 47 uint64_t sequence_number_;
48 WrappedTaskQueue::iterator iterator_; 48 WrappedTaskQueue::iterator iterator_;
49 49
50 // Back pointer to the pumpable task runner that this task is enqueued in. 50 // Back pointer to the pumpable task runner that this task is enqueued in.
51 scoped_refptr<PumpableTaskRunner> pumpable_task_runner_; 51 scoped_refptr<PumpableTaskRunner> pumpable_task_runner_;
52 52
53 DISALLOW_COPY_AND_ASSIGN(WrappedTask); 53 DISALLOW_COPY_AND_ASSIGN(WrappedTask);
54 }; 54 };
(...skipping 12 matching lines...) Expand all
67 // Enqueue WrappedTask and post it to |target_task_runner_|. 67 // Enqueue WrappedTask and post it to |target_task_runner_|.
68 bool EnqueueAndPostWrappedTask(const tracked_objects::Location& from_here, 68 bool EnqueueAndPostWrappedTask(const tracked_objects::Location& from_here,
69 WrappedTask* task, 69 WrappedTask* task,
70 base::TimeDelta delay); 70 base::TimeDelta delay);
71 71
72 // Wait at most |max_delay| to run an enqueued task. 72 // Wait at most |max_delay| to run an enqueued task.
73 bool WaitForSingleWrappedTaskToRun(const base::TimeDelta& max_delay); 73 bool WaitForSingleWrappedTaskToRun(const base::TimeDelta& max_delay);
74 74
75 // base::SingleThreadTaskRunner implementation: 75 // base::SingleThreadTaskRunner implementation:
76 bool PostDelayedTask(const tracked_objects::Location& from_here, 76 bool PostDelayedTask(const tracked_objects::Location& from_here,
77 base::Closure task, 77 base::OnceClosure task,
78 base::TimeDelta delay) override; 78 base::TimeDelta delay) override;
79 79
80 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 80 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
81 base::Closure task, 81 base::OnceClosure task,
82 base::TimeDelta delay) override; 82 base::TimeDelta delay) override;
83 83
84 bool RunsTasksOnCurrentThread() const override; 84 bool RunsTasksOnCurrentThread() const override;
85 85
86 private: 86 private:
87 friend class WrappedTask; 87 friend class WrappedTask;
88 88
89 ~PumpableTaskRunner() override; 89 ~PumpableTaskRunner() override;
90 90
91 // A queue of live messages. Must hold |task_queue_lock_| to access. Tasks 91 // A queue of live messages. Must hold |task_queue_lock_| to access. Tasks
(...skipping 15 matching lines...) Expand all
107 107
108 DISALLOW_COPY_AND_ASSIGN(PumpableTaskRunner); 108 DISALLOW_COPY_AND_ASSIGN(PumpableTaskRunner);
109 }; 109 };
110 110
111 base::LazyInstance<WindowResizeHelperMac>::Leaky g_window_resize_helper = 111 base::LazyInstance<WindowResizeHelperMac>::Leaky g_window_resize_helper =
112 LAZY_INSTANCE_INITIALIZER; 112 LAZY_INSTANCE_INITIALIZER;
113 113
114 //////////////////////////////////////////////////////////////////////////////// 114 ////////////////////////////////////////////////////////////////////////////////
115 // WrappedTask 115 // WrappedTask
116 116
117 WrappedTask::WrappedTask(base::Closure closure, base::TimeDelta delay) 117 WrappedTask::WrappedTask(base::OnceClosure closure, base::TimeDelta delay)
118 : closure_(std::move(closure)), 118 : closure_(std::move(closure)),
119 can_run_time_(base::TimeTicks::Now() + delay), 119 can_run_time_(base::TimeTicks::Now() + delay),
120 has_run_(false), 120 has_run_(false),
121 sequence_number_(0) {} 121 sequence_number_(0) {}
122 122
123 WrappedTask::~WrappedTask() { 123 WrappedTask::~WrappedTask() {
124 RemoveFromTaskRunnerQueue(); 124 RemoveFromTaskRunnerQueue();
125 } 125 }
126 126
127 bool WrappedTask::ShouldRunBefore(const WrappedTask& other) { 127 bool WrappedTask::ShouldRunBefore(const WrappedTask& other) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 253
254 return target_task_runner_->PostDelayedTask( 254 return target_task_runner_->PostDelayedTask(
255 from_here, base::Bind(&WrappedTask::Run, base::Owned(task)), delay); 255 from_here, base::Bind(&WrappedTask::Run, base::Owned(task)), delay);
256 } 256 }
257 257
258 //////////////////////////////////////////////////////////////////////////////// 258 ////////////////////////////////////////////////////////////////////////////////
259 // PumpableTaskRunner, base::SingleThreadTaskRunner implementation: 259 // PumpableTaskRunner, base::SingleThreadTaskRunner implementation:
260 260
261 bool PumpableTaskRunner::PostDelayedTask( 261 bool PumpableTaskRunner::PostDelayedTask(
262 const tracked_objects::Location& from_here, 262 const tracked_objects::Location& from_here,
263 base::Closure task, 263 base::OnceClosure task,
264 base::TimeDelta delay) { 264 base::TimeDelta delay) {
265 return EnqueueAndPostWrappedTask( 265 return EnqueueAndPostWrappedTask(
266 from_here, new WrappedTask(std::move(task), delay), delay); 266 from_here, new WrappedTask(std::move(task), delay), delay);
267 } 267 }
268 268
269 bool PumpableTaskRunner::PostNonNestableDelayedTask( 269 bool PumpableTaskRunner::PostNonNestableDelayedTask(
270 const tracked_objects::Location& from_here, 270 const tracked_objects::Location& from_here,
271 base::Closure task, 271 base::OnceClosure task,
272 base::TimeDelta delay) { 272 base::TimeDelta delay) {
273 // The correctness of non-nestable events hasn't been proven for this 273 // The correctness of non-nestable events hasn't been proven for this
274 // structure. 274 // structure.
275 NOTREACHED(); 275 NOTREACHED();
276 return false; 276 return false;
277 } 277 }
278 278
279 bool PumpableTaskRunner::RunsTasksOnCurrentThread() const { 279 bool PumpableTaskRunner::RunsTasksOnCurrentThread() const {
280 return target_task_runner_->RunsTasksOnCurrentThread(); 280 return target_task_runner_->RunsTasksOnCurrentThread();
281 } 281 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 WindowResizeHelperMac::WindowResizeHelperMac() {} 318 WindowResizeHelperMac::WindowResizeHelperMac() {}
319 WindowResizeHelperMac::~WindowResizeHelperMac() {} 319 WindowResizeHelperMac::~WindowResizeHelperMac() {}
320 320
321 void WindowResizeHelperMac::EventTimedWait(base::WaitableEvent* event, 321 void WindowResizeHelperMac::EventTimedWait(base::WaitableEvent* event,
322 base::TimeDelta delay) { 322 base::TimeDelta delay) {
323 base::ThreadRestrictions::ScopedAllowWait allow_wait; 323 base::ThreadRestrictions::ScopedAllowWait allow_wait;
324 event->TimedWait(delay); 324 event->TimedWait(delay);
325 } 325 }
326 326
327 } // namespace ui 327 } // namespace ui
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698