Chromium Code Reviews| Index: remoting/host/event_executor_win.cc |
| diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc |
| index 007f31bd07a2a9040c539bb98ec8d7e29e835785..799b702843a72f7426157bb99b36feb2e13d0afc 100644 |
| --- a/remoting/host/event_executor_win.cc |
| +++ b/remoting/host/event_executor_win.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/bind.h" |
| #include "base/compiler_specific.h" |
| #include "base/message_loop.h" |
| +#include "base/message_loop_proxy.h" |
| #include "remoting/host/capturer.h" |
| #include "remoting/host/clipboard.h" |
| #include "remoting/proto/event.pb.h" |
| @@ -30,7 +31,9 @@ using protocol::MouseEvent; |
| // A class to generate events on Windows. |
| class EventExecutorWin : public EventExecutor { |
| public: |
| - EventExecutorWin(MessageLoop* message_loop, Capturer* capturer); |
| + EventExecutorWin(MessageLoop* message_loop, |
| + base::MessageLoopProxy* ui_loop, |
| + Capturer* capturer); |
| virtual ~EventExecutorWin() {} |
| // ClipboardStub interface. |
| @@ -46,12 +49,14 @@ class EventExecutorWin : public EventExecutor { |
| private: |
| HKL GetForegroundKeyboardLayout(); |
| + void HandleClipboard(const ClipboardEvent& event); |
| void HandleKey(const KeyEvent& event); |
| void HandleMouse(const MouseEvent& event); |
| void HandleSessionStarted(); |
| void HandleSessionFinished(); |
| MessageLoop* message_loop_; |
| + base::MessageLoopProxy* ui_loop_; |
| Capturer* capturer_; |
| scoped_ptr<Clipboard> clipboard_; |
| @@ -59,23 +64,20 @@ class EventExecutorWin : public EventExecutor { |
| }; |
| EventExecutorWin::EventExecutorWin(MessageLoop* message_loop, |
| + base::MessageLoopProxy* ui_loop, |
| Capturer* capturer) |
| : message_loop_(message_loop), |
| + ui_loop_(ui_loop), |
| capturer_(capturer), |
| clipboard_(Clipboard::Create()) { |
| } |
| void EventExecutorWin::InjectClipboardEvent(const ClipboardEvent& event) { |
| - if (MessageLoop::current() != message_loop_) { |
| - message_loop_->PostTask( |
| - FROM_HERE, |
| - base::Bind(&EventExecutorWin::InjectClipboardEvent, |
| - base::Unretained(this), |
| - event)); |
| - return; |
| - } |
| - |
| - clipboard_->InjectClipboardEvent(event); |
| + ui_loop_->PostTask( |
|
Wez
2012/05/15 23:46:19
You could test if (!ui_loop_->BelongsToCurrentThre
simonmorris
2012/05/16 00:41:33
Done. (I liked the consistency of having a separat
|
| + FROM_HERE, |
| + base::Bind(&EventExecutorWin::HandleClipboard, |
| + base::Unretained(this), |
|
Wez
2012/05/15 23:46:19
Doesn't this mean we risk a crash if a clipboard e
simonmorris
2012/05/16 00:41:33
No more than with InjectKeyEvent() and InjectMouse
|
| + event)); |
| } |
| void EventExecutorWin::InjectKeyEvent(const KeyEvent& event) { |
| @@ -103,27 +105,17 @@ void EventExecutorWin::InjectMouseEvent(const MouseEvent& event) { |
| } |
| void EventExecutorWin::OnSessionStarted() { |
| - if (MessageLoop::current() != message_loop_) { |
| - message_loop_->PostTask( |
| - FROM_HERE, |
| - base::Bind(&EventExecutorWin::OnSessionStarted, |
| - base::Unretained(this))); |
| - return; |
| - } |
| - |
| - HandleSessionStarted(); |
| + ui_loop_->PostTask( |
|
Wez
2012/05/15 23:46:19
As above, with an if (BelongsToCurrentThread()) te
simonmorris
2012/05/16 00:41:33
Done.
|
| + FROM_HERE, |
| + base::Bind(&EventExecutorWin::HandleSessionStarted, |
| + base::Unretained(this))); |
| } |
| void EventExecutorWin::OnSessionFinished() { |
| - if (MessageLoop::current() != message_loop_) { |
| - message_loop_->PostTask( |
| - FROM_HERE, |
| - base::Bind(&EventExecutorWin::OnSessionFinished, |
| - base::Unretained(this))); |
| - return; |
| - } |
| - |
| - HandleSessionFinished(); |
| + ui_loop_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&EventExecutorWin::HandleSessionFinished, |
| + base::Unretained(this))); |
| } |
| HKL EventExecutorWin::GetForegroundKeyboardLayout() { |
| @@ -149,6 +141,10 @@ HKL EventExecutorWin::GetForegroundKeyboardLayout() { |
| return layout; |
| } |
| +void EventExecutorWin::HandleClipboard(const ClipboardEvent& event) { |
| + clipboard_->InjectClipboardEvent(event); |
| +} |
| + |
| void EventExecutorWin::HandleKey(const KeyEvent& event) { |
| // HostEventDispatcher should filter events missing the pressed field. |
| DCHECK(event.has_pressed()); |
| @@ -288,10 +284,11 @@ void EventExecutorWin::HandleSessionFinished() { |
| } // namespace |
| -scoped_ptr<EventExecutor> EventExecutor::Create( |
| - MessageLoop* message_loop, Capturer* capturer) { |
| +scoped_ptr<EventExecutor> EventExecutor::Create(MessageLoop* message_loop, |
| + base::MessageLoopProxy* ui_loop, |
| + Capturer* capturer) { |
| return scoped_ptr<EventExecutor>( |
| - new EventExecutorWin(message_loop, capturer)); |
| + new EventExecutorWin(message_loop, ui_loop, capturer)); |
| } |
| } // namespace remoting |