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

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: 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
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
23 UsbDevice::UsbDevice( 33 UsbDevice::UsbDevice(
24 scoped_refptr<UsbContext> context, 34 scoped_refptr<UsbContext> context,
25 PlatformUsbDevice platform_device, 35 PlatformUsbDevice platform_device,
26 uint16 vendor_id, 36 uint16 vendor_id,
27 uint16 product_id, 37 uint16 product_id,
28 uint32 unique_id) 38 uint32 unique_id)
29 : platform_device_(platform_device), 39 : platform_device_(platform_device),
30 vendor_id_(vendor_id), 40 vendor_id_(vendor_id),
31 product_id_(product_id), 41 product_id_(product_id),
32 unique_id_(unique_id), 42 unique_id_(unique_id),
(...skipping 15 matching lines...) Expand all
48 for (HandlesVector::iterator it = handles_.begin(); 58 for (HandlesVector::iterator it = handles_.begin();
49 it != handles_.end(); 59 it != handles_.end();
50 ++it) { 60 ++it) {
51 (*it)->InternalClose(); 61 (*it)->InternalClose();
52 } 62 }
53 STLClearObject(&handles_); 63 STLClearObject(&handles_);
54 libusb_unref_device(platform_device_); 64 libusb_unref_device(platform_device_);
55 } 65 }
56 66
57 #if defined(OS_CHROMEOS) 67 #if defined(OS_CHROMEOS)
68
58 void UsbDevice::RequestUsbAcess( 69 void UsbDevice::RequestUsbAcess(
59 int interface_id, 70 int interface_id,
60 const base::Callback<void(bool success)>& callback) { 71 const base::Callback<void(bool success)>& callback) {
61 DCHECK(thread_checker_.CalledOnValidThread()); 72 DCHECK(thread_checker_.CalledOnValidThread());
62 73
63 // ChromeOS builds on non-ChromeOS machines (dev) should not attempt to 74 // ChromeOS builds on non-ChromeOS machines (dev) should not attempt to
64 // use permission broker. 75 // use permission broker.
65 if (base::chromeos::IsRunningOnChromeOS()) { 76 if (base::chromeos::IsRunningOnChromeOS()) {
66 chromeos::PermissionBrokerClient* client = 77 chromeos::PermissionBrokerClient* client =
67 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); 78 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
68 DCHECK(client) << "Could not get permission broker client."; 79 DCHECK(client) << "Could not get permission broker client.";
69 if (!client) { 80 if (!client) {
70 callback.Run(false); 81 callback.Run(false);
71 return; 82 return;
72 } 83 }
73 84
74 BrowserThread::PostTask( 85 BrowserThread::PostTask(
75 BrowserThread::UI, FROM_HERE, 86 BrowserThread::UI, FROM_HERE,
76 base::Bind(&chromeos::PermissionBrokerClient::RequestUsbAccess, 87 base::Bind(&chromeos::PermissionBrokerClient::RequestUsbAccess,
77 base::Unretained(client), 88 base::Unretained(client),
78 this->vendor_id_, 89 this->vendor_id_,
79 this->product_id_, 90 this->product_id_,
80 interface_id, 91 interface_id,
81 base::Bind(&UsbDevice::OnRequestUsbAccessReplied, 92 base::Bind(&OnRequestUsbAccessReplied, callback)));
82 base::Unretained(this),
83 callback)));
84 } 93 }
85 } 94 }
86 95
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 96 #endif
95 97
96 scoped_refptr<UsbDeviceHandle> UsbDevice::Open() { 98 scoped_refptr<UsbDeviceHandle> UsbDevice::Open() {
97 DCHECK(thread_checker_.CalledOnValidThread()); 99 DCHECK(thread_checker_.CalledOnValidThread());
98 PlatformUsbDeviceHandle handle; 100 PlatformUsbDeviceHandle handle;
99 int rv = libusb_open(platform_device_, &handle); 101 int rv = libusb_open(platform_device_, &handle);
100 if (LIBUSB_SUCCESS == rv) { 102 if (LIBUSB_SUCCESS == rv) {
101 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces(); 103 scoped_refptr<UsbConfigDescriptor> interfaces = ListInterfaces();
102 if (!interfaces) 104 if (!interfaces)
103 return NULL; 105 return NULL;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 DCHECK(thread_checker_.CalledOnValidThread()); 142 DCHECK(thread_checker_.CalledOnValidThread());
141 HandlesVector handles; 143 HandlesVector handles;
142 swap(handles, handles_); 144 swap(handles, handles_);
143 for (std::vector<scoped_refptr<UsbDeviceHandle> >::iterator it = 145 for (std::vector<scoped_refptr<UsbDeviceHandle> >::iterator it =
144 handles.begin(); 146 handles.begin();
145 it != handles.end(); 147 it != handles.end();
146 ++it) { 148 ++it) {
147 (*it)->InternalClose(); 149 (*it)->InternalClose();
148 } 150 }
149 } 151 }
OLDNEW
« chrome/browser/extensions/api/usb/usb_api.cc ('K') | « chrome/browser/usb/usb_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698