Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Side by Side Diff: device/usb/usb_device_handle_impl.cc

Issue 1736703002: Ensure libusb_close is called from the FILE thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_device_handle_impl.h" 5 #include "device/usb/usb_device_handle_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <numeric> 8 #include <numeric>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 : device_(device), 775 : device_(device),
776 handle_(handle), 776 handle_(handle),
777 context_(context), 777 context_(context),
778 task_runner_(base::ThreadTaskRunnerHandle::Get()), 778 task_runner_(base::ThreadTaskRunnerHandle::Get()),
779 blocking_task_runner_(blocking_task_runner) { 779 blocking_task_runner_(blocking_task_runner) {
780 DCHECK(handle) << "Cannot create device with NULL handle."; 780 DCHECK(handle) << "Cannot create device with NULL handle.";
781 } 781 }
782 782
783 UsbDeviceHandleImpl::~UsbDeviceHandleImpl() { 783 UsbDeviceHandleImpl::~UsbDeviceHandleImpl() {
784 // This class is RefCountedThreadSafe and so the destructor may be called on 784 // This class is RefCountedThreadSafe and so the destructor may be called on
785 // any thread. 785 // any thread. libusb is not safe to reentrancy so be sure not to try to close
786 libusb_close(handle_); 786 // the device from inside a transfer completion callback.
787 if (blocking_task_runner_->RunsTasksOnCurrentThread()) {
788 libusb_close(handle_);
789 } else {
790 blocking_task_runner_->PostTask(FROM_HERE,
791 base::Bind(&libusb_close, handle_));
792 }
787 } 793 }
788 794
789 void UsbDeviceHandleImpl::SetConfigurationOnBlockingThread( 795 void UsbDeviceHandleImpl::SetConfigurationOnBlockingThread(
790 int configuration_value, 796 int configuration_value,
791 const ResultCallback& callback) { 797 const ResultCallback& callback) {
792 int rv = libusb_set_configuration(handle_, configuration_value); 798 int rv = libusb_set_configuration(handle_, configuration_value);
793 if (rv != LIBUSB_SUCCESS) { 799 if (rv != LIBUSB_SUCCESS) {
794 USB_LOG(EVENT) << "Failed to set configuration " << configuration_value 800 USB_LOG(EVENT) << "Failed to set configuration " << configuration_value
795 << ": " << ConvertPlatformUsbErrorToString(rv); 801 << ": " << ConvertPlatformUsbErrorToString(rv);
796 } 802 }
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 map_entry.second = nullptr; 1126 map_entry.second = nullptr;
1121 blocking_task_runner_->ReleaseSoon(FROM_HERE, interface_claimer); 1127 blocking_task_runner_->ReleaseSoon(FROM_HERE, interface_claimer);
1122 } 1128 }
1123 1129
1124 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to 1130 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to
1125 // finish. 1131 // finish.
1126 device_ = nullptr; 1132 device_ = nullptr;
1127 } 1133 }
1128 1134
1129 } // namespace device 1135 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698