diff options
author | reillyg <reillyg@chromium.org> | 2015-06-04 08:15:21 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-04 15:16:00 +0000 |
commit | fb5ccfe3a075c08c1ed886898339af3287800a4f (patch) | |
tree | 2f986637cbb203ed4b9e05d98f01ff6296a2dea7 /device | |
parent | cbd48d197363d75fc05465698655f668cb3952ef (diff) | |
download | chromium_src-fb5ccfe3a075c08c1ed886898339af3287800a4f.zip chromium_src-fb5ccfe3a075c08c1ed886898339af3287800a4f.tar.gz chromium_src-fb5ccfe3a075c08c1ed886898339af3287800a4f.tar.bz2 |
Invoke RequestPathAccess implicitly in UsbDevice::Open.
In preparation for changing how USB device access is granted this patch
makes the call to request access to the USB device node implicit in the
call to open the device.
BUG=496469
Review URL: https://codereview.chromium.org/1147213006
Cr-Commit-Position: refs/heads/master@{#332831}
Diffstat (limited to 'device')
-rw-r--r-- | device/usb/usb_device.cc | 8 | ||||
-rw-r--r-- | device/usb/usb_device.h | 4 | ||||
-rw-r--r-- | device/usb/usb_device_impl.cc | 34 | ||||
-rw-r--r-- | device/usb/usb_device_impl.h | 6 |
4 files changed, 30 insertions, 22 deletions
diff --git a/device/usb/usb_device.cc b/device/usb/usb_device.cc index 2be93d9..bd7a7aa 100644 --- a/device/usb/usb_device.cc +++ b/device/usb/usb_device.cc @@ -25,12 +25,8 @@ UsbDevice::~UsbDevice() { } void UsbDevice::CheckUsbAccess(const ResultCallback& callback) { - callback.Run(true); -} - -// Like CheckUsbAccess but actually changes the ownership of the device node. -void UsbDevice::RequestUsbAccess(int interface_id, - const ResultCallback& callback) { + // By default assume that access to the device is allowed. This is implemented + // on Chrome OS by checking with permission_broker. callback.Run(true); } diff --git a/device/usb/usb_device.h b/device/usb/usb_device.h index 1054a3b..cd5edd2 100644 --- a/device/usb/usb_device.h +++ b/device/usb/usb_device.h @@ -43,10 +43,6 @@ class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { // functions are no-ops and always return true. virtual void CheckUsbAccess(const ResultCallback& callback); - // Like CheckUsbAccess but actually changes the ownership of the device node. - virtual void RequestUsbAccess(int interface_id, - const ResultCallback& callback); - // Creates a UsbDeviceHandle for further manipulation. virtual void Open(const OpenCallback& callback) = 0; diff --git a/device/usb/usb_device_impl.cc b/device/usb/usb_device_impl.cc index 217c5c3a..931e505 100644 --- a/device/usb/usb_device_impl.cc +++ b/device/usb/usb_device_impl.cc @@ -132,22 +132,23 @@ void UsbDeviceImpl::CheckUsbAccess(const ResultCallback& callback) { client->CheckPathAccess(devnode_, callback); } -void UsbDeviceImpl::RequestUsbAccess(int interface_id, - const ResultCallback& callback) { +#endif // defined(OS_CHROMEOS) + +void UsbDeviceImpl::Open(const OpenCallback& callback) { DCHECK(thread_checker_.CalledOnValidThread()); + +#if defined(OS_CHROMEOS) chromeos::PermissionBrokerClient* client = chromeos::DBusThreadManager::Get()->GetPermissionBrokerClient(); DCHECK(client) << "Could not get permission broker client."; - client->RequestPathAccess(devnode_, interface_id, callback); -} - -#endif - -void UsbDeviceImpl::Open(const OpenCallback& callback) { - DCHECK(thread_checker_.CalledOnValidThread()); + client->RequestPathAccess( + devnode_, -1, + base::Bind(&UsbDeviceImpl::OnPathRequestComplete, this, callback)); +#else blocking_task_runner_->PostTask( FROM_HERE, base::Bind(&UsbDeviceImpl::OpenOnBlockingThread, this, callback)); +#endif // defined(OS_CHROMEOS) } bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) { @@ -247,6 +248,21 @@ void UsbDeviceImpl::RefreshConfiguration() { libusb_free_config_descriptor(platform_config); } +#if defined(OS_CHROMEOS) + +void UsbDeviceImpl::OnPathRequestComplete(const OpenCallback& callback, + bool success) { + if (success) { + blocking_task_runner_->PostTask( + FROM_HERE, + base::Bind(&UsbDeviceImpl::OpenOnBlockingThread, this, callback)); + } else { + callback.Run(nullptr); + } +} + +#endif // defined(OS_CHROMEOS) + void UsbDeviceImpl::OpenOnBlockingThread(const OpenCallback& callback) { PlatformUsbDeviceHandle handle; const int rv = libusb_open(platform_device_, &handle); diff --git a/device/usb/usb_device_impl.h b/device/usb/usb_device_impl.h index 76ede33..5dd856a 100644 --- a/device/usb/usb_device_impl.h +++ b/device/usb/usb_device_impl.h @@ -34,10 +34,7 @@ class UsbDeviceImpl : public UsbDevice { public: // UsbDevice implementation: #if defined(OS_CHROMEOS) - // Only overridden on Chrome OS. void CheckUsbAccess(const ResultCallback& callback) override; - void RequestUsbAccess(int interface_id, - const ResultCallback& callback) override; #endif // OS_CHROMEOS void Open(const OpenCallback& callback) override; bool Close(scoped_refptr<UsbDeviceHandle> handle) override; @@ -70,6 +67,9 @@ class UsbDeviceImpl : public UsbDevice { void RefreshConfiguration(); private: +#if defined(OS_CHROMEOS) + void OnPathRequestComplete(const OpenCallback& callback, bool success); +#endif void OpenOnBlockingThread(const OpenCallback& callback); void Opened(PlatformUsbDeviceHandle platform_handle, const OpenCallback& callback); |