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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ 6 #define CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ 7 8 #include <vector> 9 10 #include "base/callback.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/weak_ptr.h" 13 #include "base/observer_list.h" 14 #include "base/threading/thread_checker.h" 15 #include "device/hid/input_service_linux.h" 16 17 namespace chromeos { 18 19 // Proxy to device::InputServiceLinux. Should be created and used on the UI 20 // thread. 21 class InputServiceProxy { 22 public: 23 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo; 24 25 class Observer { 26 public: 27 virtual ~Observer() {} 28 virtual void OnInputDeviceAdded(const InputDeviceInfo& info) = 0; 29 virtual void OnInputDeviceRemoved(const std::string& id) = 0; 30 }; 31 32 typedef base::Callback<void(const std::vector<InputDeviceInfo>& devices)> 33 GetDevicesCallback; 34 typedef base::Callback<void(bool success, const InputDeviceInfo& info)> 35 GetDeviceInfoCallback; 36 37 InputServiceProxy(); 38 ~InputServiceProxy(); 39 40 // Used for early init for cashing info about available HID. 41 static void WarmUp(); 42 43 void AddObserver(Observer* observer); 44 void RemoveObserver(Observer* observer); 45 46 void GetDevices(const GetDevicesCallback& callback); 47 void GetDeviceInfo(const std::string& id, 48 const GetDeviceInfoCallback& callback); 49 50 private: 51 class ServiceObserver; 52 53 void OnDeviceAdded(const device::InputServiceLinux::InputDeviceInfo& info); 54 void OnDeviceRemoved(const std::string& id); 55 56 ObserverList<Observer> observers_; 57 scoped_ptr<ServiceObserver> service_observer_; 58 59 base::ThreadChecker thread_checker_; 60 61 base::WeakPtrFactory<InputServiceProxy> weak_factory_; 62 63 DISALLOW_COPY_AND_ASSIGN(InputServiceProxy); 64 }; 65 66 } // namespace chromeos 67 68 #endif // CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ 69