Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / device / hid / hid_service.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 DEVICE_HID_HID_SERVICE_H_
6 #define DEVICE_HID_HID_SERVICE_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_checker.h"
15 #include "device/hid/hid_device_info.h"
16
17 namespace device {
18
19 class HidConnection;
20
21 class HidService {
22  public:
23   typedef base::Callback<void(scoped_refptr<HidConnection> connection)>
24       ConnectCallback;
25
26   static HidService* GetInstance(
27       scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
28       scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
29
30   static void SetInstanceForTest(HidService* instance);
31
32   // Enumerates and returns a list of device identifiers.
33   virtual void GetDevices(std::vector<HidDeviceInfo>* devices);
34
35   // Fills in a DeviceInfo struct with info for the given device_id.
36   // Returns |true| if successful or |false| if |device_id| is invalid.
37   bool GetDeviceInfo(const HidDeviceId& device_id, HidDeviceInfo* info) const;
38
39   // Opens a connection to a device. The callback will be run with null on
40   // failure.
41   virtual void Connect(const HidDeviceId& device_id,
42                        const ConnectCallback& callback) = 0;
43
44  protected:
45   friend class HidConnectionTest;
46
47   typedef std::map<HidDeviceId, HidDeviceInfo> DeviceMap;
48
49   HidService();
50   virtual ~HidService();
51
52   void AddDevice(const HidDeviceInfo& info);
53   void RemoveDevice(const HidDeviceId& device_id);
54
55   const DeviceMap& devices() const { return devices_; }
56
57   base::ThreadChecker thread_checker_;
58
59  private:
60   class Destroyer;
61
62   DeviceMap devices_;
63
64   DISALLOW_COPY_AND_ASSIGN(HidService);
65 };
66
67 }  // namespace device
68
69 #endif  // DEVICE_HID_HID_SERVICE_H_