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

Side by Side Diff: chrome/browser/usb/usb_device.cc

Issue 23475048: Fixes crashing in RequestUsbDevicesAccess (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/usb/usb_device.h ('k') | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/usb/usb_device.h" 5 #include "chrome/browser/usb/usb_device.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/browser/usb/usb_context.h" 10 #include "chrome/browser/usb/usb_context.h"
11 #include "chrome/browser/usb/usb_device_handle.h" 11 #include "chrome/browser/usb/usb_device_handle.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "third_party/libusb/src/libusb/libusb.h" 13 #include "third_party/libusb/src/libusb/libusb.h"
14 14
15 #if defined(OS_CHROMEOS) 15 #if defined(OS_CHROMEOS)
16 #include "base/chromeos/chromeos_version.h" 16 #include "base/chromeos/chromeos_version.h"
17 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/permission_broker_client.h" 18 #include "chromeos/dbus/permission_broker_client.h"
19 #endif // defined(OS_CHROMEOS) 19 #endif // defined(OS_CHROMEOS)
20 20
21 using content::BrowserThread; 21 using content::BrowserThread;
22 22
23 namespace {
24
25 void OnRequestUsbAccessReplied(
26 const base::Callback<void(bool success)>& callback,
27 bool success) {
28 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
29 base::Bind(callback, success));
30 }
31
32 } // namespace
33
23 UsbDevice::UsbDevice( 34 UsbDevice::UsbDevice(
24 scoped_refptr<UsbContext> context, 35 scoped_refptr<UsbContext> context,
25 PlatformUsbDevice platform_device, 36 PlatformUsbDevice platform_device,
26 uint16 vendor_id, 37 uint16 vendor_id,
27 uint16 product_id, 38 uint16 product_id,
28 uint32 unique_id) 39 uint32 unique_id)
29 : platform_device_(platform_device), 40 : platform_device_(platform_device),
30 vendor_id_(vendor_id), 41 vendor_id_(vendor_id),
31 product_id_(product_id), 42 product_id_(product_id),
32 unique_id_(unique_id), 43 unique_id_(unique_id),
(...skipping 15 matching lines...) Expand all
48 for (HandlesVector::iterator it = handles_.begin(); 59 for (HandlesVector::iterator it = handles_.begin();
49 it != handles_.end(); 60 it != handles_.end();
50 ++it) { 61 ++it) {
51 (*it)->InternalClose(); 62 (*it)->InternalClose();
52 } 63 }
53 STLClearObject(&handles_); 64 STLClearObject(&handles_);
54 libusb_unref_device(platform_device_); 65 libusb_unref_device(platform_device_);
55 } 66 }
56 67
57 #if defined(OS_CHROMEOS) 68 #if defined(OS_CHROMEOS)
69
58 void UsbDevice::RequestUsbAcess( 70 void UsbDevice::RequestUsbAcess(
59 int interface_id, 71 int interface_id,
60 const base::Callback<void(bool success)>& callback) { 72 const base::Callback<void(bool success)>& callback) {
61 DCHECK(thread_checker_.CalledOnValidThread()); 73 DCHECK(thread_checker_.CalledOnValidThread());
62 74
63 // ChromeOS builds on non-ChromeOS machines (dev) should not attempt to 75 // ChromeOS builds on non-ChromeOS machines (dev) should not attempt to
64 // use permission broker. 76 // use permission broker.
65 if (base::chromeos::IsRunningOnChromeOS()) { 77 if (base::chromeos::IsRunningOnChromeOS()) {
66 chromeos::PermissionBrokerClient* client = 78 chromeos::PermissionBrokerClient* client =
67 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); 79 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
68 DCHECK(client) << "Could not get permission broker client."; 80 DCHECK(client) << "Could not get permission broker client.";
69 if (!client) { 81 if (!client) {
70 callback.Run(false); 82 callback.Run(false);
71 return; 83 return;
72 } 84 }
73 85
74 BrowserThread::PostTask( 86 BrowserThread::PostTask(
75 BrowserThread::UI, FROM_HERE, 87 BrowserThread::UI, FROM_HERE,
76 base::Bind(&chromeos::PermissionBrokerClient::RequestUsbAccess, 88 base::Bind(&chromeos::PermissionBrokerClient::RequestUsbAccess,
77 base::Unretained(client), 89 base::Unretained(client),
78 this->vendor_id_, 90 this->vendor_id_,
79 this->product_id_, 91 this->product_id_,
80 interface_id, 92 interface_id,
81 base::Bind(&UsbDevice::OnRequestUsbAccessReplied, 93 base::Bind(&OnRequestUsbAccessReplied, callback)));
82 base::Unretained(this),
83 callback)));
84 } 94 }
85 } 95 }
86 96
87 void UsbDevice::OnRequestUsbAccessReplied(
88 const base::Callback<void(bool success)>& callback,
89 bool success) {
90 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
91 base::Bind(callback, success));
92 }
93
94 #endif 97 #endif
95 98
96 scoped_refptr<UsbDeviceHandle> UsbDevice::Open() { 99 scoped_refptr<UsbDeviceHandle> UsbDevice::Open() {
97 DCHECK(thread_checker_.CalledOnValidThread()); 100 DCHECK(thread_checker_.CalledOnValidThread());
98 PlatformUsbDeviceHandle handle; 101 PlatformUsbDeviceHandle handle;
99 int rv = libusb_open(platform_device_, &handle); 102 int rv = libusb_open(platform_device_, &handle);
100 if (LIBUSB_SUCCESS == rv) { 103 if (LIBUSB_SUCCESS == rv) {
101 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces(); 104 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces();
102 if (!interfaces) 105 if (!interfaces)
103 return NULL; 106 return NULL;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 DCHECK(thread_checker_.CalledOnValidThread()); 143 DCHECK(thread_checker_.CalledOnValidThread());
141 HandlesVector handles; 144 HandlesVector handles;
142 swap(handles, handles_); 145 swap(handles, handles_);
143 for (std::vector<scoped_refptr<UsbDeviceHandle> >::iterator it = 146 for (std::vector<scoped_refptr<UsbDeviceHandle> >::iterator it =
144 handles.begin(); 147 handles.begin();
145 it != handles.end(); 148 it != handles.end();
146 ++it) { 149 ++it) {
147 (*it)->InternalClose(); 150 (*it)->InternalClose();
148 } 151 }
149 } 152 }
OLDNEW
« no previous file with comments | « chrome/browser/usb/usb_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698