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

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

Issue 1681383002: Add path open errors from the permission broker to the device log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_request_access
Patch Set: Addresses stevenjb@'s comments. Created 4 years, 10 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_impl.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 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_impl.h" 5 #include "device/usb/usb_device_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 189
190 void UsbDeviceImpl::Open(const OpenCallback& callback) { 190 void UsbDeviceImpl::Open(const OpenCallback& callback) {
191 DCHECK(thread_checker_.CalledOnValidThread()); 191 DCHECK(thread_checker_.CalledOnValidThread());
192 192
193 #if defined(OS_CHROMEOS) 193 #if defined(OS_CHROMEOS)
194 chromeos::PermissionBrokerClient* client = 194 chromeos::PermissionBrokerClient* client =
195 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); 195 chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient();
196 DCHECK(client) << "Could not get permission broker client."; 196 DCHECK(client) << "Could not get permission broker client.";
197 client->OpenPath( 197 client->OpenPath(
198 device_path_, 198 device_path_,
199 base::Bind(&UsbDeviceImpl::OnOpenRequestComplete, this, callback)); 199 base::Bind(&UsbDeviceImpl::OnOpenRequestComplete, this, callback),
200 base::Bind(&UsbDeviceImpl::OnOpenRequestError, this, callback));
200 #else 201 #else
201 blocking_task_runner_->PostTask( 202 blocking_task_runner_->PostTask(
202 FROM_HERE, 203 FROM_HERE,
203 base::Bind(&UsbDeviceImpl::OpenOnBlockingThread, this, callback)); 204 base::Bind(&UsbDeviceImpl::OpenOnBlockingThread, this, callback));
204 #endif // defined(OS_CHROMEOS) 205 #endif // defined(OS_CHROMEOS)
205 } 206 }
206 207
207 void UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) { 208 void UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) {
208 DCHECK(thread_checker_.CalledOnValidThread()); 209 DCHECK(thread_checker_.CalledOnValidThread());
209 210
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 285
285 #if defined(OS_CHROMEOS) 286 #if defined(OS_CHROMEOS)
286 287
287 void UsbDeviceImpl::OnOpenRequestComplete(const OpenCallback& callback, 288 void UsbDeviceImpl::OnOpenRequestComplete(const OpenCallback& callback,
288 dbus::FileDescriptor fd) { 289 dbus::FileDescriptor fd) {
289 blocking_task_runner_->PostTask( 290 blocking_task_runner_->PostTask(
290 FROM_HERE, base::Bind(&UsbDeviceImpl::OpenOnBlockingThreadWithFd, this, 291 FROM_HERE, base::Bind(&UsbDeviceImpl::OpenOnBlockingThreadWithFd, this,
291 base::Passed(&fd), callback)); 292 base::Passed(&fd), callback));
292 } 293 }
293 294
295 void UsbDeviceImpl::OnOpenRequestError(const OpenCallback& callback,
296 const std::string& error_name,
297 const std::string& error_message) {
298 USB_LOG(EVENT) << "Permission broker failed to open the device: "
299 << error_name << ": " << error_message;
300 callback.Run(nullptr);
301 }
302
294 void UsbDeviceImpl::OpenOnBlockingThreadWithFd(dbus::FileDescriptor fd, 303 void UsbDeviceImpl::OpenOnBlockingThreadWithFd(dbus::FileDescriptor fd,
295 const OpenCallback& callback) { 304 const OpenCallback& callback) {
296 fd.CheckValidity(); 305 fd.CheckValidity();
297 if (!fd.is_valid()) { 306 DCHECK(fd.is_valid());
298 USB_LOG(EVENT) << "Did not get valid device handle from permission broker.";
299 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
300 return;
301 }
302 307
303 PlatformUsbDeviceHandle handle; 308 PlatformUsbDeviceHandle handle;
304 const int rv = libusb_open_fd(platform_device_, fd.TakeValue(), &handle); 309 const int rv = libusb_open_fd(platform_device_, fd.TakeValue(), &handle);
305 if (LIBUSB_SUCCESS == rv) { 310 if (LIBUSB_SUCCESS == rv) {
306 task_runner_->PostTask( 311 task_runner_->PostTask(
307 FROM_HERE, base::Bind(&UsbDeviceImpl::Opened, this, handle, callback)); 312 FROM_HERE, base::Bind(&UsbDeviceImpl::Opened, this, handle, callback));
308 } else { 313 } else {
309 USB_LOG(EVENT) << "Failed to open device: " 314 USB_LOG(EVENT) << "Failed to open device: "
310 << ConvertPlatformUsbErrorToString(rv); 315 << ConvertPlatformUsbErrorToString(rv);
311 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); 316 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
(...skipping 18 matching lines...) Expand all
330 void UsbDeviceImpl::Opened(PlatformUsbDeviceHandle platform_handle, 335 void UsbDeviceImpl::Opened(PlatformUsbDeviceHandle platform_handle,
331 const OpenCallback& callback) { 336 const OpenCallback& callback) {
332 DCHECK(thread_checker_.CalledOnValidThread()); 337 DCHECK(thread_checker_.CalledOnValidThread());
333 scoped_refptr<UsbDeviceHandleImpl> device_handle = new UsbDeviceHandleImpl( 338 scoped_refptr<UsbDeviceHandleImpl> device_handle = new UsbDeviceHandleImpl(
334 context_, this, platform_handle, blocking_task_runner_); 339 context_, this, platform_handle, blocking_task_runner_);
335 handles_.push_back(device_handle); 340 handles_.push_back(device_handle);
336 callback.Run(device_handle); 341 callback.Run(device_handle);
337 } 342 }
338 343
339 } // namespace device 344 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_device_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698