| 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 "extensions/browser/api/hid/hid_device_manager.h" | 5 #include "extensions/browser/api/hid/hid_device_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/location.h" |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "device/core/device_client.h" | 18 #include "device/core/device_client.h" |
| 16 #include "device/hid/hid_device_filter.h" | 19 #include "device/hid/hid_device_filter.h" |
| 17 #include "device/hid/hid_service.h" | 20 #include "device/hid/hid_service.h" |
| 18 #include "extensions/browser/api/device_permissions_manager.h" | 21 #include "extensions/browser/api/device_permissions_manager.h" |
| 19 #include "extensions/common/permissions/permissions_data.h" | 22 #include "extensions/common/permissions/permissions_data.h" |
| 20 #include "extensions/common/permissions/usb_device_permission.h" | 23 #include "extensions/common/permissions/usb_device_permission.h" |
| 21 | 24 |
| 22 namespace hid = extensions::api::hid; | 25 namespace hid = extensions::api::hid; |
| 23 | 26 |
| 24 using device::HidDeviceFilter; | 27 using device::HidDeviceFilter; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 void HidDeviceManager::GetApiDevices( | 120 void HidDeviceManager::GetApiDevices( |
| 118 const Extension* extension, | 121 const Extension* extension, |
| 119 const std::vector<HidDeviceFilter>& filters, | 122 const std::vector<HidDeviceFilter>& filters, |
| 120 const GetApiDevicesCallback& callback) { | 123 const GetApiDevicesCallback& callback) { |
| 121 DCHECK(thread_checker_.CalledOnValidThread()); | 124 DCHECK(thread_checker_.CalledOnValidThread()); |
| 122 LazyInitialize(); | 125 LazyInitialize(); |
| 123 | 126 |
| 124 if (enumeration_ready_) { | 127 if (enumeration_ready_) { |
| 125 std::unique_ptr<base::ListValue> devices = | 128 std::unique_ptr<base::ListValue> devices = |
| 126 CreateApiDeviceList(extension, filters); | 129 CreateApiDeviceList(extension, filters); |
| 127 base::MessageLoop::current()->PostTask( | 130 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 128 FROM_HERE, base::Bind(callback, base::Passed(&devices))); | 131 FROM_HERE, base::Bind(callback, base::Passed(&devices))); |
| 129 } else { | 132 } else { |
| 130 pending_enumerations_.push_back(base::WrapUnique( | 133 pending_enumerations_.push_back(base::WrapUnique( |
| 131 new GetApiDevicesParams(extension, filters, callback))); | 134 new GetApiDevicesParams(extension, filters, callback))); |
| 132 } | 135 } |
| 133 } | 136 } |
| 134 | 137 |
| 135 std::unique_ptr<base::ListValue> HidDeviceManager::GetApiDevicesFromList( | 138 std::unique_ptr<base::ListValue> HidDeviceManager::GetApiDevicesFromList( |
| 136 const std::vector<scoped_refptr<HidDeviceInfo>>& devices) { | 139 const std::vector<scoped_refptr<HidDeviceInfo>>& devices) { |
| 137 DCHECK(thread_checker_.CalledOnValidThread()); | 140 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 std::unique_ptr<base::ListValue> event_args, | 335 std::unique_ptr<base::ListValue> event_args, |
| 333 scoped_refptr<HidDeviceInfo> device_info) { | 336 scoped_refptr<HidDeviceInfo> device_info) { |
| 334 std::unique_ptr<Event> event( | 337 std::unique_ptr<Event> event( |
| 335 new Event(histogram_value, event_name, std::move(event_args))); | 338 new Event(histogram_value, event_name, std::move(event_args))); |
| 336 event->will_dispatch_callback = base::Bind( | 339 event->will_dispatch_callback = base::Bind( |
| 337 &WillDispatchDeviceEvent, weak_factory_.GetWeakPtr(), device_info); | 340 &WillDispatchDeviceEvent, weak_factory_.GetWeakPtr(), device_info); |
| 338 event_router_->BroadcastEvent(std::move(event)); | 341 event_router_->BroadcastEvent(std::move(event)); |
| 339 } | 342 } |
| 340 | 343 |
| 341 } // namespace extensions | 344 } // namespace extensions |
| OLD | NEW |