summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/device/input_service_proxy.h
blob: e41196f62ca05046a4dda634f82ab0fc329dce87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_
#define CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_

#include <vector>

#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
#include "device/hid/input_service_linux.h"

namespace chromeos {

// Proxy to device::InputServiceLinux. Should be created and used on the UI
// thread.
class InputServiceProxy {
 public:
  typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo;

  class Observer {
   public:
    virtual ~Observer() {}
    virtual void OnInputDeviceAdded(const InputDeviceInfo& info) = 0;
    virtual void OnInputDeviceRemoved(const std::string& id) = 0;
  };

  typedef base::Callback<void(const std::vector<InputDeviceInfo>& devices)>
      GetDevicesCallback;
  typedef base::Callback<void(bool success, const InputDeviceInfo& info)>
      GetDeviceInfoCallback;

  InputServiceProxy();
  ~InputServiceProxy();

  // Used for early init for cashing info about available HID.
  static void WarmUp();

  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

  void GetDevices(const GetDevicesCallback& callback);
  void GetDeviceInfo(const std::string& id,
                     const GetDeviceInfoCallback& callback);

 private:
  class ServiceObserver;

  void OnDeviceAdded(const device::InputServiceLinux::InputDeviceInfo& info);
  void OnDeviceRemoved(const std::string& id);

  ObserverList<Observer> observers_;
  scoped_ptr<ServiceObserver> service_observer_;

  base::ThreadChecker thread_checker_;

  base::WeakPtrFactory<InputServiceProxy> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(InputServiceProxy);
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_