diff options
author | sergeyu <sergeyu@chromium.org> | 2015-10-20 17:22:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-21 00:22:39 +0000 |
commit | 815bc8f7727e03d4e66d19462bfca9d943be1198 (patch) | |
tree | 0a8f853106ba1fa495a1c33d0116942baf55f84d /remoting/client/plugin | |
parent | 20550da3be779194f3d7eb2475cd5bb07e4894aa (diff) | |
download | chromium_src-815bc8f7727e03d4e66d19462bfca9d943be1198.zip chromium_src-815bc8f7727e03d4e66d19462bfca9d943be1198.tar.gz chromium_src-815bc8f7727e03d4e66d19462bfca9d943be1198.tar.bz2 |
Replace PluginThreadTaskRunner with a simpler MainPluginThreadTaskRunner.
PluginThreadTaskRunner was designed to work with NPAPI and PPAPI, but
it's no longer necessary. Replacing it with MainPluginThreadTaskRunner
that's Pepper-specific and is much simpler.
BUG=544275
Review URL: https://codereview.chromium.org/1410923004
Cr-Commit-Position: refs/heads/master@{#355200}
Diffstat (limited to 'remoting/client/plugin')
6 files changed, 97 insertions, 71 deletions
diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc index 755b46fed..39a5595 100644 --- a/remoting/client/plugin/chromoting_instance.cc +++ b/remoting/client/plugin/chromoting_instance.cc @@ -42,6 +42,7 @@ #include "remoting/client/normalizing_input_filter_mac.h" #include "remoting/client/plugin/delegating_signal_strategy.h" #include "remoting/client/plugin/pepper_audio_player.h" +#include "remoting/client/plugin/pepper_main_thread_task_runner.h" #include "remoting/client/plugin/pepper_mouse_locker.h" #include "remoting/client/plugin/pepper_port_allocator.h" #include "remoting/client/plugin/pepper_video_renderer_2d.h" @@ -137,7 +138,7 @@ base::LazyInstance<base::Lock>::Leaky g_logging_lock = ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) : pp::Instance(pp_instance), initialized_(false), - plugin_task_runner_(new PluginThreadTaskRunner(&plugin_thread_delegate_)), + plugin_task_runner_(new PepperMainThreadTaskRunner()), context_(plugin_task_runner_.get()), input_tracker_(&mouse_input_filter_), touch_input_scaler_(&input_tracker_), @@ -192,11 +193,6 @@ ChromotingInstance::~ChromotingInstance() { // to it. This will stop all logging in all Chromoting instances. UnregisterLoggingInstance(); - plugin_task_runner_->Quit(); - - // Ensure that nothing touches the plugin thread delegate after this point. - plugin_task_runner_->DetachAndRunShutdownLoop(); - // Stopping the context shuts down all chromoting threads. context_.Stop(); } diff --git a/remoting/client/plugin/chromoting_instance.h b/remoting/client/plugin/chromoting_instance.h index a07ecf6..9339ded 100644 --- a/remoting/client/plugin/chromoting_instance.h +++ b/remoting/client/plugin/chromoting_instance.h @@ -22,7 +22,6 @@ #include "remoting/client/key_event_mapper.h" #include "remoting/client/plugin/pepper_cursor_setter.h" #include "remoting/client/plugin/pepper_input_handler.h" -#include "remoting/client/plugin/pepper_plugin_thread_delegate.h" #include "remoting/client/plugin/pepper_video_renderer.h" #include "remoting/client/touch_input_scaler.h" #include "remoting/proto/event.pb.h" @@ -243,8 +242,7 @@ class ChromotingInstance : public ClientUserInterface, bool initialized_; - PepperPluginThreadDelegate plugin_thread_delegate_; - scoped_refptr<PluginThreadTaskRunner> plugin_task_runner_; + scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_; scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; scoped_ptr<jingle_glue::JingleThreadWrapper> thread_wrapper_; ClientContext context_; diff --git a/remoting/client/plugin/pepper_main_thread_task_runner.cc b/remoting/client/plugin/pepper_main_thread_task_runner.cc new file mode 100644 index 0000000..9dade17 --- /dev/null +++ b/remoting/client/plugin/pepper_main_thread_task_runner.cc @@ -0,0 +1,43 @@ +// Copyright 2015 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/client/plugin/pepper_main_thread_task_runner.h" + +#include "base/bind.h" +#include "ppapi/cpp/core.h" + +namespace remoting { + +PepperMainThreadTaskRunner::PepperMainThreadTaskRunner() + : core_(pp::Module::Get()->core()), callback_factory_(this) {} + +bool PepperMainThreadTaskRunner::PostDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, + base::TimeDelta delay) { + core_->CallOnMainThread(delay.InMillisecondsRoundedUp(), + callback_factory_.NewCallback( + &PepperMainThreadTaskRunner::RunTask, task)); + return true; +} + +bool PepperMainThreadTaskRunner::PostNonNestableDelayedTask( + const tracked_objects::Location& from_here, + const base::Closure& task, + base::TimeDelta delay) { + return PostDelayedTask(from_here, task, delay); +} + +bool PepperMainThreadTaskRunner::RunsTasksOnCurrentThread() const { + return core_->IsMainThread(); +} + +PepperMainThreadTaskRunner::~PepperMainThreadTaskRunner() {} + +void PepperMainThreadTaskRunner::RunTask(int32_t result, + const base::Closure& task) { + task.Run(); +} + +} // namespace remoting diff --git a/remoting/client/plugin/pepper_main_thread_task_runner.h b/remoting/client/plugin/pepper_main_thread_task_runner.h new file mode 100644 index 0000000..a6e839a --- /dev/null +++ b/remoting/client/plugin/pepper_main_thread_task_runner.h @@ -0,0 +1,51 @@ +// Copyright 2015 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_CLIENT_PLUGIN_PEPPER_MAIN_THREAD_TASK_RUNNER_H_ +#define REMOTING_CLIENT_PLUGIN_PEPPER_MAIN_THREAD_TASK_RUNNER_H_ + +#include "base/callback_forward.h" +#include "base/compiler_specific.h" +#include "base/macros.h" +#include "base/single_thread_task_runner.h" +#include "base/time/time.h" +#include "ppapi/utility/completion_callback_factory.h" + +namespace pp { +class Core; +} // namespace pp + +namespace remoting { + +// SingleThreadTaskRunner implementation for the main plugin thread. +class PepperMainThreadTaskRunner : public base::SingleThreadTaskRunner { + public: + PepperMainThreadTaskRunner(); + + // base::SingleThreadTaskRunner interface. + bool PostDelayedTask(const tracked_objects::Location& from_here, + const base::Closure& task, + base::TimeDelta delay) override; + bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, + const base::Closure& task, + base::TimeDelta delay) override; + bool RunsTasksOnCurrentThread() const override; + + protected: + ~PepperMainThreadTaskRunner() override; + + private: + // Helper that allows a base::Closure to be used as a pp::CompletionCallback, + // by ignoring the completion result. + void RunTask(int32_t result, const base::Closure& task); + + pp::Core* core_; + pp::CompletionCallbackFactory<PepperMainThreadTaskRunner> callback_factory_; + + DISALLOW_COPY_AND_ASSIGN(PepperMainThreadTaskRunner); +}; + +} // namespace remoting + +#endif // REMOTING_CLIENT_PLUGIN_PEPPER_MAIN_THREAD_TASK_RUNNER_H_ diff --git a/remoting/client/plugin/pepper_plugin_thread_delegate.cc b/remoting/client/plugin/pepper_plugin_thread_delegate.cc deleted file mode 100644 index e14a93c..0000000 --- a/remoting/client/plugin/pepper_plugin_thread_delegate.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2012 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/client/plugin/pepper_plugin_thread_delegate.h" - -#include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/module.h" - -namespace remoting { - -PepperPluginThreadDelegate::PepperPluginThreadDelegate() - : core_(pp::Module::Get()->core()) { -} - -PepperPluginThreadDelegate::~PepperPluginThreadDelegate() { } - -bool PepperPluginThreadDelegate::RunOnPluginThread( - base::TimeDelta delay, void(CDECL function)(void*), void* data) { - // It is safe to cast |function| to PP_CompletionCallback_Func, - // which is defined as void(*)(void*, int). The callee will just - // ignore the last argument. The only case when it may be unsafe is - // with VS when default calling convention is set to __stdcall, but - // this code will not typecheck in that case. - core_->CallOnMainThread( - delay.InMilliseconds(), pp::CompletionCallback( - reinterpret_cast<PP_CompletionCallback_Func>(function), data), 0); - return true; -} - -} // namespace remoting diff --git a/remoting/client/plugin/pepper_plugin_thread_delegate.h b/remoting/client/plugin/pepper_plugin_thread_delegate.h deleted file mode 100644 index eb6ddb3..0000000 --- a/remoting/client/plugin/pepper_plugin_thread_delegate.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2012 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_CLIENT_PLUGIN_PEPPER_PLUGIN_THREAD_DELEGATE_H_ -#define REMOTING_CLIENT_PLUGIN_PEPPER_PLUGIN_THREAD_DELEGATE_H_ - -#include "remoting/base/plugin_thread_task_runner.h" - -namespace pp { -class Core; -} // namespace pp - -namespace remoting { - -class PepperPluginThreadDelegate : public PluginThreadTaskRunner::Delegate { - public: - PepperPluginThreadDelegate(); - ~PepperPluginThreadDelegate() override; - - bool RunOnPluginThread(base::TimeDelta delay, - void(CDECL function)(void*), - void* data) override; - - private: - pp::Core* core_; -}; - -} // namespace remoting - -#endif // REMOTING_CLIENT_PLUGIN_PEPPER_PLUGIN_THREAD_DELEGATE_H_ |