| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 14 #include "chrome/browser/extensions/api/api_resource.h" | 15 #include "chrome/browser/extensions/api/api_resource.h" |
| 15 #include "chrome/browser/extensions/api/api_resource_manager.h" | 16 #include "chrome/browser/extensions/api/api_resource_manager.h" |
| 16 #include "chrome/browser/usb/usb_device.h" | 17 #include "chrome/browser/usb/usb_device.h" |
| 17 #include "chrome/common/extensions/api/usb.h" | 18 #include "chrome/common/extensions/api/usb.h" |
| 18 | 19 |
| 19 class UsbDevice; | 20 class UsbDevice; |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 class IOBuffer; | 23 class IOBuffer; |
| 23 } // namespace net | 24 } // namespace net |
| 24 | 25 |
| 25 namespace extensions { | 26 namespace extensions { |
| 26 | 27 |
| 27 // A UsbDeviceResource is an ApiResource wrapper for a UsbDevice. | 28 // A UsbDeviceResource is an ApiResource wrapper for a UsbDevice. |
| 29 // It will redirect all the requests on the FILE thread if necessary. |
| 28 class UsbDeviceResource : public ApiResource { | 30 class UsbDeviceResource : public ApiResource { |
| 29 public: | 31 public: |
| 30 UsbDeviceResource(const std::string& owner_extension_id, | 32 UsbDeviceResource(const std::string& owner_extension_id, |
| 31 scoped_refptr<UsbDevice> device); | 33 scoped_refptr<UsbDevice> device); |
| 32 virtual ~UsbDeviceResource(); | 34 virtual ~UsbDeviceResource(); |
| 33 | 35 |
| 34 scoped_refptr<UsbDevice> device() { | 36 virtual void Close(const base::Callback<void()>& callback); |
| 35 return device_; | 37 |
| 36 } | 38 virtual void ListInterfaces(UsbConfigDescriptor* config, |
| 39 const UsbInterfaceCallback& callback); |
| 40 |
| 41 virtual void ClaimInterface(const int interface_number, |
| 42 const UsbInterfaceCallback& callback); |
| 43 |
| 44 virtual void ReleaseInterface(const int interface_number, |
| 45 const UsbInterfaceCallback& callback); |
| 46 |
| 47 virtual void SetInterfaceAlternateSetting( |
| 48 const int interface_number, |
| 49 const int alternate_setting, |
| 50 const UsbInterfaceCallback& callback); |
| 51 |
| 52 virtual void ControlTransfer( |
| 53 const UsbEndpointDirection direction, |
| 54 const UsbDevice::TransferRequestType request_type, |
| 55 const UsbDevice::TransferRecipient recipient, |
| 56 const uint8 request, |
| 57 const uint16 value, const uint16 index, net::IOBuffer* buffer, |
| 58 const size_t length, const unsigned int timeout, |
| 59 const UsbTransferCallback& callback); |
| 60 |
| 61 virtual void BulkTransfer(const UsbEndpointDirection direction, |
| 62 const uint8 endpoint, net::IOBuffer* buffer, |
| 63 const size_t length, |
| 64 const unsigned int timeout, |
| 65 const UsbTransferCallback& callback); |
| 66 |
| 67 virtual void InterruptTransfer(const UsbEndpointDirection direction, |
| 68 const uint8 endpoint, net::IOBuffer* buffer, |
| 69 const size_t length, |
| 70 const unsigned int timeout, |
| 71 const UsbTransferCallback& callback); |
| 72 |
| 73 virtual void IsochronousTransfer(const UsbEndpointDirection direction, |
| 74 const uint8 endpoint, net::IOBuffer* buffer, |
| 75 const size_t length, |
| 76 const unsigned int packets, |
| 77 const unsigned int packet_length, |
| 78 const unsigned int timeout, |
| 79 const UsbTransferCallback& callback); |
| 80 |
| 81 virtual void ResetDevice(const UsbResetDeviceCallback& callback); |
| 37 | 82 |
| 38 private: | 83 private: |
| 39 friend class ApiResourceManager<UsbDeviceResource>; | 84 friend class ApiResourceManager<UsbDeviceResource>; |
| 40 static const char* service_name() { | 85 static const char* service_name() { |
| 41 return "UsbDeviceResourceManager"; | 86 return "UsbDeviceResourceManager"; |
| 42 } | 87 } |
| 43 | 88 |
| 44 scoped_refptr<UsbDevice> device_; | 89 scoped_refptr<UsbDevice> device_; |
| 45 | 90 |
| 46 DISALLOW_COPY_AND_ASSIGN(UsbDeviceResource); | 91 DISALLOW_COPY_AND_ASSIGN(UsbDeviceResource); |
| 47 }; | 92 }; |
| 48 | 93 |
| 49 } // namespace extensions | 94 } // namespace extensions |
| 50 | 95 |
| 51 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ | 96 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ |
| OLD | NEW |