diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 19:26:21 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 19:26:21 +0000 |
commit | 00b0e0048bacda3600b47ccb09fb24712e93a145 (patch) | |
tree | 5dc227c8cdd77afd62c1cca6143626170eb71403 /remoting/host | |
parent | 8b740120a98dea710146d8a0ec2bc8062a673128 (diff) | |
download | chromium_src-00b0e0048bacda3600b47ccb09fb24712e93a145.zip chromium_src-00b0e0048bacda3600b47ccb09fb24712e93a145.tar.gz chromium_src-00b0e0048bacda3600b47ccb09fb24712e93a145.tar.bz2 |
Don't use MessageLoop or MessageLoopProxy in EventExecutor.
Review URL: https://chromiumcodereview.appspot.com/10539056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141936 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/desktop_environment.cc | 14 | ||||
-rw-r--r-- | remoting/host/event_executor.h | 19 | ||||
-rw-r--r-- | remoting/host/event_executor_linux.cc | 29 | ||||
-rw-r--r-- | remoting/host/event_executor_mac.cc | 34 | ||||
-rw-r--r-- | remoting/host/event_executor_win.cc | 52 | ||||
-rw-r--r-- | remoting/host/simple_host_process.cc | 7 |
6 files changed, 80 insertions, 75 deletions
diff --git a/remoting/host/desktop_environment.cc b/remoting/host/desktop_environment.cc index 26921ac..7eb755d 100644 --- a/remoting/host/desktop_environment.cc +++ b/remoting/host/desktop_environment.cc @@ -20,10 +20,9 @@ namespace remoting { scoped_ptr<DesktopEnvironment> DesktopEnvironment::Create( ChromotingHostContext* context) { scoped_ptr<Capturer> capturer(Capturer::Create()); - scoped_ptr<EventExecutor> event_executor = - EventExecutor::Create(context->desktop_message_loop(), - context->ui_message_loop(), - capturer.get()); + scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( + context->desktop_message_loop()->message_loop_proxy(), + context->ui_message_loop(), capturer.get()); if (capturer.get() == NULL || event_executor.get() == NULL) { LOG(ERROR) << "Unable to create DesktopEnvironment"; @@ -40,10 +39,9 @@ scoped_ptr<DesktopEnvironment> DesktopEnvironment::Create( scoped_ptr<DesktopEnvironment> DesktopEnvironment::CreateForService( ChromotingHostContext* context) { scoped_ptr<Capturer> capturer(Capturer::Create()); - scoped_ptr<EventExecutor> event_executor = - EventExecutor::Create(context->desktop_message_loop(), - context->ui_message_loop(), - capturer.get()); + scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( + context->desktop_message_loop()->message_loop_proxy(), + context->ui_message_loop(), capturer.get()); if (capturer.get() == NULL || event_executor.get() == NULL) { LOG(ERROR) << "Unable to create DesktopEnvironment"; diff --git a/remoting/host/event_executor.h b/remoting/host/event_executor.h index d033915..dfc0ff2a 100644 --- a/remoting/host/event_executor.h +++ b/remoting/host/event_executor.h @@ -5,14 +5,13 @@ #ifndef REMOTING_HOST_EVENT_EXECUTOR_H_ #define REMOTING_HOST_EVENT_EXECUTOR_H_ +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "remoting/protocol/clipboard_stub.h" #include "remoting/protocol/host_event_stub.h" -class MessageLoop; - namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; } // namespace base namespace remoting { @@ -21,12 +20,14 @@ class Capturer; class EventExecutor : public protocol::HostEventStub { public: - // Creates a default event executor for the current platform. - // This object should do as much work as possible on |message_loop|, using - // |ui_loop| only when necessary. - static scoped_ptr<EventExecutor> Create(MessageLoop* message_loop, - base::MessageLoopProxy* ui_loop, - Capturer* capturer); + // Creates a default event executor for the current platform. This + // object should do as much work as possible on |main_task_runner|, + // using |ui_task_runner| only for tasks actually requiring a UI + // thread. + static scoped_ptr<EventExecutor> Create( + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + Capturer* capturer); // Initialises any objects needed to execute events. virtual void OnSessionStarted( diff --git a/remoting/host/event_executor_linux.cc b/remoting/host/event_executor_linux.cc index c438a3d..8c16fba 100644 --- a/remoting/host/event_executor_linux.cc +++ b/remoting/host/event_executor_linux.cc @@ -14,8 +14,9 @@ #include "base/basictypes.h" #include "base/bind.h" #include "base/compiler_specific.h" +#include "base/location.h" #include "base/logging.h" -#include "base/message_loop.h" +#include "base/single_thread_task_runner.h" #include "remoting/proto/internal.pb.h" namespace remoting { @@ -34,7 +35,7 @@ using protocol::MouseEvent; // A class to generate events on Linux. class EventExecutorLinux : public EventExecutor { public: - EventExecutorLinux(MessageLoop* message_loop); + EventExecutorLinux(scoped_refptr<base::SingleThreadTaskRunner> task_runner); virtual ~EventExecutorLinux(); bool Init(); @@ -59,7 +60,7 @@ class EventExecutorLinux : public EventExecutor { void SetAutoRepeatForKey(int keycode, int mode); void InjectScrollWheelClicks(int button, int count); - MessageLoop* message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; std::set<int> pressed_keys_; @@ -267,8 +268,9 @@ int ChromotocolKeycodeToX11Keysym(int32_t keycode) { return kUsVkeyToKeysym[keycode]; } -EventExecutorLinux::EventExecutorLinux(MessageLoop* message_loop) - : message_loop_(message_loop), +EventExecutorLinux::EventExecutorLinux( + scoped_refptr<base::SingleThreadTaskRunner> task_runner) + : task_runner_(task_runner), display_(XOpenDisplay(NULL)), root_window_(BadValue) { } @@ -306,8 +308,8 @@ void EventExecutorLinux::InjectKeyEvent(const KeyEvent& event) { // HostEventDispatcher should filter events missing the pressed field. DCHECK(event.has_pressed()); - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask( FROM_HERE, base::Bind(&EventExecutorLinux::InjectKeyEvent, base::Unretained(this), event)); @@ -375,8 +377,8 @@ void EventExecutorLinux::InjectScrollWheelClicks(int button, int count) { } void EventExecutorLinux::InjectMouseEvent(const MouseEvent& event) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask( FROM_HERE, base::Bind(&EventExecutorLinux::InjectMouseEvent, base::Unretained(this), event)); @@ -431,11 +433,12 @@ void EventExecutorLinux::OnSessionFinished() { } // namespace -scoped_ptr<EventExecutor> EventExecutor::Create(MessageLoop* message_loop, - base::MessageLoopProxy* ui_loop, - Capturer* capturer) { +scoped_ptr<EventExecutor> EventExecutor::Create( + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + Capturer* capturer) { scoped_ptr<EventExecutorLinux> executor( - new EventExecutorLinux(message_loop)); + new EventExecutorLinux(main_task_runner)); if (!executor->Init()) return scoped_ptr<EventExecutor>(NULL); return executor.PassAs<EventExecutor>(); diff --git a/remoting/host/event_executor_mac.cc b/remoting/host/event_executor_mac.cc index 32c9988..44b359a 100644 --- a/remoting/host/event_executor_mac.cc +++ b/remoting/host/event_executor_mac.cc @@ -10,8 +10,9 @@ #include "base/basictypes.h" #include "base/bind.h" #include "base/compiler_specific.h" +#include "base/location.h" #include "base/mac/scoped_cftyperef.h" -#include "base/message_loop.h" +#include "base/single_thread_task_runner.h" #include "remoting/host/clipboard.h" #include "remoting/proto/internal.pb.h" #include "remoting/protocol/message_decoder.h" @@ -33,7 +34,7 @@ using protocol::MouseEvent; // A class to generate events on Mac. class EventExecutorMac : public EventExecutor { public: - EventExecutorMac(MessageLoop* message_loop); + EventExecutorMac(scoped_refptr<base::SingleThreadTaskRunner> task_runner); virtual ~EventExecutorMac() {} // ClipboardStub interface. @@ -49,7 +50,7 @@ class EventExecutorMac : public EventExecutor { virtual void OnSessionFinished() OVERRIDE; private: - MessageLoop* message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; SkIPoint mouse_pos_; uint32 mouse_button_state_; scoped_ptr<Clipboard> clipboard_; @@ -57,8 +58,9 @@ class EventExecutorMac : public EventExecutor { DISALLOW_COPY_AND_ASSIGN(EventExecutorMac); }; -EventExecutorMac::EventExecutorMac(MessageLoop* message_loop) - : message_loop_(message_loop), +EventExecutorMac::EventExecutorMac( + scoped_refptr<base::SingleThreadTaskRunner> task_runner) + : task_runner_(task_runner), mouse_button_state_(0), clipboard_(Clipboard::Create()) { // Ensure that local hardware events are not suppressed after injecting @@ -255,8 +257,8 @@ const int kUsVkeyToKeysym[256] = { }; void EventExecutorMac::InjectClipboardEvent(const ClipboardEvent& event) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask( FROM_HERE, base::Bind(&EventExecutorMac::InjectClipboardEvent, base::Unretained(this), @@ -351,8 +353,8 @@ void EventExecutorMac::InjectMouseEvent(const MouseEvent& event) { void EventExecutorMac::OnSessionStarted( scoped_ptr<protocol::ClipboardStub> client_clipboard) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask( FROM_HERE, base::Bind(&EventExecutorMac::OnSessionStarted, base::Unretained(this), @@ -364,8 +366,8 @@ void EventExecutorMac::OnSessionStarted( } void EventExecutorMac::OnSessionFinished() { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask( FROM_HERE, base::Bind(&EventExecutorMac::OnSessionFinished, base::Unretained(this))); @@ -377,11 +379,11 @@ void EventExecutorMac::OnSessionFinished() { } // namespace -scoped_ptr<EventExecutor> EventExecutor::Create(MessageLoop* message_loop, - base::MessageLoopProxy* ui_loop, - Capturer* capturer) { - return scoped_ptr<EventExecutor>( - new EventExecutorMac(message_loop)); +scoped_ptr<EventExecutor> EventExecutor::Create( + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + Capturer* capturer) { + return scoped_ptr<EventExecutor>(new EventExecutorMac(main_task_runner)); } } // namespace remoting diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc index c4d6b7e..86db6bf 100644 --- a/remoting/host/event_executor_win.cc +++ b/remoting/host/event_executor_win.cc @@ -8,8 +8,8 @@ #include "base/bind.h" #include "base/compiler_specific.h" -#include "base/message_loop.h" -#include "base/message_loop_proxy.h" +#include "base/location.h" +#include "base/single_thread_task_runner.h" #include "remoting/host/capturer.h" #include "remoting/host/clipboard.h" #include "remoting/proto/event.pb.h" @@ -30,8 +30,8 @@ using protocol::MouseEvent; // A class to generate events on Windows. class EventExecutorWin : public EventExecutor { public: - EventExecutorWin(MessageLoop* message_loop, - base::MessageLoopProxy* ui_loop, + EventExecutorWin(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, Capturer* capturer); virtual ~EventExecutorWin() {} @@ -52,26 +52,27 @@ class EventExecutorWin : public EventExecutor { void HandleKey(const KeyEvent& event); void HandleMouse(const MouseEvent& event); - MessageLoop* message_loop_; - base::MessageLoopProxy* ui_loop_; + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; Capturer* capturer_; scoped_ptr<Clipboard> clipboard_; DISALLOW_COPY_AND_ASSIGN(EventExecutorWin); }; -EventExecutorWin::EventExecutorWin(MessageLoop* message_loop, - base::MessageLoopProxy* ui_loop, - Capturer* capturer) - : message_loop_(message_loop), - ui_loop_(ui_loop), +EventExecutorWin::EventExecutorWin( + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + Capturer* capturer) + : main_task_runner_(main_task_runner), + ui_task_runner_(ui_task_runner), capturer_(capturer), clipboard_(Clipboard::Create()) { } void EventExecutorWin::InjectClipboardEvent(const ClipboardEvent& event) { - if (!ui_loop_->BelongsToCurrentThread()) { - ui_loop_->PostTask( + if (!ui_task_runner_->BelongsToCurrentThread()) { + ui_task_runner_->PostTask( FROM_HERE, base::Bind(&EventExecutorWin::InjectClipboardEvent, base::Unretained(this), @@ -83,8 +84,8 @@ void EventExecutorWin::InjectClipboardEvent(const ClipboardEvent& event) { } void EventExecutorWin::InjectKeyEvent(const KeyEvent& event) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!main_task_runner_->BelongsToCurrentThread()) { + main_task_runner_->PostTask( FROM_HERE, base::Bind(&EventExecutorWin::InjectKeyEvent, base::Unretained(this), event)); @@ -95,8 +96,8 @@ void EventExecutorWin::InjectKeyEvent(const KeyEvent& event) { } void EventExecutorWin::InjectMouseEvent(const MouseEvent& event) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!main_task_runner_->BelongsToCurrentThread()) { + main_task_runner_->PostTask( FROM_HERE, base::Bind(&EventExecutorWin::InjectMouseEvent, base::Unretained(this), event)); @@ -108,8 +109,8 @@ void EventExecutorWin::InjectMouseEvent(const MouseEvent& event) { void EventExecutorWin::OnSessionStarted( scoped_ptr<protocol::ClipboardStub> client_clipboard) { - if (!ui_loop_->BelongsToCurrentThread()) { - ui_loop_->PostTask( + if (!ui_task_runner_->BelongsToCurrentThread()) { + ui_task_runner_->PostTask( FROM_HERE, base::Bind(&EventExecutorWin::OnSessionStarted, base::Unretained(this), @@ -121,8 +122,8 @@ void EventExecutorWin::OnSessionStarted( } void EventExecutorWin::OnSessionFinished() { - if (!ui_loop_->BelongsToCurrentThread()) { - ui_loop_->PostTask( + if (!ui_task_runner_->BelongsToCurrentThread()) { + ui_task_runner_->PostTask( FROM_HERE, base::Bind(&EventExecutorWin::OnSessionFinished, base::Unretained(this))); @@ -286,11 +287,12 @@ void EventExecutorWin::HandleMouse(const MouseEvent& event) { } // namespace -scoped_ptr<EventExecutor> EventExecutor::Create(MessageLoop* message_loop, - base::MessageLoopProxy* ui_loop, - Capturer* capturer) { +scoped_ptr<EventExecutor> EventExecutor::Create( + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + Capturer* capturer) { return scoped_ptr<EventExecutor>( - new EventExecutorWin(message_loop, ui_loop, capturer)); + new EventExecutorWin(main_task_runner, ui_task_runner, capturer)); } } // namespace remoting diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc index 58e3c5d..53cd897 100644 --- a/remoting/host/simple_host_process.cc +++ b/remoting/host/simple_host_process.cc @@ -222,10 +222,9 @@ class SimpleHost : public HeartbeatSender::Listener { if (fake_) { scoped_ptr<Capturer> capturer(new CapturerFake()); - scoped_ptr<EventExecutor> event_executor = - EventExecutor::Create(context_.desktop_message_loop(), - context_.ui_message_loop(), - capturer.get()); + scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( + context_.desktop_message_loop()->message_loop_proxy(), + context_.ui_message_loop(), capturer.get()); desktop_environment_ = DesktopEnvironment::CreateFake( &context_, capturer.Pass(), event_executor.Pass()); } else { |