11ba071abe477a5668559211a85fb345e719c9fb
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / device / input_service_proxy.h
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   void AddObserver(Observer* observer);
41   void RemoveObserver(Observer* observer);
42
43   void GetDevices(const GetDevicesCallback& callback);
44   void GetDeviceInfo(const std::string& id,
45                      const GetDeviceInfoCallback& callback);
46
47  private:
48   class ServiceObserver;
49
50   void OnDeviceAdded(const device::InputServiceLinux::InputDeviceInfo& info);
51   void OnDeviceRemoved(const std::string& id);
52
53   ObserverList<Observer> observers_;
54   scoped_ptr<ServiceObserver> service_observer_;
55
56   base::ThreadChecker thread_checker_;
57
58   base::WeakPtrFactory<InputServiceProxy> weak_factory_;
59
60   DISALLOW_COPY_AND_ASSIGN(InputServiceProxy);
61 };
62
63 }  // namespace chromeos
64
65 #endif  // CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_