Chromium Code Reviews| Index: remoting/base/plugin_message_loop_proxy.cc |
| diff --git a/remoting/base/plugin_message_loop_proxy.cc b/remoting/base/plugin_message_loop_proxy.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4ea94d95004253c5de767bab9733bdbf4ff294b9 |
| --- /dev/null |
| +++ b/remoting/base/plugin_message_loop_proxy.cc |
| @@ -0,0 +1,109 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/base/plugin_message_loop_proxy.h" |
| + |
| +namespace remoting { |
| + |
| +PluginMessageLoopProxy::PluginMessageLoopProxy(Delegate* delegate) |
| + : delegate_(delegate) { |
| +} |
| + |
| +PluginMessageLoopProxy::~PluginMessageLoopProxy() { |
| +} |
| + |
| +void PluginMessageLoopProxy::Detach() { |
| + base::AutoLock auto_lock(lock_); |
| + delegate_ = NULL; |
| +} |
| + |
| +// MessageLoopProxy interface implementation. |
| +bool PluginMessageLoopProxy::PostTask( |
| + const tracked_objects::Location& from_here, |
| + Task* task) { |
| + return PostDelayedTask(from_here, task, 0); |
| +} |
| + |
| +bool PluginMessageLoopProxy::PostDelayedTask( |
| + const tracked_objects::Location& from_here, |
| + Task* task, |
| + int64 delay_ms) { |
| + base::AutoLock auto_lock(lock_); |
| + if (!delegate_) { |
| + return false; |
| + } else { |
| + return delegate_->RunOnPluginThread( |
| + delay_ms, &PluginMessageLoopProxy::RunTask, task); |
| + } |
| +} |
| + |
| +bool PluginMessageLoopProxy::PostNonNestableTask( |
| + const tracked_objects::Location& from_here, |
| + Task* task) { |
| + // All tasks running on this message loop are non-nestable. |
| + return PostTask(from_here, task); |
|
awong
2011/08/12 21:15:26
I'm not certain we should even allow this API to b
Sergey Ulanov
2011/08/12 22:45:26
That is right, but tasks scheduled with this proxy
|
| +} |
| + |
| +bool PluginMessageLoopProxy::PostNonNestableDelayedTask( |
| + const tracked_objects::Location& from_here, |
| + Task* task, |
| + int64 delay_ms) { |
| + // All tasks running on this message loop are non-nestable. |
| + return PostDelayedTask(from_here, task, delay_ms); |
| +} |
| + |
| +bool PluginMessageLoopProxy::PostTask( |
| + const tracked_objects::Location& from_here, |
| + const base::Closure& task) { |
| + return PostDelayedTask(from_here, task, 0); |
| +} |
| + |
| +bool PluginMessageLoopProxy::PostDelayedTask( |
| + const tracked_objects::Location& from_here, |
| + const base::Closure& task, |
| + int64 delay_ms) { |
| + base::AutoLock auto_lock(lock_); |
| + if (!delegate_) { |
| + return false; |
| + } else { |
| + base::Closure* task_in_heap = new base::Closure(task); |
|
awong
2011/08/12 21:15:26
task_in_heap -> task_on_heap
Sergey Ulanov
2011/08/12 22:45:26
Done.
|
| + return delegate_->RunOnPluginThread( |
| + delay_ms, &PluginMessageLoopProxy::RunClosure, task_in_heap); |
| + } |
| +} |
| + |
| +bool PluginMessageLoopProxy::PostNonNestableTask( |
| + const tracked_objects::Location& from_here, |
| + const base::Closure& task) { |
| + // All tasks running on this message loop are non-nestable. |
| + return PostTask(from_here, task); |
| +} |
| + |
| +bool PluginMessageLoopProxy::PostNonNestableDelayedTask( |
| + const tracked_objects::Location& from_here, |
| + const base::Closure& task, |
| + int64 delay_ms) { |
| + // All tasks running on this message loop are non-nestable. |
| + return PostDelayedTask(from_here, task, delay_ms); |
| +} |
| + |
| +bool PluginMessageLoopProxy::BelongsToCurrentThread() { |
| + return delegate_->IsPluginThread(); |
| +} |
| + |
| +// static |
| +void PluginMessageLoopProxy::RunTask(void* data) { |
| + Task* task = reinterpret_cast<Task*>(data); |
| + task->Run(); |
| + delete task; |
| +} |
| + |
| +// static |
| +void PluginMessageLoopProxy::RunClosure(void* data) { |
| + base::Closure* task = reinterpret_cast<base::Closure*>(data); |
| + task->Run(); |
| + delete task; |
| +} |
| + |
| +} // namespace remoting |