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

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

Issue 2857473002: Use the task scheduler in the USB service on macOS and Windows (Closed)
Patch Set: Add AssertIOAllowed Created 3 years, 7 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 | device/usb/usb_device_impl.h » ('j') | 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 <memory> 8 #include <memory>
9 #include <numeric> 9 #include <numeric>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/sequence_checker.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h" 18 #include "base/stl_util.h"
18 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
19 #include "base/synchronization/lock.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "components/device_event_log/device_event_log.h" 21 #include "components/device_event_log/device_event_log.h"
22 #include "device/usb/usb_context.h" 22 #include "device/usb/usb_context.h"
23 #include "device/usb/usb_descriptors.h" 23 #include "device/usb/usb_descriptors.h"
24 #include "device/usb/usb_device_impl.h" 24 #include "device/usb/usb_device_impl.h"
25 #include "device/usb/usb_error.h" 25 #include "device/usb/usb_error.h"
26 #include "device/usb/usb_service.h" 26 #include "device/usb/usb_service.h"
27 #include "net/base/io_buffer.h" 27 #include "net/base/io_buffer.h"
28 #include "third_party/libusb/src/libusb/libusb.h" 28 #include "third_party/libusb/src/libusb/libusb.h"
29 29
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 161
162 private: 162 private:
163 friend class base::RefCountedThreadSafe<InterfaceClaimer>; 163 friend class base::RefCountedThreadSafe<InterfaceClaimer>;
164 ~InterfaceClaimer(); 164 ~InterfaceClaimer();
165 165
166 const scoped_refptr<UsbDeviceHandleImpl> handle_; 166 const scoped_refptr<UsbDeviceHandleImpl> handle_;
167 const int interface_number_; 167 const int interface_number_;
168 int alternate_setting_; 168 int alternate_setting_;
169 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 169 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
170 ResultCallback release_callback_; 170 ResultCallback release_callback_;
171 base::ThreadChecker thread_checker_; 171 base::SequenceChecker sequence_checker_;
172 172
173 DISALLOW_COPY_AND_ASSIGN(InterfaceClaimer); 173 DISALLOW_COPY_AND_ASSIGN(InterfaceClaimer);
174 }; 174 };
175 175
176 UsbDeviceHandleImpl::InterfaceClaimer::InterfaceClaimer( 176 UsbDeviceHandleImpl::InterfaceClaimer::InterfaceClaimer(
177 scoped_refptr<UsbDeviceHandleImpl> handle, 177 scoped_refptr<UsbDeviceHandleImpl> handle,
178 int interface_number, 178 int interface_number,
179 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 179 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
180 : handle_(handle), 180 : handle_(handle),
181 interface_number_(interface_number), 181 interface_number_(interface_number),
182 alternate_setting_(0), 182 alternate_setting_(0),
183 task_runner_(task_runner) {} 183 task_runner_(task_runner) {}
184 184
185 UsbDeviceHandleImpl::InterfaceClaimer::~InterfaceClaimer() { 185 UsbDeviceHandleImpl::InterfaceClaimer::~InterfaceClaimer() {
186 DCHECK(thread_checker_.CalledOnValidThread()); 186 DCHECK(sequence_checker_.CalledOnValidSequence());
187 int rc = libusb_release_interface(handle_->handle(), interface_number_); 187 int rc = libusb_release_interface(handle_->handle(), interface_number_);
188 if (rc != LIBUSB_SUCCESS) { 188 if (rc != LIBUSB_SUCCESS) {
189 USB_LOG(DEBUG) << "Failed to release interface: " 189 USB_LOG(DEBUG) << "Failed to release interface: "
190 << ConvertPlatformUsbErrorToString(rc); 190 << ConvertPlatformUsbErrorToString(rc);
191 } 191 }
192 if (!release_callback_.is_null()) { 192 if (!release_callback_.is_null()) {
193 task_runner_->PostTask(FROM_HERE, 193 task_runner_->PostTask(FROM_HERE,
194 base::Bind(release_callback_, rc == LIBUSB_SUCCESS)); 194 base::Bind(release_callback_, rc == LIBUSB_SUCCESS));
195 } 195 }
196 } 196 }
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 } else { 1145 } else {
1146 transfer->callback_task_runner()->PostTask(FROM_HERE, callback); 1146 transfer->callback_task_runner()->PostTask(FROM_HERE, callback);
1147 } 1147 }
1148 1148
1149 // libusb_free_transfer races with libusb_submit_transfer and only work- 1149 // libusb_free_transfer races with libusb_submit_transfer and only work-
1150 // around is to make sure to call them on the same thread. 1150 // around is to make sure to call them on the same thread.
1151 blocking_task_runner_->DeleteSoon(FROM_HERE, transfer); 1151 blocking_task_runner_->DeleteSoon(FROM_HERE, transfer);
1152 } 1152 }
1153 1153
1154 } // namespace device 1154 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/usb/usb_device_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698