Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Side by Side Diff: device/hid/hid_service.h

Issue 660573007: Open HID connections asynchronously. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/hid/hid_connection_unittest.cc ('k') | device/hid/hid_service_linux.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_HID_HID_SERVICE_H_ 5 #ifndef DEVICE_HID_HID_SERVICE_H_
6 #define DEVICE_HID_HID_SERVICE_H_ 6 #define DEVICE_HID_HID_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "device/hid/hid_device_info.h" 15 #include "device/hid/hid_device_info.h"
16 16
17 namespace device { 17 namespace device {
18 18
19 class HidConnection; 19 class HidConnection;
20 20
21 class HidService { 21 class HidService {
22 public: 22 public:
23 typedef base::Callback<void(scoped_refptr<HidConnection> connection)>
24 ConnectCallback;
25
23 static HidService* GetInstance( 26 static HidService* GetInstance(
24 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, 27 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
25 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); 28 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
26 29
27 // Enumerates and returns a list of device identifiers. 30 // Enumerates and returns a list of device identifiers.
28 virtual void GetDevices(std::vector<HidDeviceInfo>* devices); 31 virtual void GetDevices(std::vector<HidDeviceInfo>* devices);
29 32
30 // Fills in a DeviceInfo struct with info for the given device_id. 33 // Fills in a DeviceInfo struct with info for the given device_id.
31 // Returns |true| if successful or |false| if |device_id| is invalid. 34 // Returns |true| if successful or |false| if |device_id| is invalid.
32 bool GetDeviceInfo(const HidDeviceId& device_id, HidDeviceInfo* info) const; 35 bool GetDeviceInfo(const HidDeviceId& device_id, HidDeviceInfo* info) const;
33 36
34 #if defined(OS_CHROMEOS) 37 // Opens a connection to a device. The callback will be run with null on
35 // Requests access to the given device from the Chrome OS permission broker. 38 // failure.
36 virtual void RequestAccess( 39 virtual void Connect(const HidDeviceId& device_id,
37 const HidDeviceId& device_id, 40 const ConnectCallback& callback) = 0;
38 const base::Callback<void(bool success)>& callback) = 0;
39 #endif
40
41 virtual scoped_refptr<HidConnection> Connect(
42 const HidDeviceId& device_id) = 0;
43 41
44 protected: 42 protected:
45 friend class HidConnectionTest; 43 friend class HidConnectionTest;
46 44
47 typedef std::map<HidDeviceId, HidDeviceInfo> DeviceMap; 45 typedef std::map<HidDeviceId, HidDeviceInfo> DeviceMap;
48 46
49 HidService(); 47 HidService();
50 virtual ~HidService(); 48 virtual ~HidService();
51 49
52 void AddDevice(const HidDeviceInfo& info); 50 void AddDevice(const HidDeviceInfo& info);
53 void RemoveDevice(const HidDeviceId& device_id); 51 void RemoveDevice(const HidDeviceId& device_id);
54 52
55 const DeviceMap& devices() const { return devices_; } 53 const DeviceMap& devices() const { return devices_; }
56 54
57 base::ThreadChecker thread_checker_; 55 base::ThreadChecker thread_checker_;
58 56
59 private: 57 private:
60 class Destroyer; 58 class Destroyer;
61 59
62 DeviceMap devices_; 60 DeviceMap devices_;
63 61
64 DISALLOW_COPY_AND_ASSIGN(HidService); 62 DISALLOW_COPY_AND_ASSIGN(HidService);
65 }; 63 };
66 64
67 } // namespace device 65 } // namespace device
68 66
69 #endif // DEVICE_HID_HID_SERVICE_H_ 67 #endif // DEVICE_HID_HID_SERVICE_H_
OLDNEW
« no previous file with comments | « device/hid/hid_connection_unittest.cc ('k') | device/hid/hid_service_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698