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 #include "chrome/browser/extensions/api/hid/hid_device_manager.h" | 5 #include "chrome/browser/extensions/api/hid/hid_device_manager.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 int resource_id = device_iter->first; | 42 int resource_id = device_iter->first; |
43 device::HidDeviceId device_id = device_iter->second; | 43 device::HidDeviceId device_id = device_iter->second; |
44 device::HidDeviceInfo device_info; | 44 device::HidDeviceInfo device_info; |
45 if (hid_service->GetDeviceInfo(device_id, &device_info)) { | 45 if (hid_service->GetDeviceInfo(device_id, &device_info)) { |
46 if (device_info.vendor_id == vendor_id && | 46 if (device_info.vendor_id == vendor_id && |
47 device_info.product_id == product_id) { | 47 device_info.product_id == product_id) { |
48 api::hid::HidDeviceInfo api_device_info; | 48 api::hid::HidDeviceInfo api_device_info; |
49 api_device_info.device_id = resource_id; | 49 api_device_info.device_id = resource_id; |
50 api_device_info.vendor_id = device_info.vendor_id; | 50 api_device_info.vendor_id = device_info.vendor_id; |
51 api_device_info.product_id = device_info.product_id; | 51 api_device_info.product_id = device_info.product_id; |
| 52 for (std::vector<device::HidUsageAndPage>::const_iterator usage_iter = |
| 53 device_info.usages.begin(); |
| 54 usage_iter != device_info.usages.end(); |
| 55 ++usage_iter) { |
| 56 api::hid::HidUsageAndPage* usage_and_page = |
| 57 new api::hid::HidUsageAndPage(); |
| 58 usage_and_page->usage_page = (*usage_iter).usage_page; |
| 59 usage_and_page->usage = (*usage_iter).usage; |
| 60 linked_ptr<api::hid::HidUsageAndPage> usage_and_page_ptr( |
| 61 usage_and_page); |
| 62 api_device_info.usages.push_back(usage_and_page_ptr); |
| 63 } |
52 api_devices->Append(api_device_info.ToValue().release()); | 64 api_devices->Append(api_device_info.ToValue().release()); |
53 } | 65 } |
54 } | 66 } |
55 } | 67 } |
56 return scoped_ptr<base::ListValue>(api_devices); | 68 return scoped_ptr<base::ListValue>(api_devices); |
57 } | 69 } |
58 | 70 |
59 bool HidDeviceManager::GetDeviceInfo(int resource_id, | 71 bool HidDeviceManager::GetDeviceInfo(int resource_id, |
60 device::HidDeviceInfo* device_info) { | 72 device::HidDeviceInfo* device_info) { |
61 UpdateDevices(); | 73 UpdateDevices(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 new_id = next_resource_id_++; | 108 new_id = next_resource_id_++; |
97 } | 109 } |
98 new_resource_ids[device_info.device_id] = new_id; | 110 new_resource_ids[device_info.device_id] = new_id; |
99 new_device_ids[new_id] = device_info.device_id; | 111 new_device_ids[new_id] = device_info.device_id; |
100 } | 112 } |
101 device_ids_.swap(new_device_ids); | 113 device_ids_.swap(new_device_ids); |
102 resource_ids_.swap(new_resource_ids); | 114 resource_ids_.swap(new_resource_ids); |
103 } | 115 } |
104 | 116 |
105 } // namespace extensions | 117 } // namespace extensions |
OLD | NEW |