Revert 269361 "Fix WebURLLoaderImpl::Context leak if a pending r..."
[chromium-blink-merge.git] / device / hid / input_service_linux.h
blobdc43dba9bc27be9a1ed08926954b67be695a6496
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.
5 #ifndef DEVICE_HID_INPUT_SERVICE_LINUX_H_
6 #define DEVICE_HID_INPUT_SERVICE_LINUX_H_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/observer_list.h"
17 #include "base/threading/thread_checker.h"
18 #include "device/hid/device_monitor_linux.h"
20 namespace device {
22 // This class provides information and notifications about
23 // connected/disconnected input/HID devices. This class is *NOT*
24 // thread-safe and all methods must be called from the FILE thread.
25 class InputServiceLinux : public base::MessageLoop::DestructionObserver {
26 public:
27 struct InputDeviceInfo {
28 enum Subsystem { SUBSYSTEM_HID, SUBSYSTEM_INPUT, SUBSYSTEM_UNKNOWN };
29 enum Type { TYPE_BLUETOOTH, TYPE_USB, TYPE_SERIO, TYPE_UNKNOWN };
31 InputDeviceInfo();
33 std::string id;
34 std::string name;
35 Subsystem subsystem;
36 Type type;
38 bool is_accelerometer : 1;
39 bool is_joystick : 1;
40 bool is_key : 1;
41 bool is_keyboard : 1;
42 bool is_mouse : 1;
43 bool is_tablet : 1;
44 bool is_touchpad : 1;
45 bool is_touchscreen : 1;
48 class Observer {
49 public:
50 virtual ~Observer() {}
51 virtual void OnInputDeviceAdded(const InputDeviceInfo& info) = 0;
52 virtual void OnInputDeviceRemoved(const std::string& id) = 0;
55 InputServiceLinux();
57 static InputServiceLinux* GetInstance();
58 static bool HasInstance();
59 static void SetForTesting(InputServiceLinux* service);
61 void AddObserver(Observer* observer);
62 void RemoveObserver(Observer* observer);
64 // Returns list of all currently connected input/hid devices.
65 void GetDevices(std::vector<InputDeviceInfo>* devices);
67 // Returns an info about input device identified by |id|. When there're
68 // no input or hid device with such id, returns false and doesn't
69 // modify |info|.
70 bool GetDeviceInfo(const std::string& id, InputDeviceInfo* info) const;
72 // Implements base::MessageLoop::DestructionObserver
73 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
75 protected:
76 virtual ~InputServiceLinux();
78 void AddDevice(const InputDeviceInfo& info);
79 void RemoveDevice(const std::string& id);
81 bool CalledOnValidThread() const;
83 private:
84 friend struct base::DefaultDeleter<InputServiceLinux>;
86 typedef base::hash_map<std::string, InputDeviceInfo> DeviceMap;
88 DeviceMap devices_;
89 ObserverList<Observer> observers_;
91 base::ThreadChecker thread_checker_;
93 DISALLOW_COPY_AND_ASSIGN(InputServiceLinux);
96 } // namespace device
98 #endif // DEVICE_HID_INPUT_SERVICE_LINUX_H_