Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / events / ozone / evdev / event_thread_evdev.cc
blob66ce4c28165eba668365540b1fde344ca8753166
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.
5 #include "ui/events/ozone/evdev/event_thread_evdev.h"
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"
17 namespace ui {
19 namespace {
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(); }
34 void Init() override {
35 TRACE_EVENT0("evdev", "EvdevThread::Init");
36 input_device_factory_ =
37 new InputDeviceFactoryEvdev(dispatcher_.Pass(), cursor_);
39 scoped_ptr<InputDeviceFactoryEvdevProxy> proxy(
40 new InputDeviceFactoryEvdevProxy(base::ThreadTaskRunnerHandle::Get(),
41 input_device_factory_->GetWeakPtr()));
43 init_runner_->PostTask(FROM_HERE,
44 base::Bind(init_callback_, base::Passed(&proxy)));
47 void CleanUp() override {
48 TRACE_EVENT0("evdev", "EvdevThread::CleanUp");
49 delete input_device_factory_;
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_;
59 // Thread-internal state.
60 InputDeviceFactoryEvdev* input_device_factory_ = nullptr;
63 } // namespace
65 EventThreadEvdev::EventThreadEvdev() {
68 EventThreadEvdev::~EventThreadEvdev() {
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";
81 } // namespace ui