| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "components/input_device_service/input_device_client.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" |
| 10 |
| 11 namespace input_device { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // TODO(kylechar): Debug, remove eventually. |
| 16 template <class DeviceType> |
| 17 void PrintDevices(std::string title, const DeviceType& devices) { |
| 18 LOG(ERROR) << title << " devices.size()=" << devices.size(); |
| 19 for (const auto& device : devices) { |
| 20 LOG(ERROR) << device.ToString(); |
| 21 } |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 26 InputDeviceClient::InputDeviceClient() : binding_(this) {} |
| 27 |
| 28 InputDeviceClient::~InputDeviceClient() { |
| 29 InputDeviceService::ClearInstance(); |
| 30 } |
| 31 |
| 32 void InputDeviceClient::Initialize(shell::Connector* connector) { |
| 33 connector->ConnectToInterface("mojo:mus", &service_); |
| 34 |
| 35 // Add this class as an observer via Mojo IPC. |
| 36 service_->AddObserver(binding_.CreateInterfacePtrAndBind()); |
| 37 |
| 38 // TODO(kylechar): Can we somehow check for a successful connection here? |
| 39 RequestDeviceUpdates(); |
| 40 |
| 41 // Install this as the InputDeviceService. |
| 42 InputDeviceService::SetInstance(this); |
| 43 } |
| 44 |
| 45 void InputDeviceClient::OnKeyboardDeviceConfigurationChanged( |
| 46 mojo::Array<ui::InputDevice> devices) { |
| 47 UpdateKeyboardDevices(std::move(devices)); |
| 48 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 49 OnKeyboardDeviceConfigurationChanged()); |
| 50 } |
| 51 |
| 52 void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged( |
| 53 mojo::Array<ui::InputDevice> devices) { |
| 54 UpdateTouchscreenDevices(std::move(devices)); |
| 55 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 56 OnTouchscreenDeviceConfigurationChanged()); |
| 57 } |
| 58 |
| 59 void InputDeviceClient::OnMouseDeviceConfigurationChanged( |
| 60 mojo::Array<ui::InputDevice> devices) { |
| 61 UpdateMouseDevices(std::move(devices)); |
| 62 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 63 OnMouseDeviceConfigurationChanged()); |
| 64 } |
| 65 |
| 66 void InputDeviceClient::OnTouchpadDeviceConfigurationChanged( |
| 67 mojo::Array<ui::InputDevice> devices) { |
| 68 UpdateTouchpadDevices(std::move(devices)); |
| 69 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_, |
| 70 OnTouchpadDeviceConfigurationChanged()); |
| 71 } |
| 72 |
| 73 void InputDeviceClient::AddObserver(ui::InputDeviceEventObserver* observer) { |
| 74 observers_.AddObserver(observer); |
| 75 } |
| 76 |
| 77 void InputDeviceClient::RemoveObserver(ui::InputDeviceEventObserver* observer) { |
| 78 observers_.RemoveObserver(observer); |
| 79 } |
| 80 |
| 81 const std::vector<ui::InputDevice>& InputDeviceClient::keyboard_devices() { |
| 82 return keyboard_devices_; |
| 83 } |
| 84 |
| 85 const std::vector<ui::InputDevice>& InputDeviceClient::touchscreen_devices() { |
| 86 return touchscreen_devices_; |
| 87 } |
| 88 |
| 89 const std::vector<ui::InputDevice>& InputDeviceClient::mouse_devices() { |
| 90 return mouse_devices_; |
| 91 } |
| 92 |
| 93 const std::vector<ui::InputDevice>& InputDeviceClient::touchpad_devices() { |
| 94 return touchpad_devices_; |
| 95 } |
| 96 |
| 97 void InputDeviceClient::RequestDeviceUpdates() { |
| 98 // TODO(kylechar): Maybe this should use a weakptr_factory? |
| 99 service_->GetKeyboardDevices(base::Bind( |
| 100 &InputDeviceClient::UpdateKeyboardDevices, base::Unretained(this))); |
| 101 |
| 102 service_->GetTouchscreenDevices(base::Bind( |
| 103 &InputDeviceClient::UpdateTouchscreenDevices, base::Unretained(this))); |
| 104 |
| 105 service_->GetMouseDevices(base::Bind(&InputDeviceClient::UpdateMouseDevices, |
| 106 base::Unretained(this))); |
| 107 |
| 108 service_->GetTouchpadDevices(base::Bind( |
| 109 &InputDeviceClient::UpdateTouchpadDevices, base::Unretained(this))); |
| 110 } |
| 111 |
| 112 void InputDeviceClient::UpdateKeyboardDevices( |
| 113 mojo::Array<ui::InputDevice> devices) { |
| 114 keyboard_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
| 115 PrintDevices("UpdateKeyboardDevices", keyboard_devices_); |
| 116 } |
| 117 |
| 118 void InputDeviceClient::UpdateTouchscreenDevices( |
| 119 mojo::Array<ui::InputDevice> devices) { |
| 120 touchscreen_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
| 121 PrintDevices("UpdateTouchscreenDevices", touchscreen_devices_); |
| 122 } |
| 123 |
| 124 void InputDeviceClient::UpdateMouseDevices( |
| 125 mojo::Array<ui::InputDevice> devices) { |
| 126 mouse_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
| 127 PrintDevices("UpdateMouseDevices", mouse_devices_); |
| 128 } |
| 129 |
| 130 void InputDeviceClient::UpdateTouchpadDevices( |
| 131 mojo::Array<ui::InputDevice> devices) { |
| 132 touchpad_devices_ = devices.To<std::vector<ui::InputDevice>>(); |
| 133 PrintDevices("UpdateTouchpadDevices", touchpad_devices_); |
| 134 } |
| 135 |
| 136 } // namespace input_device |
| OLD | NEW |