Chromium Code Reviews| Index: extensions/browser/api/usb/usb_api.h |
| diff --git a/extensions/browser/api/usb/usb_api.h b/extensions/browser/api/usb/usb_api.h |
| index 8903348a3ba06b38c5c608a0d20b0d9b1b70515f..c7ab6c3c33fb5189573906a69906101f15cfd6b5 100644 |
| --- a/extensions/browser/api/usb/usb_api.h |
| +++ b/extensions/browser/api/usb/usb_api.h |
| @@ -14,8 +14,8 @@ |
| #include "device/usb/usb_device_filter.h" |
| #include "device/usb/usb_device_handle.h" |
| #include "extensions/browser/api/api_resource_manager.h" |
| -#include "extensions/browser/api/async_api_function.h" |
| #include "extensions/browser/api/device_permissions_prompt.h" |
| +#include "extensions/browser/extension_function.h" |
| #include "extensions/common/api/usb.h" |
| #include "net/base/io_buffer.h" |
| @@ -26,83 +26,86 @@ class DevicePermissions; |
| class DevicePermissionsManager; |
| class UsbDeviceResource; |
| -class UsbAsyncApiFunction : public AsyncApiFunction { |
| - public: |
| - UsbAsyncApiFunction(); |
| - |
| +class UsbPermissionCheckingFunction : public UIThreadExtensionFunction { |
|
Ken Rockot(use gerrit already)
2015/04/08 07:45:57
Inheritance seems like overkill for this. What abo
Reilly Grant (use Gerrit)
2015/04/08 21:39:04
It's helpful to have access to ExtensionFunction m
|
| protected: |
| - ~UsbAsyncApiFunction() override; |
| - |
| - // AsyncApiFunction: |
| - bool PrePrepare() override; |
| - bool Respond() override; |
| + UsbPermissionCheckingFunction(); |
| + ~UsbPermissionCheckingFunction() override; |
| bool HasDevicePermission(scoped_refptr<device::UsbDevice> device); |
| - scoped_refptr<device::UsbDeviceHandle> GetDeviceHandleOrCompleteWithError( |
| - const extensions::core_api::usb::ConnectionHandle& input_device_handle); |
| - void RemoveUsbDeviceResource(int api_resource_id); |
| - void CompleteWithError(const std::string& error); |
| + void RecordDeviceLastUsed(); |
| - ApiResourceManager<UsbDeviceResource>* manager_; |
| - scoped_ptr<DevicePermissions> device_permissions_; |
| + private: |
| + DevicePermissionsManager* device_permissions_manager_; |
| scoped_refptr<DevicePermissionEntry> permission_entry_; |
| }; |
| -class UsbAsyncApiTransferFunction : public UsbAsyncApiFunction { |
| +class UsbConnectionFunction : public UIThreadExtensionFunction { |
| protected: |
| - UsbAsyncApiTransferFunction(); |
| - ~UsbAsyncApiTransferFunction() override; |
| - |
| - bool ConvertDirectionSafely(const extensions::core_api::usb::Direction& input, |
| - device::UsbEndpointDirection* output); |
| - bool ConvertRequestTypeSafely( |
| - const extensions::core_api::usb::RequestType& input, |
| - device::UsbDeviceHandle::TransferRequestType* output); |
| - bool ConvertRecipientSafely( |
| - const extensions::core_api::usb::Recipient& input, |
| - device::UsbDeviceHandle::TransferRecipient* output); |
| + UsbConnectionFunction(); |
| + ~UsbConnectionFunction() override; |
| + |
| + scoped_refptr<device::UsbDeviceHandle> GetDeviceHandle( |
| + const extensions::core_api::usb::ConnectionHandle& handle); |
| + void ReleaseDeviceHandle( |
| + const extensions::core_api::usb::ConnectionHandle& handle); |
| +}; |
| + |
| +class UsbTransferFunction : public UsbConnectionFunction { |
| + protected: |
| + UsbTransferFunction(); |
| + ~UsbTransferFunction() override; |
| void OnCompleted(device::UsbTransferStatus status, |
| scoped_refptr<net::IOBuffer> data, |
| size_t length); |
| }; |
| -class UsbFindDevicesFunction : public UsbAsyncApiFunction { |
| +class UsbFindDevicesFunction : public UIThreadExtensionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES) |
| UsbFindDevicesFunction(); |
| - protected: |
| + private: |
| ~UsbFindDevicesFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| + |
| + void OnGetDevicesComplete( |
| + const std::vector<scoped_refptr<device::UsbDevice>>& devices); |
| + void OnRequestAccessComplete(scoped_refptr<device::UsbDevice> device, |
| + bool success); |
| + void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle); |
| + void OpenComplete(); |
| - private: |
| - void OpenDevices( |
| - scoped_ptr<std::vector<scoped_refptr<device::UsbDevice> > > devices); |
| + uint16_t vendor_id_; |
| + uint16_t product_id_; |
| + int interface_id_; |
| + scoped_ptr<base::ListValue> result_; |
| + base::Closure barrier_; |
| - std::vector<scoped_refptr<device::UsbDeviceHandle> > device_handles_; |
| - scoped_ptr<extensions::core_api::usb::FindDevices::Params> parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbFindDevicesFunction); |
| }; |
| -class UsbGetDevicesFunction : public UsbAsyncApiFunction { |
| +class UsbGetDevicesFunction : public UsbPermissionCheckingFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES) |
| UsbGetDevicesFunction(); |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| - |
| - protected: |
| + private: |
| ~UsbGetDevicesFunction() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::GetDevices::Params> parameters_; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| + |
| + void OnGetDevicesComplete( |
| + const std::vector<scoped_refptr<device::UsbDevice>>& devices); |
| + |
| + std::vector<device::UsbDeviceFilter> filters_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UsbGetDevicesFunction); |
| }; |
| class UsbGetUserSelectedDevicesFunction |
| @@ -114,130 +117,117 @@ class UsbGetUserSelectedDevicesFunction |
| UsbGetUserSelectedDevicesFunction(); |
| - protected: |
| + private: |
| ~UsbGetUserSelectedDevicesFunction() override; |
| // ExtensionFunction: |
| ResponseAction Run() override; |
| - private: |
| void OnUsbDevicesChosen( |
| const std::vector<scoped_refptr<device::UsbDevice>>& devices) override; |
| scoped_ptr<DevicePermissionsPrompt> prompt_; |
| - std::vector<uint32> device_ids_; |
| - std::vector<scoped_refptr<device::UsbDevice>> devices_; |
| - std::vector<base::string16> serial_numbers_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UsbGetUserSelectedDevicesFunction); |
| }; |
| -class UsbRequestAccessFunction : public UsbAsyncApiFunction { |
| +class UsbRequestAccessFunction : public UIThreadExtensionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS) |
| UsbRequestAccessFunction(); |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| - |
| - protected: |
| + private: |
| ~UsbRequestAccessFunction() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::RequestAccess::Params> parameters_; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UsbRequestAccessFunction); |
| }; |
| -class UsbOpenDeviceFunction : public UsbAsyncApiFunction { |
| +class UsbOpenDeviceFunction : public UsbPermissionCheckingFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE) |
| UsbOpenDeviceFunction(); |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| - bool Respond() override; |
| - |
| - protected: |
| + private: |
| ~UsbOpenDeviceFunction() override; |
| - private: |
| - void OnRequestAccessComplete(bool success); |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| - DevicePermissionsManager* device_permissions_manager_; |
| - scoped_refptr<device::UsbDevice> device_; |
| - scoped_ptr<extensions::core_api::usb::OpenDevice::Params> parameters_; |
| + void OnRequestAccessComplete(scoped_refptr<device::UsbDevice> device, |
| + bool success); |
| + void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UsbOpenDeviceFunction); |
| }; |
| -class UsbSetConfigurationFunction : public UsbAsyncApiFunction { |
| +class UsbSetConfigurationFunction : public UsbConnectionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.setConfiguration", USB_SETCONFIGURATION) |
| UsbSetConfigurationFunction(); |
| - protected: |
| + private: |
| ~UsbSetConfigurationFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::SetConfiguration::Params> parameters_; |
| + void OnComplete(bool success); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UsbSetConfigurationFunction); |
| }; |
| -class UsbGetConfigurationFunction : public UsbAsyncApiFunction { |
| +class UsbGetConfigurationFunction : public UsbConnectionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.getConfiguration", USB_GETCONFIGURATION) |
| UsbGetConfigurationFunction(); |
| - protected: |
| + private: |
| ~UsbGetConfigurationFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::GetConfiguration::Params> parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbGetConfigurationFunction); |
| }; |
| -class UsbListInterfacesFunction : public UsbAsyncApiFunction { |
| +class UsbListInterfacesFunction : public UsbConnectionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES) |
| UsbListInterfacesFunction(); |
| - protected: |
| + private: |
| ~UsbListInterfacesFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::ListInterfaces::Params> parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbListInterfacesFunction); |
| }; |
| -class UsbCloseDeviceFunction : public UsbAsyncApiFunction { |
| +class UsbCloseDeviceFunction : public UsbConnectionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE) |
| UsbCloseDeviceFunction(); |
| - protected: |
| + private: |
| ~UsbCloseDeviceFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::CloseDevice::Params> parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbCloseDeviceFunction); |
| }; |
| -class UsbClaimInterfaceFunction : public UsbAsyncApiFunction { |
| +class UsbClaimInterfaceFunction : public UsbConnectionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE) |
| @@ -246,32 +236,30 @@ class UsbClaimInterfaceFunction : public UsbAsyncApiFunction { |
| protected: |
| ~UsbClaimInterfaceFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| + |
| + void OnComplete(bool success); |
| - private: |
| - scoped_ptr<extensions::core_api::usb::ClaimInterface::Params> parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbClaimInterfaceFunction); |
| }; |
| -class UsbReleaseInterfaceFunction : public UsbAsyncApiFunction { |
| +class UsbReleaseInterfaceFunction : public UsbConnectionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.releaseInterface", USB_RELEASEINTERFACE) |
| UsbReleaseInterfaceFunction(); |
| - protected: |
| + private: |
| ~UsbReleaseInterfaceFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::ReleaseInterface::Params> parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbReleaseInterfaceFunction); |
| }; |
| -class UsbSetInterfaceAlternateSettingFunction : public UsbAsyncApiFunction { |
| +class UsbSetInterfaceAlternateSettingFunction : public UsbConnectionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.setInterfaceAlternateSetting", |
| USB_SETINTERFACEALTERNATESETTING) |
| @@ -281,98 +269,91 @@ class UsbSetInterfaceAlternateSettingFunction : public UsbAsyncApiFunction { |
| private: |
| ~UsbSetInterfaceAlternateSettingFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| + |
| + void OnComplete(bool success); |
| - scoped_ptr<extensions::core_api::usb::SetInterfaceAlternateSetting::Params> |
| - parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbSetInterfaceAlternateSettingFunction); |
| }; |
| -class UsbControlTransferFunction : public UsbAsyncApiTransferFunction { |
| +class UsbControlTransferFunction : public UsbTransferFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.controlTransfer", USB_CONTROLTRANSFER) |
| UsbControlTransferFunction(); |
| - protected: |
| + private: |
| ~UsbControlTransferFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::ControlTransfer::Params> parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbControlTransferFunction); |
| }; |
| -class UsbBulkTransferFunction : public UsbAsyncApiTransferFunction { |
| +class UsbBulkTransferFunction : public UsbTransferFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.bulkTransfer", USB_BULKTRANSFER) |
| UsbBulkTransferFunction(); |
| - protected: |
| + private: |
| ~UsbBulkTransferFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::BulkTransfer::Params> parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbBulkTransferFunction); |
| }; |
| -class UsbInterruptTransferFunction : public UsbAsyncApiTransferFunction { |
| +class UsbInterruptTransferFunction : public UsbTransferFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER) |
| UsbInterruptTransferFunction(); |
| - protected: |
| + private: |
| ~UsbInterruptTransferFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::InterruptTransfer::Params> parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbInterruptTransferFunction); |
| }; |
| -class UsbIsochronousTransferFunction : public UsbAsyncApiTransferFunction { |
| +class UsbIsochronousTransferFunction : public UsbTransferFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.isochronousTransfer", USB_ISOCHRONOUSTRANSFER) |
| UsbIsochronousTransferFunction(); |
| - protected: |
| + private: |
| ~UsbIsochronousTransferFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| - private: |
| - scoped_ptr<extensions::core_api::usb::IsochronousTransfer::Params> |
| - parameters_; |
| + DISALLOW_COPY_AND_ASSIGN(UsbIsochronousTransferFunction); |
| }; |
| -class UsbResetDeviceFunction : public UsbAsyncApiFunction { |
| +class UsbResetDeviceFunction : public UsbConnectionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION("usb.resetDevice", USB_RESETDEVICE) |
| UsbResetDeviceFunction(); |
| - protected: |
| + private: |
| ~UsbResetDeviceFunction() override; |
| - // AsyncApiFunction: |
| - bool Prepare() override; |
| - void AsyncWorkStart() override; |
| + // ExtensionFunction: |
| + ResponseAction Run() override; |
| + |
| + void OnComplete(bool success); |
| - private: |
| scoped_ptr<extensions::core_api::usb::ResetDevice::Params> parameters_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UsbResetDeviceFunction); |
| }; |
| } // namespace extensions |