Commit 89f96d35 authored by sergeyu@chromium.org's avatar sergeyu@chromium.org

Replace PluginMessageLoopProxy with PluginThreadTaskRunner.

Previosly plugin code was using PluginMessageLoopProxy that implements
MessageLoopProxy interface. We no longer need MessageLoopProxy.
Replacing PluginMessageLoopProxy with PluginThreadTaskRunner that
implements SingleThreadTaskRunner interface


Review URL: https://chromiumcodereview.appspot.com/10830016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148801 0039d316-1c4b-4281-b951-d872f2087c98
parent c7e526f8
......@@ -2,21 +2,21 @@
// 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"
#include "remoting/base/plugin_thread_task_runner.h"
#include "base/bind.h"
namespace remoting {
PluginMessageLoopProxy::PluginMessageLoopProxy(Delegate* delegate)
PluginThreadTaskRunner::PluginThreadTaskRunner(Delegate* delegate)
: plugin_thread_id_(base::PlatformThread::CurrentId()),
delegate_(delegate) {
}
PluginMessageLoopProxy::~PluginMessageLoopProxy() {
PluginThreadTaskRunner::~PluginThreadTaskRunner() {
}
void PluginMessageLoopProxy::Detach() {
void PluginThreadTaskRunner::Detach() {
base::AutoLock auto_lock(lock_);
if (delegate_) {
DCHECK(BelongsToCurrentThread());
......@@ -24,7 +24,7 @@ void PluginMessageLoopProxy::Detach() {
}
}
bool PluginMessageLoopProxy::PostDelayedTask(
bool PluginThreadTaskRunner::PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
......@@ -33,12 +33,12 @@ bool PluginMessageLoopProxy::PostDelayedTask(
return false;
base::Closure* springpad_closure = new base::Closure(base::Bind(
&PluginMessageLoopProxy::RunClosureIf, this, task));
&PluginThreadTaskRunner::RunClosureIf, this, task));
return delegate_->RunOnPluginThread(
delay, &PluginMessageLoopProxy::TaskSpringboard, springpad_closure);
delay, &PluginThreadTaskRunner::TaskSpringboard, springpad_closure);
}
bool PluginMessageLoopProxy::PostNonNestableDelayedTask(
bool PluginThreadTaskRunner::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
......@@ -46,7 +46,7 @@ bool PluginMessageLoopProxy::PostNonNestableDelayedTask(
return PostDelayedTask(from_here, task, delay);
}
bool PluginMessageLoopProxy::RunsTasksOnCurrentThread() const {
bool PluginThreadTaskRunner::RunsTasksOnCurrentThread() const {
// In pepper plugins ideally we should use pp::Core::IsMainThread,
// but it is problematic because we would need to keep reference to
// Core somewhere, e.g. make the delegate ref-counted.
......@@ -54,13 +54,13 @@ bool PluginMessageLoopProxy::RunsTasksOnCurrentThread() const {
}
// static
void PluginMessageLoopProxy::TaskSpringboard(void* data) {
void PluginThreadTaskRunner::TaskSpringboard(void* data) {
base::Closure* task = reinterpret_cast<base::Closure*>(data);
task->Run();
delete task;
}
void PluginMessageLoopProxy::RunClosureIf(const base::Closure& task) {
void PluginThreadTaskRunner::RunClosureIf(const base::Closure& task) {
// |delegate_| can be changed only from our thread, so it's safe to
// access it without acquiring |lock_|.
if (delegate_)
......
......@@ -2,19 +2,19 @@
// 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_
#ifndef REMOTING_BASE_PLUGIN_THREAD_TASK_RUNNER_H_
#define REMOTING_BASE_PLUGIN_THREAD_TASK_RUNNER_H_
#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/message_loop_proxy.h"
#include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
namespace remoting {
// MessageLoopProxy for plugin main threads.
class PluginMessageLoopProxy : public base::MessageLoopProxy {
// SingleThreadTaskRunner for plugin main threads.
class PluginThreadTaskRunner : public base::SingleThreadTaskRunner {
public:
class Delegate {
public:
......@@ -26,11 +26,11 @@ class PluginMessageLoopProxy : public base::MessageLoopProxy {
};
// Caller keeps ownership of delegate.
PluginMessageLoopProxy(Delegate* delegate);
PluginThreadTaskRunner(Delegate* delegate);
void Detach();
// base::MessageLoopProxy implementation.
// base::SingleThreadTaskRunner interface.
virtual bool PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
......@@ -43,7 +43,7 @@ class PluginMessageLoopProxy : public base::MessageLoopProxy {
virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
protected:
virtual ~PluginMessageLoopProxy();
virtual ~PluginThreadTaskRunner();
private:
static void TaskSpringboard(void* data);
......@@ -56,9 +56,9 @@ class PluginMessageLoopProxy : public base::MessageLoopProxy {
base::Lock lock_;
Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(PluginMessageLoopProxy);
DISALLOW_COPY_AND_ASSIGN(PluginThreadTaskRunner);
};
} // namespace remoting
#endif // REMOTING_BASE_PLUGIN_MESSAGE_LOOP_H_
#endif // REMOTING_BASE_PLUGIN_THREAD_TASK_RUNNER_H_
......@@ -152,9 +152,9 @@ bool ChromotingInstance::ParseAuthMethods(const std::string& auth_methods_str,
ChromotingInstance::ChromotingInstance(PP_Instance pp_instance)
: pp::Instance(pp_instance),
initialized_(false),
plugin_message_loop_(
new PluginMessageLoopProxy(&plugin_thread_delegate_)),
context_(plugin_message_loop_),
plugin_task_runner_(
new PluginThreadTaskRunner(&plugin_thread_delegate_)),
context_(plugin_task_runner_),
weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL);
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
......@@ -171,7 +171,7 @@ ChromotingInstance::ChromotingInstance(PP_Instance pp_instance)
}
ChromotingInstance::~ChromotingInstance() {
DCHECK(plugin_message_loop_->BelongsToCurrentThread());
DCHECK(plugin_task_runner_->BelongsToCurrentThread());
// Unregister this instance so that debug log messages will no longer be sent
// to it. This will stop all logging in all Chromoting instances.
......@@ -191,7 +191,7 @@ ChromotingInstance::~ChromotingInstance() {
context_.Stop();
// Ensure that nothing touches the plugin thread delegate after this point.
plugin_message_loop_->Detach();
plugin_task_runner_->Detach();
}
bool ChromotingInstance::Init(uint32_t argc,
......@@ -223,7 +223,7 @@ bool ChromotingInstance::Init(uint32_t argc,
// RectangleUpdateDecoder runs on a separate thread so for now we wrap
// PepperView with a ref-counted proxy object.
scoped_refptr<FrameConsumerProxy> consumer_proxy =
new FrameConsumerProxy(plugin_message_loop_);
new FrameConsumerProxy(plugin_task_runner_);
rectangle_decoder_ = new RectangleUpdateDecoder(
context_.decode_task_runner(), consumer_proxy);
view_.reset(new PepperView(this, &context_, rectangle_decoder_.get()));
......@@ -342,7 +342,7 @@ void ChromotingInstance::HandleMessage(const pp::Var& message) {
}
void ChromotingInstance::DidChangeView(const pp::View& view) {
DCHECK(plugin_message_loop_->BelongsToCurrentThread());
DCHECK(plugin_task_runner_->BelongsToCurrentThread());
view_->SetView(view);
......@@ -352,7 +352,7 @@ void ChromotingInstance::DidChangeView(const pp::View& view) {
}
bool ChromotingInstance::HandleInputEvent(const pp::InputEvent& event) {
DCHECK(plugin_message_loop_->BelongsToCurrentThread());
DCHECK(plugin_task_runner_->BelongsToCurrentThread());
if (!IsConnected())
return false;
......@@ -465,7 +465,7 @@ void ChromotingInstance::OnFirstFrameReceived() {
}
void ChromotingInstance::Connect(const ClientConfig& config) {
DCHECK(plugin_message_loop_->BelongsToCurrentThread());
DCHECK(plugin_task_runner_->BelongsToCurrentThread());
jingle_glue::JingleThreadWrapper::EnsureForCurrentThread();
......@@ -501,7 +501,7 @@ void ChromotingInstance::Connect(const ClientConfig& config) {
// Setup the XMPP Proxy.
xmpp_proxy_ = new PepperXmppProxy(
base::Bind(&ChromotingInstance::SendOutgoingIq, AsWeakPtr()),
plugin_message_loop_, context_.main_task_runner());
plugin_task_runner_, context_.main_task_runner());
scoped_ptr<cricket::HttpPortAllocatorBase> port_allocator(
PepperPortAllocator::Create(this));
......@@ -512,13 +512,13 @@ void ChromotingInstance::Connect(const ClientConfig& config) {
client_->Start(xmpp_proxy_, transport_factory.Pass());
// Start timer that periodically sends perf stats.
plugin_message_loop_->PostDelayedTask(
plugin_task_runner_->PostDelayedTask(
FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, AsWeakPtr()),
base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs));
}
void ChromotingInstance::Disconnect() {
DCHECK(plugin_message_loop_->BelongsToCurrentThread());
DCHECK(plugin_task_runner_->BelongsToCurrentThread());
// PepperView must be destroyed before the client.
view_.reset();
......@@ -630,7 +630,7 @@ void ChromotingInstance::SendPerfStats() {
return;
}
plugin_message_loop_->PostDelayedTask(
plugin_task_runner_->PostDelayedTask(
FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, AsWeakPtr()),
base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs));
......@@ -668,7 +668,7 @@ void ChromotingInstance::RegisterLoggingInstance() {
// If multiple plugins are run, then the last one registered will handle all
// logging for all instances.
g_logging_instance.Get() = weak_factory_.GetWeakPtr();
g_logging_task_runner.Get() = plugin_message_loop_;
g_logging_task_runner.Get() = plugin_task_runner_;
g_has_logging_instance = true;
}
......@@ -735,7 +735,7 @@ bool ChromotingInstance::LogToUI(int severity, const char* file, int line,
}
void ChromotingInstance::ProcessLogToUI(const std::string& message) {
DCHECK(plugin_message_loop_->BelongsToCurrentThread());
DCHECK(plugin_task_runner_->BelongsToCurrentThread());
// This flag (which is set only here) is used to prevent LogToUI from posting
// new tasks while we're in the middle of servicing a LOG call. This can
......
......@@ -185,7 +185,7 @@ class ChromotingInstance :
bool initialized_;
PepperPluginThreadDelegate plugin_thread_delegate_;
scoped_refptr<PluginMessageLoopProxy> plugin_message_loop_;
scoped_refptr<PluginThreadTaskRunner> plugin_task_runner_;
ClientContext context_;
scoped_ptr<protocol::ConnectionToHost> host_connection_;
scoped_ptr<PepperView> view_;
......
......@@ -5,7 +5,7 @@
#ifndef REMOTING_CLIENT_PLUGIN_PEPPER_PLUGIN_THREAD_DELEGATE_H_
#define REMOTING_CLIENT_PLUGIN_PEPPER_PLUGIN_THREAD_DELEGATE_H_
#include "remoting/base/plugin_message_loop_proxy.h"
#include "remoting/base/plugin_thread_task_runner.h"
// Macro useful for writing cross-platform function pointers.
#if defined(OS_WIN) && !defined(CDECL)
......@@ -20,7 +20,7 @@ class Core;
namespace remoting {
class PepperPluginThreadDelegate : public PluginMessageLoopProxy::Delegate {
class PepperPluginThreadDelegate : public PluginThreadTaskRunner::Delegate {
public:
PepperPluginThreadDelegate();
virtual ~PepperPluginThreadDelegate();
......
......@@ -13,7 +13,7 @@
#include "base/logging.h"
#include "base/stringize_macros.h"
#include "net/socket/ssl_server_socket.h"
#include "remoting/base/plugin_message_loop_proxy.h"
#include "remoting/base/plugin_thread_task_runner.h"
#include "remoting/host/plugin/constants.h"
#include "remoting/host/plugin/host_log_handler.h"
#include "remoting/host/plugin/host_plugin_utils.h"
......@@ -57,7 +57,7 @@ base::AtExitManager* g_at_exit_manager = NULL;
// NPAPI plugin implementation for remoting host.
// Documentation for most of the calls in this class can be found here:
// https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Scripting_plugins
class HostNPPlugin : public remoting::PluginMessageLoopProxy::Delegate {
class HostNPPlugin : public remoting::PluginThreadTaskRunner::Delegate {
public:
// |mode| is the display mode of plug-in. Values:
// NP_EMBED: (1) Instance was created by an EMBED tag and shares the browser
......@@ -148,7 +148,7 @@ class HostNPPlugin : public remoting::PluginMessageLoopProxy::Delegate {
return scriptable_object_;
}
// PluginMessageLoopProxy::Delegate implementation.
// PluginThreadTaskRunner::Delegate implementation.
virtual bool RunOnPluginThread(
base::TimeDelta delay, void(function)(void*), void* data) OVERRIDE {
if (delay == base::TimeDelta()) {
......
......@@ -79,14 +79,14 @@ const int kMaxWorkerPoolThreads = 2;
HostNPScriptObject::HostNPScriptObject(
NPP plugin,
NPObject* parent,
PluginMessageLoopProxy::Delegate* plugin_thread_delegate)
PluginThreadTaskRunner::Delegate* plugin_thread_delegate)
: plugin_(plugin),
parent_(parent),
am_currently_logging_(false),
state_(kDisconnected),
np_thread_id_(base::PlatformThread::CurrentId()),
plugin_task_runner_(
new PluginMessageLoopProxy(plugin_thread_delegate)),
new PluginThreadTaskRunner(plugin_thread_delegate)),
failed_login_attempts_(0),
disconnected_event_(true, false),
nat_traversal_enabled_(false),
......
......@@ -18,7 +18,7 @@
#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
#include "base/time.h"
#include "remoting/base/plugin_message_loop_proxy.h"
#include "remoting/base/plugin_thread_task_runner.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/host_key_pair.h"
#include "remoting/host/host_status_observer.h"
......@@ -51,7 +51,7 @@ class PolicyWatcher;
class HostNPScriptObject : public HostStatusObserver {
public:
HostNPScriptObject(NPP plugin, NPObject* parent,
PluginMessageLoopProxy::Delegate* plugin_thread_delegate);
PluginThreadTaskRunner::Delegate* plugin_thread_delegate);
virtual ~HostNPScriptObject();
bool Init();
......@@ -302,7 +302,7 @@ class HostNPScriptObject : public HostStatusObserver {
ScopedRefNPObject on_nat_traversal_policy_changed_func_;
ScopedRefNPObject on_state_changed_func_;
base::PlatformThreadId np_thread_id_;
scoped_refptr<PluginMessageLoopProxy> plugin_task_runner_;
scoped_refptr<PluginThreadTaskRunner> plugin_task_runner_;
scoped_ptr<ChromotingHostContext> host_context_;
HostKeyPair host_key_pair_;
......
......@@ -1107,8 +1107,8 @@
'base/encoder_vp8.h',
'base/encoder_row_based.cc',
'base/encoder_row_based.h',
'base/plugin_message_loop_proxy.cc',
'base/plugin_message_loop_proxy.h',
'base/plugin_thread_task_runner.cc',
'base/plugin_thread_task_runner.h',
'base/rate_counter.cc',
'base/rate_counter.h',
'base/running_average.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment