| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/events/test/platform_event_waiter.h" | 5 #include "ui/events/test/platform_event_waiter.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" |
| 8 #include "ui/events/platform/platform_event_source.h" | 10 #include "ui/events/platform/platform_event_source.h" |
| 9 | 11 |
| 10 namespace ui { | 12 namespace ui { |
| 11 | 13 |
| 12 PlatformEventWaiter::PlatformEventWaiter( | 14 PlatformEventWaiter::PlatformEventWaiter( |
| 13 const base::Closure& success_callback, | 15 const base::Closure& success_callback, |
| 14 const PlatformEventMatcher& event_matcher) | 16 const PlatformEventMatcher& event_matcher) |
| 15 : success_callback_(success_callback), | 17 : success_callback_(success_callback), |
| 16 event_matcher_(event_matcher) { | 18 event_matcher_(event_matcher) { |
| 17 PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); | 19 PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); |
| 18 } | 20 } |
| 19 | 21 |
| 20 PlatformEventWaiter::~PlatformEventWaiter() { | 22 PlatformEventWaiter::~PlatformEventWaiter() { |
| 21 PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); | 23 PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); |
| 22 } | 24 } |
| 23 | 25 |
| 24 void PlatformEventWaiter::WillProcessEvent(const PlatformEvent& event) { | 26 void PlatformEventWaiter::WillProcessEvent(const PlatformEvent& event) { |
| 25 if (event_matcher_.Run(event)) { | 27 if (event_matcher_.Run(event)) { |
| 26 base::MessageLoop::current()->PostTask(FROM_HERE, success_callback_); | 28 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, success_callback_); |
| 27 delete this; | 29 delete this; |
| 28 } | 30 } |
| 29 } | 31 } |
| 30 | 32 |
| 31 void PlatformEventWaiter::DidProcessEvent(const PlatformEvent& event) { | 33 void PlatformEventWaiter::DidProcessEvent(const PlatformEvent& event) { |
| 32 } | 34 } |
| 33 | 35 |
| 34 // static | 36 // static |
| 35 PlatformEventWaiter* PlatformEventWaiter::Create( | 37 PlatformEventWaiter* PlatformEventWaiter::Create( |
| 36 const base::Closure& success_callback, | 38 const base::Closure& success_callback, |
| 37 const PlatformEventMatcher& event_matcher) { | 39 const PlatformEventMatcher& event_matcher) { |
| 38 return new PlatformEventWaiter(success_callback, event_matcher); | 40 return new PlatformEventWaiter(success_callback, event_matcher); |
| 39 } | 41 } |
| 40 | 42 |
| 41 } // namespace ui | 43 } // namespace ui |
| OLD | NEW |