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 REMOTING_BASE_PLUGIN_MESSAGE_LOOP_H_ | 5 #ifndef REMOTING_BASE_PLUGIN_MESSAGE_LOOP_H_ |
6 #define REMOTING_BASE_PLUGIN_MESSAGE_LOOP_H_ | 6 #define REMOTING_BASE_PLUGIN_MESSAGE_LOOP_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 | 13 |
14 namespace remoting { | 14 namespace remoting { |
15 | 15 |
16 // MessageLoopProxy for plugin main threads. | 16 // MessageLoopProxy for plugin main threads. |
17 class PluginMessageLoopProxy : public base::MessageLoopProxy { | 17 class PluginMessageLoopProxy : public base::MessageLoopProxy { |
18 public: | 18 public: |
19 class Delegate { | 19 class Delegate { |
20 public: | 20 public: |
21 Delegate() { } | 21 Delegate() { } |
22 virtual ~Delegate() { } | 22 virtual ~Delegate() { } |
23 | 23 |
24 virtual bool RunOnPluginThread( | 24 virtual bool RunOnPluginThread( |
25 base::TimeDelta delay, void(function)(void*), void* data) = 0; | 25 base::TimeDelta delay, void(function)(void*), void* data) = 0; |
26 }; | 26 }; |
27 | 27 |
28 // Caller keeps ownership of delegate. | 28 // Caller keeps ownership of delegate. |
29 PluginMessageLoopProxy(Delegate* delegate); | 29 PluginMessageLoopProxy(Delegate* delegate); |
30 virtual ~PluginMessageLoopProxy(); | |
31 | 30 |
32 void Detach(); | 31 void Detach(); |
33 | 32 |
34 // base::MessageLoopProxy implementation. | 33 // base::MessageLoopProxy implementation. |
35 virtual bool PostDelayedTask( | 34 virtual bool PostDelayedTask( |
36 const tracked_objects::Location& from_here, | 35 const tracked_objects::Location& from_here, |
37 const base::Closure& task, | 36 const base::Closure& task, |
38 int64 delay_ms) OVERRIDE; | 37 int64 delay_ms) OVERRIDE; |
39 virtual bool PostDelayedTask( | 38 virtual bool PostDelayedTask( |
40 const tracked_objects::Location& from_here, | 39 const tracked_objects::Location& from_here, |
41 const base::Closure& task, | 40 const base::Closure& task, |
42 base::TimeDelta delay) OVERRIDE; | 41 base::TimeDelta delay) OVERRIDE; |
43 virtual bool PostNonNestableDelayedTask( | 42 virtual bool PostNonNestableDelayedTask( |
44 const tracked_objects::Location& from_here, | 43 const tracked_objects::Location& from_here, |
45 const base::Closure& task, | 44 const base::Closure& task, |
46 int64 delay_ms) OVERRIDE; | 45 int64 delay_ms) OVERRIDE; |
47 virtual bool PostNonNestableDelayedTask( | 46 virtual bool PostNonNestableDelayedTask( |
48 const tracked_objects::Location& from_here, | 47 const tracked_objects::Location& from_here, |
49 const base::Closure& task, | 48 const base::Closure& task, |
50 base::TimeDelta delay) OVERRIDE; | 49 base::TimeDelta delay) OVERRIDE; |
51 | 50 |
52 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | 51 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
53 | 52 |
| 53 protected: |
| 54 virtual ~PluginMessageLoopProxy(); |
| 55 |
54 private: | 56 private: |
55 static void TaskSpringboard(void* data); | 57 static void TaskSpringboard(void* data); |
56 | 58 |
57 void RunClosureIf(const base::Closure& task); | 59 void RunClosureIf(const base::Closure& task); |
58 | 60 |
59 base::PlatformThreadId plugin_thread_id_; | 61 base::PlatformThreadId plugin_thread_id_; |
60 | 62 |
61 // |lock_| must be acquired when accessing |delegate_|. | 63 // |lock_| must be acquired when accessing |delegate_|. |
62 base::Lock lock_; | 64 base::Lock lock_; |
63 Delegate* delegate_; | 65 Delegate* delegate_; |
64 | 66 |
65 DISALLOW_COPY_AND_ASSIGN(PluginMessageLoopProxy); | 67 DISALLOW_COPY_AND_ASSIGN(PluginMessageLoopProxy); |
66 }; | 68 }; |
67 | 69 |
68 } // namespace remoting | 70 } // namespace remoting |
69 | 71 |
70 #endif // REMOTING_BASE_PLUGIN_MESSAGE_LOOP_H_ | 72 #endif // REMOTING_BASE_PLUGIN_MESSAGE_LOOP_H_ |
OLD | NEW |