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