OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/events/ozone/evdev/event_thread_evdev.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/threading/thread.h" |
| 12 #include "base/trace_event/trace_event.h" |
| 13 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" |
| 14 #include "ui/events/ozone/evdev/input_device_factory_evdev.h" |
| 15 #include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h" |
| 16 |
| 17 namespace ui { |
| 18 |
| 19 namespace { |
| 20 |
| 21 // Internal base::Thread subclass for events thread. |
| 22 class EvdevThread : public base::Thread { |
| 23 public: |
| 24 EvdevThread(scoped_ptr<DeviceEventDispatcherEvdev> dispatcher, |
| 25 CursorDelegateEvdev* cursor, |
| 26 const EventThreadStartCallback& callback) |
| 27 : base::Thread("evdev"), |
| 28 dispatcher_(dispatcher.Pass()), |
| 29 cursor_(cursor), |
| 30 init_callback_(callback), |
| 31 init_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 32 ~EvdevThread() override { Stop(); } |
| 33 |
| 34 void Init() override { |
| 35 TRACE_EVENT0("evdev", "EvdevThread::Init"); |
| 36 input_device_factory_ = |
| 37 new InputDeviceFactoryEvdev(dispatcher_.Pass(), cursor_); |
| 38 |
| 39 scoped_ptr<InputDeviceFactoryEvdevProxy> proxy( |
| 40 new InputDeviceFactoryEvdevProxy(base::ThreadTaskRunnerHandle::Get(), |
| 41 input_device_factory_->GetWeakPtr())); |
| 42 |
| 43 init_runner_->PostTask(FROM_HERE, |
| 44 base::Bind(init_callback_, base::Passed(&proxy))); |
| 45 } |
| 46 |
| 47 void CleanUp() override { |
| 48 TRACE_EVENT0("evdev", "EvdevThread::CleanUp"); |
| 49 delete input_device_factory_; |
| 50 } |
| 51 |
| 52 private: |
| 53 // Initialization bits passed from main thread. |
| 54 scoped_ptr<DeviceEventDispatcherEvdev> dispatcher_; |
| 55 CursorDelegateEvdev* cursor_; |
| 56 EventThreadStartCallback init_callback_; |
| 57 scoped_refptr<base::SingleThreadTaskRunner> init_runner_; |
| 58 |
| 59 // Thread-internal state. |
| 60 InputDeviceFactoryEvdev* input_device_factory_ = nullptr; |
| 61 }; |
| 62 |
| 63 } // namespace |
| 64 |
| 65 EventThreadEvdev::EventThreadEvdev() { |
| 66 } |
| 67 |
| 68 EventThreadEvdev::~EventThreadEvdev() { |
| 69 } |
| 70 |
| 71 void EventThreadEvdev::Start(scoped_ptr<DeviceEventDispatcherEvdev> dispatcher, |
| 72 CursorDelegateEvdev* cursor, |
| 73 const EventThreadStartCallback& callback) { |
| 74 TRACE_EVENT0("evdev", "EventThreadEvdev::Start"); |
| 75 thread_.reset(new EvdevThread(dispatcher.Pass(), cursor, callback)); |
| 76 if (!thread_->StartWithOptions( |
| 77 base::Thread::Options(base::MessageLoop::TYPE_UI, 0))) |
| 78 LOG(FATAL) << "Failed to create input thread"; |
| 79 } |
| 80 |
| 81 } // namespace ui |
OLD | NEW |