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

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

Issue 2797433005: Remove MessageLoop destruction observer from //device/usb (Closed)
Patch Set: Further clarify cross-thread ownership Created 3 years, 8 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_handle_usbfs.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 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 "jni/ChromeUsbConnection_jni.h" 10 #include "jni/ChromeUsbConnection_jni.h"
11 11
12 using base::android::ScopedJavaLocalRef; 12 using base::android::ScopedJavaLocalRef;
13 13
14 namespace device { 14 namespace device {
15 15
16 // static 16 // static
17 scoped_refptr<UsbDeviceHandleAndroid> UsbDeviceHandleAndroid::Create( 17 scoped_refptr<UsbDeviceHandleAndroid> UsbDeviceHandleAndroid::Create(
18 JNIEnv* env, 18 JNIEnv* env,
19 scoped_refptr<UsbDevice> device, 19 scoped_refptr<UsbDevice> device,
20 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, 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
25 // below to release it without closing it.
24 base::ScopedFD fd(Java_ChromeUsbConnection_getFileDescriptor(env, wrapper)); 26 base::ScopedFD fd(Java_ChromeUsbConnection_getFileDescriptor(env, wrapper));
25 return make_scoped_refptr(new UsbDeviceHandleAndroid( 27 return make_scoped_refptr(new UsbDeviceHandleAndroid(
26 device, std::move(fd), blocking_task_runner, wrapper)); 28 device, std::move(fd), blocking_task_runner, wrapper));
27 } 29 }
28 30
29 UsbDeviceHandleAndroid::UsbDeviceHandleAndroid( 31 UsbDeviceHandleAndroid::UsbDeviceHandleAndroid(
30 scoped_refptr<UsbDevice> device, 32 scoped_refptr<UsbDevice> device,
31 base::ScopedFD fd, 33 base::ScopedFD fd,
32 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, 34 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
33 const base::android::JavaRef<jobject>& wrapper) 35 const base::android::JavaRef<jobject>& wrapper)
34 : UsbDeviceHandleUsbfs(device, std::move(fd), blocking_task_runner), 36 : UsbDeviceHandleUsbfs(device, std::move(fd), blocking_task_runner),
35 j_object_(wrapper) {} 37 j_object_(wrapper) {}
36 38
37 UsbDeviceHandleAndroid::~UsbDeviceHandleAndroid() {} 39 UsbDeviceHandleAndroid::~UsbDeviceHandleAndroid() {}
38 40
39 void UsbDeviceHandleAndroid::CloseBlocking() { 41 void UsbDeviceHandleAndroid::CloseBlocking() {
40 ReleaseFileDescriptor(); 42 ReleaseFileDescriptor();
41 task_runner()->PostTask( 43 task_runner()->PostTask(
42 FROM_HERE, base::Bind(&UsbDeviceHandleAndroid::CloseConnection, this)); 44 FROM_HERE, base::Bind(&UsbDeviceHandleAndroid::CloseConnection, this));
43 } 45 }
44 46
45 void UsbDeviceHandleAndroid::CloseConnection() { 47 void UsbDeviceHandleAndroid::CloseConnection() {
46 JNIEnv* env = base::android::AttachCurrentThread(); 48 JNIEnv* env = base::android::AttachCurrentThread();
47 Java_ChromeUsbConnection_close(env, j_object_); 49 Java_ChromeUsbConnection_close(env, j_object_);
48 j_object_.Reset(); 50 j_object_.Reset();
49 } 51 }
50 52
51 } // namespace device 53 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/usb/usb_device_handle_usbfs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698