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 "device/usb/usb_service_impl.h" | 5 #include "device/usb/usb_service_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/barrier_closure.h" | 14 #include "base/barrier_closure.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/threading/thread_task_runner_handle.h" | |
23 #include "build/build_config.h" | 22 #include "build/build_config.h" |
24 #include "components/device_event_log/device_event_log.h" | 23 #include "components/device_event_log/device_event_log.h" |
25 #include "device/usb/usb_device_handle.h" | 24 #include "device/usb/usb_device_handle.h" |
26 #include "device/usb/usb_error.h" | 25 #include "device/usb/usb_error.h" |
27 #include "device/usb/webusb_descriptors.h" | 26 #include "device/usb/webusb_descriptors.h" |
28 #include "net/base/io_buffer.h" | 27 #include "net/base/io_buffer.h" |
29 #include "third_party/libusb/src/libusb/libusb.h" | 28 #include "third_party/libusb/src/libusb/libusb.h" |
30 | 29 |
31 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
32 #include <setupapi.h> | 31 #include <setupapi.h> |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 device_handle, barrier)); | 207 device_handle, barrier)); |
209 } | 208 } |
210 } else { | 209 } else { |
211 failure_closure.Run(); | 210 failure_closure.Run(); |
212 } | 211 } |
213 } | 212 } |
214 | 213 |
215 } // namespace | 214 } // namespace |
216 | 215 |
217 UsbServiceImpl::UsbServiceImpl( | 216 UsbServiceImpl::UsbServiceImpl( |
218 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) | 217 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_in) |
219 : UsbService(base::ThreadTaskRunnerHandle::Get(), blocking_task_runner), | 218 : UsbService(std::move(blocking_task_runner_in)), |
220 #if defined(OS_WIN) | 219 #if defined(OS_WIN) |
221 device_observer_(this), | 220 device_observer_(this), |
222 #endif | 221 #endif |
223 weak_factory_(this) { | 222 weak_factory_(this) { |
224 blocking_task_runner->PostTask( | 223 blocking_task_runner()->PostTask( |
225 FROM_HERE, base::Bind(&InitializeUsbContextOnBlockingThread, | 224 FROM_HERE, |
226 base::ThreadTaskRunnerHandle::Get(), | 225 base::Bind(&InitializeUsbContextOnBlockingThread, task_runner(), |
227 base::Bind(&UsbServiceImpl::OnUsbContext, | 226 base::Bind(&UsbServiceImpl::OnUsbContext, |
228 weak_factory_.GetWeakPtr()))); | 227 weak_factory_.GetWeakPtr()))); |
229 } | 228 } |
230 | 229 |
231 UsbServiceImpl::~UsbServiceImpl() { | 230 UsbServiceImpl::~UsbServiceImpl() { |
232 if (hotplug_enabled_) | 231 if (hotplug_enabled_) |
233 libusb_hotplug_deregister_callback(context_->context(), hotplug_handle_); | 232 libusb_hotplug_deregister_callback(context_->context(), hotplug_handle_); |
234 for (auto* platform_device : ignored_devices_) | 233 for (auto* platform_device : ignored_devices_) |
235 libusb_unref_device(platform_device); | 234 libusb_unref_device(platform_device); |
236 } | 235 } |
237 | 236 |
238 void UsbServiceImpl::GetDevices(const GetDevicesCallback& callback) { | 237 void UsbServiceImpl::GetDevices(const GetDevicesCallback& callback) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 } | 548 } |
550 | 549 |
551 void UsbServiceImpl::EnumerationFailed(PlatformUsbDevice platform_device, | 550 void UsbServiceImpl::EnumerationFailed(PlatformUsbDevice platform_device, |
552 const base::Closure& refresh_complete) { | 551 const base::Closure& refresh_complete) { |
553 libusb_ref_device(platform_device); | 552 libusb_ref_device(platform_device); |
554 ignored_devices_.insert(platform_device); | 553 ignored_devices_.insert(platform_device); |
555 refresh_complete.Run(); | 554 refresh_complete.Run(); |
556 } | 555 } |
557 | 556 |
558 } // namespace device | 557 } // namespace device |
OLD | NEW |