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

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

Issue 2849953003: Use the task scheduler for blocking tasks in the USB service on Linux (Closed)
Patch Set: Remove more passing of the SequencedTaskRunner 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 | « device/usb/usb_device_handle_android.h ('k') | device/usb/usb_device_handle_unittest.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_android.h" 5 #include "device/usb/usb_device_handle_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "device/usb/usb_device.h" 9 #include "device/usb/usb_device.h"
10 #include "device/usb/usb_service.h"
10 #include "jni/ChromeUsbConnection_jni.h" 11 #include "jni/ChromeUsbConnection_jni.h"
11 12
12 using base::android::ScopedJavaLocalRef; 13 using base::android::ScopedJavaLocalRef;
13 14
14 namespace device { 15 namespace device {
15 16
16 // static 17 // static
17 scoped_refptr<UsbDeviceHandleAndroid> UsbDeviceHandleAndroid::Create( 18 scoped_refptr<UsbDeviceHandleAndroid> UsbDeviceHandleAndroid::Create(
18 JNIEnv* env, 19 JNIEnv* env,
19 scoped_refptr<UsbDevice> device, 20 scoped_refptr<UsbDevice> device,
20 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
21 const base::android::JavaRef<jobject>& usb_connection) { 21 const base::android::JavaRef<jobject>& usb_connection) {
22 ScopedJavaLocalRef<jobject> wrapper = 22 ScopedJavaLocalRef<jobject> wrapper =
23 Java_ChromeUsbConnection_create(env, usb_connection); 23 Java_ChromeUsbConnection_create(env, usb_connection);
24 // C++ doesn't own this file descriptor so CloseBlocking() is overridden 24 // C++ doesn't own this file descriptor so CloseBlocking() is overridden
25 // below to release it without closing it. 25 // below to release it without closing it.
26 base::ScopedFD fd(Java_ChromeUsbConnection_getFileDescriptor(env, wrapper)); 26 base::ScopedFD fd(Java_ChromeUsbConnection_getFileDescriptor(env, wrapper));
27 return make_scoped_refptr(new UsbDeviceHandleAndroid( 27 return make_scoped_refptr(
28 device, std::move(fd), blocking_task_runner, wrapper)); 28 new UsbDeviceHandleAndroid(device, std::move(fd), wrapper));
29 } 29 }
30 30
31 UsbDeviceHandleAndroid::UsbDeviceHandleAndroid( 31 UsbDeviceHandleAndroid::UsbDeviceHandleAndroid(
32 scoped_refptr<UsbDevice> device, 32 scoped_refptr<UsbDevice> device,
33 base::ScopedFD fd, 33 base::ScopedFD fd,
34 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
35 const base::android::JavaRef<jobject>& wrapper) 34 const base::android::JavaRef<jobject>& wrapper)
36 : UsbDeviceHandleUsbfs(device, std::move(fd), blocking_task_runner), 35 : UsbDeviceHandleUsbfs(device,
36 std::move(fd),
37 UsbService::CreateBlockingTaskRunner()),
37 j_object_(wrapper) {} 38 j_object_(wrapper) {}
38 39
39 UsbDeviceHandleAndroid::~UsbDeviceHandleAndroid() {} 40 UsbDeviceHandleAndroid::~UsbDeviceHandleAndroid() {}
40 41
41 void UsbDeviceHandleAndroid::CloseBlocking() { 42 void UsbDeviceHandleAndroid::CloseBlocking() {
42 ReleaseFileDescriptor(); 43 ReleaseFileDescriptor();
43 task_runner()->PostTask( 44 task_runner()->PostTask(
44 FROM_HERE, base::Bind(&UsbDeviceHandleAndroid::CloseConnection, this)); 45 FROM_HERE, base::Bind(&UsbDeviceHandleAndroid::CloseConnection, this));
45 } 46 }
46 47
47 void UsbDeviceHandleAndroid::CloseConnection() { 48 void UsbDeviceHandleAndroid::CloseConnection() {
48 JNIEnv* env = base::android::AttachCurrentThread(); 49 JNIEnv* env = base::android::AttachCurrentThread();
49 Java_ChromeUsbConnection_close(env, j_object_); 50 Java_ChromeUsbConnection_close(env, j_object_);
50 j_object_.Reset(); 51 j_object_.Reset();
51 } 52 }
52 53
53 } // namespace device 54 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_device_handle_android.h ('k') | device/usb/usb_device_handle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698