| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.h" | 5 #include "device/usb/usb_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/feature_list.h" | 8 #include "base/feature_list.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "components/device_event_log/device_event_log.h" | 13 #include "components/device_event_log/device_event_log.h" |
| 14 #include "device/base/features.h" | 14 #include "device/base/features.h" |
| 15 #include "device/usb/usb_device.h" | 15 #include "device/usb/usb_device.h" |
| 16 #include "device/usb/usb_device_handle.h" |
| 16 | 17 |
| 17 #if defined(OS_ANDROID) | 18 #if defined(OS_ANDROID) |
| 18 #include "device/usb/usb_service_android.h" | 19 #include "device/usb/usb_service_android.h" |
| 19 #elif defined(USE_UDEV) | 20 #elif defined(USE_UDEV) |
| 20 #include "device/usb/usb_service_linux.h" | 21 #include "device/usb/usb_service_linux.h" |
| 21 #else | 22 #else |
| 22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 23 #include "device/usb/usb_service_win.h" | 24 #include "device/usb/usb_service_win.h" |
| 24 #endif | 25 #endif |
| 25 #include "device/usb/usb_service_impl.h" | 26 #include "device/usb/usb_service_impl.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 80 |
| 80 scoped_refptr<UsbDevice> UsbService::GetDevice(const std::string& guid) { | 81 scoped_refptr<UsbDevice> UsbService::GetDevice(const std::string& guid) { |
| 81 DCHECK(CalledOnValidThread()); | 82 DCHECK(CalledOnValidThread()); |
| 82 auto it = devices_.find(guid); | 83 auto it = devices_.find(guid); |
| 83 if (it == devices_.end()) | 84 if (it == devices_.end()) |
| 84 return nullptr; | 85 return nullptr; |
| 85 return it->second; | 86 return it->second; |
| 86 } | 87 } |
| 87 | 88 |
| 88 void UsbService::Shutdown() { | 89 void UsbService::Shutdown() { |
| 90 for (const auto& map_entry : devices_) { |
| 91 // Swap out this list as UsbDevice::HandleClosed() will try to modify it. |
| 92 std::list<UsbDeviceHandle*> handles; |
| 93 handles.swap(map_entry.second->handles()); |
| 94 for (auto* handle : handles) |
| 95 handle->Close(); |
| 96 } |
| 89 #if DCHECK_IS_ON() | 97 #if DCHECK_IS_ON() |
| 90 DCHECK(!did_shutdown_); | 98 DCHECK(!did_shutdown_); |
| 91 did_shutdown_ = true; | 99 did_shutdown_ = true; |
| 92 #endif | 100 #endif |
| 93 } | 101 } |
| 94 | 102 |
| 95 void UsbService::GetDevices(const GetDevicesCallback& callback) { | 103 void UsbService::GetDevices(const GetDevicesCallback& callback) { |
| 96 std::vector<scoped_refptr<UsbDevice>> devices; | 104 std::vector<scoped_refptr<UsbDevice>> devices; |
| 97 devices.reserve(devices_.size()); | 105 devices.reserve(devices_.size()); |
| 98 for (const auto& map_entry : devices_) | 106 for (const auto& map_entry : devices_) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 DCHECK(CalledOnValidThread()); | 166 DCHECK(CalledOnValidThread()); |
| 159 | 167 |
| 160 for (auto& observer : observer_list_) | 168 for (auto& observer : observer_list_) |
| 161 observer.OnDeviceRemoved(device); | 169 observer.OnDeviceRemoved(device); |
| 162 device->NotifyDeviceRemoved(); | 170 device->NotifyDeviceRemoved(); |
| 163 for (auto& observer : observer_list_) | 171 for (auto& observer : observer_list_) |
| 164 observer.OnDeviceRemovedCleanup(device); | 172 observer.OnDeviceRemovedCleanup(device); |
| 165 } | 173 } |
| 166 | 174 |
| 167 } // namespace device | 175 } // namespace device |
| OLD | NEW |