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/debug/trace_event.h" | |
10 #include "base/logging.h" | |
11 #include "base/thread_task_runner_handle.h" | |
12 #include "base/threading/thread.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_proxy_evdev.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 input_device_factory_(nullptr) {} | |
33 ~EvdevThread() override {} | |
piman
2015/01/28 00:07:26
You need to call Stop() here to avoid subtle races
spang
2015/01/28 00:20:14
Done.
Oops, missed the warning in all caps :(
| |
34 | |
35 void Init() override { | |
36 TRACE_EVENT0("ozone", "EvdevThread::Init"); | |
37 input_device_factory_ = | |
38 new InputDeviceFactoryEvdev(dispatcher_.Pass(), cursor_); | |
39 | |
40 scoped_ptr<InputDeviceFactoryProxyEvdev> proxy( | |
41 new InputDeviceFactoryProxyEvdev(base::ThreadTaskRunnerHandle::Get(), | |
42 input_device_factory_->GetWeakPtr())); | |
43 | |
44 init_runner_->PostTask(FROM_HERE, | |
45 base::Bind(init_callback_, base::Passed(&proxy))); | |
46 } | |
47 | |
48 void CleanUp() override { | |
49 TRACE_EVENT0("ozone", "EvdevThread::CleanUp"); | |
50 delete input_device_factory_; | |
51 } | |
52 | |
53 private: | |
54 // Initialization bits passed from main thread. | |
55 scoped_ptr<DeviceEventDispatcherEvdev> dispatcher_; | |
56 CursorDelegateEvdev* cursor_; | |
57 EventThreadStartCallback init_callback_; | |
58 scoped_refptr<base::SingleThreadTaskRunner> init_runner_; | |
59 | |
60 // Thread-internal state. | |
61 InputDeviceFactoryEvdev* input_device_factory_; | |
62 }; | |
63 | |
64 } // namespace | |
65 | |
66 EventThreadEvdev::EventThreadEvdev() { | |
67 } | |
68 | |
69 EventThreadEvdev::~EventThreadEvdev() { | |
70 } | |
71 | |
72 void EventThreadEvdev::Start(scoped_ptr<DeviceEventDispatcherEvdev> dispatcher, | |
73 CursorDelegateEvdev* cursor, | |
74 const EventThreadStartCallback& callback) { | |
75 TRACE_EVENT0("ozone", "EventThreadEvdev::Start"); | |
76 thread_.reset(new EvdevThread(dispatcher.Pass(), cursor, callback)); | |
77 if (!thread_->StartWithOptions( | |
78 base::Thread::Options(base::MessageLoop::TYPE_UI, 0))) | |
79 LOG(FATAL) << "Failed to create input thread"; | |
80 } | |
81 | |
82 } // namespace ui | |
OLD | NEW |