| 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 "device/hid/input_service_linux.h" | 5 #include "device/hid/input_service_linux.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 private: | 83 private: |
| 84 friend class InputServiceLinux; | 84 friend class InputServiceLinux; |
| 85 | 85 |
| 86 InputServiceLinuxImpl(); | 86 InputServiceLinuxImpl(); |
| 87 ~InputServiceLinuxImpl() override; | 87 ~InputServiceLinuxImpl() override; |
| 88 | 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(InputServiceLinuxImpl); | 89 DISALLOW_COPY_AND_ASSIGN(InputServiceLinuxImpl); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 InputServiceLinuxImpl::InputServiceLinuxImpl() { | 92 InputServiceLinuxImpl::InputServiceLinuxImpl() { |
| 93 base::ThreadRestrictions::AssertIOAllowed(); |
| 94 base::MessageLoop::current()->AddDestructionObserver(this); |
| 95 |
| 93 DeviceMonitorLinux::GetInstance()->AddObserver(this); | 96 DeviceMonitorLinux::GetInstance()->AddObserver(this); |
| 94 DeviceMonitorLinux::GetInstance()->Enumerate(base::Bind( | 97 DeviceMonitorLinux::GetInstance()->Enumerate(base::Bind( |
| 95 &InputServiceLinuxImpl::OnDeviceAdded, base::Unretained(this))); | 98 &InputServiceLinuxImpl::OnDeviceAdded, base::Unretained(this))); |
| 96 } | 99 } |
| 97 | 100 |
| 98 InputServiceLinuxImpl::~InputServiceLinuxImpl() { | 101 InputServiceLinuxImpl::~InputServiceLinuxImpl() { |
| 99 if (DeviceMonitorLinux::HasInstance()) | 102 if (DeviceMonitorLinux::HasInstance()) |
| 100 DeviceMonitorLinux::GetInstance()->RemoveObserver(this); | 103 DeviceMonitorLinux::GetInstance()->RemoveObserver(this); |
| 104 base::MessageLoop::current()->RemoveDestructionObserver(this); |
| 101 } | 105 } |
| 102 | 106 |
| 103 void InputServiceLinuxImpl::OnDeviceAdded(udev_device* device) { | 107 void InputServiceLinuxImpl::OnDeviceAdded(udev_device* device) { |
| 104 DCHECK(CalledOnValidThread()); | 108 DCHECK(CalledOnValidThread()); |
| 105 if (!device) | 109 if (!device) |
| 106 return; | 110 return; |
| 107 const char* devnode = udev_device_get_devnode(device); | 111 const char* devnode = udev_device_get_devnode(device); |
| 108 if (!devnode) | 112 if (!devnode) |
| 109 return; | 113 return; |
| 110 | 114 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 is_accelerometer(false), | 159 is_accelerometer(false), |
| 156 is_joystick(false), | 160 is_joystick(false), |
| 157 is_key(false), | 161 is_key(false), |
| 158 is_keyboard(false), | 162 is_keyboard(false), |
| 159 is_mouse(false), | 163 is_mouse(false), |
| 160 is_tablet(false), | 164 is_tablet(false), |
| 161 is_touchpad(false), | 165 is_touchpad(false), |
| 162 is_touchscreen(false) {} | 166 is_touchscreen(false) {} |
| 163 | 167 |
| 164 InputServiceLinux::InputServiceLinux() { | 168 InputServiceLinux::InputServiceLinux() { |
| 165 base::ThreadRestrictions::AssertIOAllowed(); | |
| 166 base::MessageLoop::current()->AddDestructionObserver(this); | |
| 167 } | 169 } |
| 168 | 170 |
| 169 InputServiceLinux::~InputServiceLinux() { | 171 InputServiceLinux::~InputServiceLinux() { |
| 170 DCHECK(CalledOnValidThread()); | 172 DCHECK(CalledOnValidThread()); |
| 171 base::MessageLoop::current()->RemoveDestructionObserver(this); | |
| 172 } | 173 } |
| 173 | 174 |
| 174 // static | 175 // static |
| 175 InputServiceLinux* InputServiceLinux::GetInstance() { | 176 InputServiceLinux* InputServiceLinux::GetInstance() { |
| 176 if (!HasInstance()) | 177 if (!HasInstance()) |
| 177 g_input_service_linux_ptr.Get().reset(new InputServiceLinuxImpl()); | 178 g_input_service_linux_ptr.Get().reset(new InputServiceLinuxImpl()); |
| 178 return g_input_service_linux_ptr.Get().get(); | 179 return g_input_service_linux_ptr.Get().get(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 // static | 182 // static |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 void InputServiceLinux::RemoveDevice(const std::string& id) { | 232 void InputServiceLinux::RemoveDevice(const std::string& id) { |
| 232 devices_.erase(id); | 233 devices_.erase(id); |
| 233 FOR_EACH_OBSERVER(Observer, observers_, OnInputDeviceRemoved(id)); | 234 FOR_EACH_OBSERVER(Observer, observers_, OnInputDeviceRemoved(id)); |
| 234 } | 235 } |
| 235 | 236 |
| 236 bool InputServiceLinux::CalledOnValidThread() const { | 237 bool InputServiceLinux::CalledOnValidThread() const { |
| 237 return thread_checker_.CalledOnValidThread(); | 238 return thread_checker_.CalledOnValidThread(); |
| 238 } | 239 } |
| 239 | 240 |
| 240 } // namespace device | 241 } // namespace device |
| OLD | NEW |