forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PluginMessageLoopProxy and use it for Host plugin UI thread.
The new class will also be used in the client plugin for the main plugin thread. BUG=None TEST=Everything works. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=96981 Review URL: http://codereview.chromium.org/7635030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97050 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
sergeyu@chromium.org
committed
Aug 16, 2011
1 parent
e04e824
commit 12835bf
Showing
14 changed files
with
316 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// 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); | ||
} | ||
|
||
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_on_heap = new base::Closure(task); | ||
return delegate_->RunOnPluginThread( | ||
delay_ms, &PluginMessageLoopProxy::RunClosure, task_on_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() { | ||
base::AutoLock auto_lock(lock_); | ||
if (delegate_) { | ||
return delegate_->IsPluginThread(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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. | ||
|
||
#ifndef REMOTING_BASE_PLUGIN_MESSAGE_LOOP_H_ | ||
#define REMOTING_BASE_PLUGIN_MESSAGE_LOOP_H_ | ||
|
||
#include "base/callback.h" | ||
#include "base/compiler_specific.h" | ||
#include "base/message_loop_proxy.h" | ||
|
||
namespace remoting { | ||
|
||
// MessageLoopProxy for plugin main threads. | ||
class PluginMessageLoopProxy : public base::MessageLoopProxy { | ||
public: | ||
class Delegate { | ||
public: | ||
Delegate() { } | ||
virtual ~Delegate() { } | ||
|
||
virtual bool RunOnPluginThread( | ||
int delay_ms, void(function)(void*), void* data) = 0; | ||
virtual bool IsPluginThread() = 0; | ||
}; | ||
|
||
// Caller keeps ownership of delegate. | ||
PluginMessageLoopProxy(Delegate* delegate); | ||
virtual ~PluginMessageLoopProxy(); | ||
|
||
void Detach(); | ||
|
||
// base::MessageLoopProxy interface. | ||
virtual bool PostTask( | ||
const tracked_objects::Location& from_here, | ||
Task* task) OVERRIDE; | ||
virtual bool PostDelayedTask( | ||
const tracked_objects::Location& from_here, | ||
Task* task, | ||
int64 delay_ms) OVERRIDE; | ||
virtual bool PostNonNestableTask( | ||
const tracked_objects::Location& from_here, | ||
Task* task) OVERRIDE; | ||
virtual bool PostNonNestableDelayedTask( | ||
const tracked_objects::Location& from_here, | ||
Task* task, | ||
int64 delay_ms) OVERRIDE; | ||
|
||
virtual bool PostTask( | ||
const tracked_objects::Location& from_here, | ||
const base::Closure& task) OVERRIDE; | ||
virtual bool PostDelayedTask( | ||
const tracked_objects::Location& from_here, | ||
const base::Closure& task, | ||
int64 delay_ms) OVERRIDE; | ||
virtual bool PostNonNestableTask( | ||
const tracked_objects::Location& from_here, | ||
const base::Closure& task) OVERRIDE; | ||
virtual bool PostNonNestableDelayedTask( | ||
const tracked_objects::Location& from_here, | ||
const base::Closure& task, | ||
int64 delay_ms) OVERRIDE; | ||
|
||
virtual bool BelongsToCurrentThread() OVERRIDE; | ||
|
||
private: | ||
// |lock_| must be acquired when accessing |delegate_|. | ||
base::Lock lock_; | ||
Delegate* delegate_; | ||
|
||
static void RunTask(void* data); | ||
static void RunClosure(void* data); | ||
|
||
DISALLOW_COPY_AND_ASSIGN(PluginMessageLoopProxy); | ||
}; | ||
|
||
} // namespace remoting | ||
|
||
#endif // REMOTING_BASE_PLUGIN_MESSAGE_LOOP_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.