OLD | NEW |
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 EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ |
6 #define EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 | 49 |
50 // Enumerates available devices, taking into account the permissions held by | 50 // Enumerates available devices, taking into account the permissions held by |
51 // the given extension and the filters provided. The provided callback will | 51 // the given extension and the filters provided. The provided callback will |
52 // be posted to the calling thread's task runner with a list of device info | 52 // be posted to the calling thread's task runner with a list of device info |
53 // objects. | 53 // objects. |
54 void GetApiDevices(const Extension* extension, | 54 void GetApiDevices(const Extension* extension, |
55 const std::vector<device::HidDeviceFilter>& filters, | 55 const std::vector<device::HidDeviceFilter>& filters, |
56 const GetApiDevicesCallback& callback); | 56 const GetApiDevicesCallback& callback); |
57 | 57 |
58 bool GetDeviceInfo(int resource_id, device::HidDeviceInfo* device_info); | 58 scoped_refptr<device::HidDeviceInfo> GetDeviceInfo(int resource_id); |
59 | 59 |
60 static bool HasPermission(const Extension* extension, | 60 static bool HasPermission(const Extension* extension, |
61 const device::HidDeviceInfo& device_info); | 61 scoped_refptr<device::HidDeviceInfo> device_info); |
62 | 62 |
63 private: | 63 private: |
64 friend class BrowserContextKeyedAPIFactory<HidDeviceManager>; | 64 friend class BrowserContextKeyedAPIFactory<HidDeviceManager>; |
65 | 65 |
66 typedef std::map<int, device::HidDeviceId> ResourceIdToDeviceIdMap; | 66 typedef std::map<int, device::HidDeviceId> ResourceIdToDeviceIdMap; |
67 typedef std::map<device::HidDeviceId, int> DeviceIdToResourceIdMap; | 67 typedef std::map<device::HidDeviceId, int> DeviceIdToResourceIdMap; |
68 | 68 |
69 struct GetApiDevicesParams; | 69 struct GetApiDevicesParams; |
70 | 70 |
71 // KeyedService: | 71 // KeyedService: |
72 void Shutdown() override; | 72 void Shutdown() override; |
73 | 73 |
74 // BrowserContextKeyedAPI: | 74 // BrowserContextKeyedAPI: |
75 static const char* service_name() { return "HidDeviceManager"; } | 75 static const char* service_name() { return "HidDeviceManager"; } |
76 static const bool kServiceHasOwnInstanceInIncognito = true; | 76 static const bool kServiceHasOwnInstanceInIncognito = true; |
77 static const bool kServiceIsNULLWhileTesting = true; | 77 static const bool kServiceIsNULLWhileTesting = true; |
78 | 78 |
79 // EventRouter::Observer: | 79 // EventRouter::Observer: |
80 void OnListenerAdded(const EventListenerInfo& details) override; | 80 void OnListenerAdded(const EventListenerInfo& details) override; |
81 | 81 |
82 // HidService::Observer: | 82 // HidService::Observer: |
83 void OnDeviceAdded(const device::HidDeviceInfo& device_info) override; | 83 void OnDeviceAdded(scoped_refptr<device::HidDeviceInfo> device_info) override; |
84 void OnDeviceRemoved(const device::HidDeviceInfo& device_info) override; | 84 void OnDeviceRemoved( |
| 85 scoped_refptr<device::HidDeviceInfo> device_info) override; |
85 | 86 |
86 // Wait to perform an initial enumeration and register a HidService::Observer | 87 // Wait to perform an initial enumeration and register a HidService::Observer |
87 // until the first API customer makes a request or registers an event | 88 // until the first API customer makes a request or registers an event |
88 // listener. | 89 // listener. |
89 void LazyInitialize(); | 90 void LazyInitialize(); |
90 | 91 |
91 // Builds a list of device info objects representing the currently enumerated | 92 // Builds a list of device info objects representing the currently enumerated |
92 // devices, taking into account the permissions held by the given extension | 93 // devices, taking into account the permissions held by the given extension |
93 // and the filters provided. | 94 // and the filters provided. |
94 scoped_ptr<base::ListValue> CreateApiDeviceList( | 95 scoped_ptr<base::ListValue> CreateApiDeviceList( |
95 const Extension* extension, | 96 const Extension* extension, |
96 const std::vector<device::HidDeviceFilter>& filters); | 97 const std::vector<device::HidDeviceFilter>& filters); |
97 void OnEnumerationComplete(const std::vector<device::HidDeviceInfo>& devices); | 98 void OnEnumerationComplete( |
| 99 const std::vector<scoped_refptr<device::HidDeviceInfo>>& devices); |
98 | 100 |
99 void DispatchEvent(const std::string& event_name, | 101 void DispatchEvent(const std::string& event_name, |
100 scoped_ptr<base::ListValue> event_args, | 102 scoped_ptr<base::ListValue> event_args, |
101 const device::HidDeviceInfo& device_info); | 103 scoped_refptr<device::HidDeviceInfo> device_info); |
102 | 104 |
103 base::ThreadChecker thread_checker_; | 105 base::ThreadChecker thread_checker_; |
104 EventRouter* event_router_; | 106 EventRouter* event_router_; |
105 bool initialized_; | 107 bool initialized_; |
106 ScopedObserver<device::HidService, device::HidService::Observer> | 108 ScopedObserver<device::HidService, device::HidService::Observer> |
107 hid_service_observer_; | 109 hid_service_observer_; |
108 bool enumeration_ready_; | 110 bool enumeration_ready_; |
109 ScopedVector<GetApiDevicesParams> pending_enumerations_; | 111 ScopedVector<GetApiDevicesParams> pending_enumerations_; |
110 int next_resource_id_; | 112 int next_resource_id_; |
111 ResourceIdToDeviceIdMap device_ids_; | 113 ResourceIdToDeviceIdMap device_ids_; |
112 DeviceIdToResourceIdMap resource_ids_; | 114 DeviceIdToResourceIdMap resource_ids_; |
113 base::WeakPtrFactory<HidDeviceManager> weak_factory_; | 115 base::WeakPtrFactory<HidDeviceManager> weak_factory_; |
114 | 116 |
115 DISALLOW_COPY_AND_ASSIGN(HidDeviceManager); | 117 DISALLOW_COPY_AND_ASSIGN(HidDeviceManager); |
116 }; | 118 }; |
117 | 119 |
118 } // namespace extensions | 120 } // namespace extensions |
119 | 121 |
120 #endif // EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ | 122 #endif // EXTENSIONS_BROWSER_API_HID_HID_DEVICE_MANAGER_H_ |
OLD | NEW |