| Index: device/hid/input_service_linux.cc
|
| diff --git a/device/hid/input_service_linux.cc b/device/hid/input_service_linux.cc
|
| index f6fd0dceb7bf8589fbcf8bee5c649a23978d1327..11313115dab92165ba3c8e81e40b20d4b241cf78 100644
|
| --- a/device/hid/input_service_linux.cc
|
| +++ b/device/hid/input_service_linux.cc
|
| @@ -80,24 +80,62 @@ class InputServiceLinuxImpl : public InputServiceLinux,
|
| void OnDeviceAdded(udev_device* device) override;
|
| void OnDeviceRemoved(udev_device* device) override;
|
|
|
| + // InputServiceLinux overrides:
|
| + void AddObserver(InputServiceLinux::Observer* observer) override;
|
| + void RemoveObserver(InputServiceLinux::Observer* observer) override;
|
| + void GetDevices(std::vector<InputDeviceInfo>* devices) override;
|
| + bool GetDeviceInfo(
|
| + const std::string& id, InputDeviceInfo* info) const override;
|
| + void WillDestroyCurrentMessageLoop() override;
|
| +
|
| + protected:
|
| + bool CalledOnValidThread() const;
|
| +
|
| private:
|
| friend class InputServiceLinux;
|
|
|
| InputServiceLinuxImpl();
|
| ~InputServiceLinuxImpl() override;
|
|
|
| + base::ThreadChecker thread_checker_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(InputServiceLinuxImpl);
|
| };
|
|
|
| InputServiceLinuxImpl::InputServiceLinuxImpl() {
|
| + base::ThreadRestrictions::AssertIOAllowed();
|
| + base::MessageLoop::current()->AddDestructionObserver(this);
|
| +
|
| DeviceMonitorLinux::GetInstance()->AddObserver(this);
|
| DeviceMonitorLinux::GetInstance()->Enumerate(base::Bind(
|
| &InputServiceLinuxImpl::OnDeviceAdded, base::Unretained(this)));
|
| }
|
|
|
| InputServiceLinuxImpl::~InputServiceLinuxImpl() {
|
| - if (DeviceMonitorLinux::HasInstance())
|
| - DeviceMonitorLinux::GetInstance()->RemoveObserver(this);
|
| + DCHECK(CalledOnValidThread());
|
| + base::MessageLoop::current()->RemoveDestructionObserver(this);
|
| +}
|
| +
|
| +void InputServiceLinuxImpl::AddObserver(InputServiceLinux::Observer* observer) {
|
| + DCHECK(CalledOnValidThread());
|
| + InputServiceLinux::AddObserver(observer);
|
| +}
|
| +
|
| +void InputServiceLinuxImpl::RemoveObserver(
|
| + InputServiceLinux::Observer* observer) {
|
| + DCHECK(CalledOnValidThread());
|
| + InputServiceLinux::RemoveObserver(observer);
|
| +}
|
| +
|
| +void InputServiceLinuxImpl::GetDevices(std::vector<InputDeviceInfo>* devices) {
|
| + DCHECK(CalledOnValidThread());
|
| + InputServiceLinux::GetDevices(devices);
|
| +}
|
| +
|
| +bool InputServiceLinuxImpl::GetDeviceInfo(const std::string& id,
|
| + InputDeviceInfo* info) const {
|
| + DCHECK(CalledOnValidThread());
|
| + return InputServiceLinux::GetDeviceInfo(id, info);
|
| }
|
|
|
| void InputServiceLinuxImpl::OnDeviceAdded(udev_device* device) {
|
| @@ -147,6 +185,15 @@ void InputServiceLinuxImpl::OnDeviceRemoved(udev_device* device) {
|
| RemoveDevice(devnode);
|
| }
|
|
|
| +void InputServiceLinuxImpl::WillDestroyCurrentMessageLoop() {
|
| + DCHECK(CalledOnValidThread());
|
| + InputServiceLinux::WillDestroyCurrentMessageLoop();
|
| +}
|
| +
|
| +bool InputServiceLinuxImpl::CalledOnValidThread() const {
|
| + return thread_checker_.CalledOnValidThread();
|
| +}
|
| +
|
| } // namespace
|
|
|
| InputServiceLinux::InputDeviceInfo::InputDeviceInfo()
|
| @@ -162,13 +209,9 @@ InputServiceLinux::InputDeviceInfo::InputDeviceInfo()
|
| is_touchscreen(false) {}
|
|
|
| InputServiceLinux::InputServiceLinux() {
|
| - base::ThreadRestrictions::AssertIOAllowed();
|
| - base::MessageLoop::current()->AddDestructionObserver(this);
|
| }
|
|
|
| InputServiceLinux::~InputServiceLinux() {
|
| - DCHECK(CalledOnValidThread());
|
| - base::MessageLoop::current()->RemoveDestructionObserver(this);
|
| }
|
|
|
| // static
|
| @@ -189,19 +232,16 @@ void InputServiceLinux::SetForTesting(InputServiceLinux* service) {
|
| }
|
|
|
| void InputServiceLinux::AddObserver(Observer* observer) {
|
| - DCHECK(CalledOnValidThread());
|
| if (observer)
|
| observers_.AddObserver(observer);
|
| }
|
|
|
| void InputServiceLinux::RemoveObserver(Observer* observer) {
|
| - DCHECK(CalledOnValidThread());
|
| if (observer)
|
| observers_.RemoveObserver(observer);
|
| }
|
|
|
| void InputServiceLinux::GetDevices(std::vector<InputDeviceInfo>* devices) {
|
| - DCHECK(CalledOnValidThread());
|
| for (DeviceMap::iterator it = devices_.begin(), ie = devices_.end(); it != ie;
|
| ++it) {
|
| devices->push_back(it->second);
|
| @@ -210,7 +250,6 @@ void InputServiceLinux::GetDevices(std::vector<InputDeviceInfo>* devices) {
|
|
|
| bool InputServiceLinux::GetDeviceInfo(const std::string& id,
|
| InputDeviceInfo* info) const {
|
| - DCHECK(CalledOnValidThread());
|
| DeviceMap::const_iterator it = devices_.find(id);
|
| if (it == devices_.end())
|
| return false;
|
| @@ -219,7 +258,6 @@ bool InputServiceLinux::GetDeviceInfo(const std::string& id,
|
| }
|
|
|
| void InputServiceLinux::WillDestroyCurrentMessageLoop() {
|
| - DCHECK(CalledOnValidThread());
|
| g_input_service_linux_ptr.Get().reset(NULL);
|
| }
|
|
|
| @@ -233,8 +271,4 @@ void InputServiceLinux::RemoveDevice(const std::string& id) {
|
| FOR_EACH_OBSERVER(Observer, observers_, OnInputDeviceRemoved(id));
|
| }
|
|
|
| -bool InputServiceLinux::CalledOnValidThread() const {
|
| - return thread_checker_.CalledOnValidThread();
|
| -}
|
| -
|
| } // namespace device
|
|
|