OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/base/plugin_message_loop_proxy.h" | |
6 | |
7 namespace remoting { | |
8 | |
9 PluginMessageLoopProxy::PluginMessageLoopProxy(Delegate* delegate) | |
10 : delegate_(delegate) { | |
11 } | |
12 | |
13 PluginMessageLoopProxy::~PluginMessageLoopProxy() { | |
14 } | |
15 | |
16 void PluginMessageLoopProxy::Detach() { | |
17 base::AutoLock auto_lock(lock_); | |
18 delegate_ = NULL; | |
19 } | |
20 | |
21 // MessageLoopProxy interface implementation. | |
22 bool PluginMessageLoopProxy::PostTask( | |
23 const tracked_objects::Location& from_here, | |
24 Task* task) { | |
25 return PostDelayedTask(from_here, task, 0); | |
26 } | |
27 | |
28 bool PluginMessageLoopProxy::PostDelayedTask( | |
29 const tracked_objects::Location& from_here, | |
30 Task* task, | |
31 int64 delay_ms) { | |
32 base::AutoLock auto_lock(lock_); | |
33 if (!delegate_) { | |
34 return false; | |
35 } else { | |
36 return delegate_->RunOnPluginThread( | |
37 delay_ms, &PluginMessageLoopProxy::RunTask, task); | |
38 } | |
39 } | |
40 | |
41 bool PluginMessageLoopProxy::PostNonNestableTask( | |
42 const tracked_objects::Location& from_here, | |
43 Task* task) { | |
44 // All tasks running on this message loop are non-nestable. | |
45 return PostTask(from_here, task); | |
46 } | |
47 | |
48 bool PluginMessageLoopProxy::PostNonNestableDelayedTask( | |
49 const tracked_objects::Location& from_here, | |
50 Task* task, | |
51 int64 delay_ms) { | |
52 // All tasks running on this message loop are non-nestable. | |
53 return PostDelayedTask(from_here, task, delay_ms); | |
54 } | |
55 | |
56 bool PluginMessageLoopProxy::PostTask( | |
57 const tracked_objects::Location& from_here, | |
58 const base::Closure& task) { | |
59 return PostDelayedTask(from_here, task, 0); | |
60 } | |
61 | |
62 bool PluginMessageLoopProxy::PostDelayedTask( | |
63 const tracked_objects::Location& from_here, | |
64 const base::Closure& task, | |
65 int64 delay_ms) { | |
66 base::AutoLock auto_lock(lock_); | |
67 if (!delegate_) { | |
68 return false; | |
69 } else { | |
70 base::Closure* task_on_heap = new base::Closure(task); | |
71 return delegate_->RunOnPluginThread( | |
72 delay_ms, &PluginMessageLoopProxy::RunClosure, task_on_heap); | |
73 } | |
74 } | |
75 | |
76 bool PluginMessageLoopProxy::PostNonNestableTask( | |
77 const tracked_objects::Location& from_here, | |
78 const base::Closure& task) { | |
79 // All tasks running on this message loop are non-nestable. | |
80 return PostTask(from_here, task); | |
81 } | |
82 | |
83 bool PluginMessageLoopProxy::PostNonNestableDelayedTask( | |
84 const tracked_objects::Location& from_here, | |
85 const base::Closure& task, | |
86 int64 delay_ms) { | |
87 // All tasks running on this message loop are non-nestable. | |
88 return PostDelayedTask(from_here, task, delay_ms); | |
89 } | |
90 | |
91 bool PluginMessageLoopProxy::BelongsToCurrentThread() { | |
92 base::AutoLock auto_lock(lock_); | |
93 if (delegate_) { | |
94 return delegate_->IsPluginThread(); | |
95 } else { | |
96 return false; | |
97 } | |
98 } | |
99 | |
100 // static | |
101 void PluginMessageLoopProxy::RunTask(void* data) { | |
102 Task* task = reinterpret_cast<Task*>(data); | |
103 task->Run(); | |
104 delete task; | |
105 } | |
106 | |
107 // static | |
108 void PluginMessageLoopProxy::RunClosure(void* data) { | |
109 base::Closure* task = reinterpret_cast<base::Closure*>(data); | |
110 task->Run(); | |
111 delete task; | |
112 } | |
113 | |
114 } // namespace remoting | |
OLD | NEW |