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

Side by Side Diff: base/message_loop/message_loop_task_runner.h

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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_TASK_RUNNER_H_ 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_TASK_RUNNER_H_
6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_TASK_RUNNER_H_ 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_TASK_RUNNER_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/callback.h"
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/pending_task.h" 12 #include "base/pending_task.h"
12 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
14 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
15 16
16 namespace base { 17 namespace base {
17 namespace internal { 18 namespace internal {
18 19
19 class IncomingTaskQueue; 20 class IncomingTaskQueue;
20 21
21 // A stock implementation of SingleThreadTaskRunner that is created and managed 22 // A stock implementation of SingleThreadTaskRunner that is created and managed
22 // by a MessageLoop. For now a MessageLoopTaskRunner can only be created as 23 // by a MessageLoop. For now a MessageLoopTaskRunner can only be created as
23 // part of a MessageLoop. 24 // part of a MessageLoop.
24 class BASE_EXPORT MessageLoopTaskRunner : public SingleThreadTaskRunner { 25 class BASE_EXPORT MessageLoopTaskRunner : public SingleThreadTaskRunner {
25 public: 26 public:
26 explicit MessageLoopTaskRunner( 27 explicit MessageLoopTaskRunner(
27 scoped_refptr<IncomingTaskQueue> incoming_queue); 28 scoped_refptr<IncomingTaskQueue> incoming_queue);
28 29
29 // Initialize this message loop task runner on the current thread. 30 // Initialize this message loop task runner on the current thread.
30 void BindToCurrentThread(); 31 void BindToCurrentThread();
31 32
32 // SingleThreadTaskRunner implementation 33 // SingleThreadTaskRunner implementation
33 bool PostDelayedTask(const tracked_objects::Location& from_here, 34 bool PostDelayedTask(const tracked_objects::Location& from_here,
34 const base::Closure& task, 35 Closure task,
35 base::TimeDelta delay) override; 36 base::TimeDelta delay) override;
36 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 37 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
37 const base::Closure& task, 38 Closure task,
38 base::TimeDelta delay) override; 39 base::TimeDelta delay) override;
39 bool RunsTasksOnCurrentThread() const override; 40 bool RunsTasksOnCurrentThread() const override;
40 41
41 private: 42 private:
42 friend class RefCountedThreadSafe<MessageLoopTaskRunner>; 43 friend class RefCountedThreadSafe<MessageLoopTaskRunner>;
43 ~MessageLoopTaskRunner() override; 44 ~MessageLoopTaskRunner() override;
44 45
45 // The incoming queue receiving all posted tasks. 46 // The incoming queue receiving all posted tasks.
46 scoped_refptr<IncomingTaskQueue> incoming_queue_; 47 scoped_refptr<IncomingTaskQueue> incoming_queue_;
47 48
48 // ID of the thread |this| was created on. Could be accessed on multiple 49 // ID of the thread |this| was created on. Could be accessed on multiple
49 // threads, protected by |valid_thread_id_lock_|. 50 // threads, protected by |valid_thread_id_lock_|.
50 PlatformThreadId valid_thread_id_; 51 PlatformThreadId valid_thread_id_;
51 mutable Lock valid_thread_id_lock_; 52 mutable Lock valid_thread_id_lock_;
52 53
53 DISALLOW_COPY_AND_ASSIGN(MessageLoopTaskRunner); 54 DISALLOW_COPY_AND_ASSIGN(MessageLoopTaskRunner);
54 }; 55 };
55 56
56 } // namespace internal 57 } // namespace internal
57 } // namespace base 58 } // namespace base
58 59
59 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_TASK_RUNNER_H_ 60 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_TASK_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698