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