OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ | |
7 #pragma once | |
8 | |
9 #include <set> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/linked_ptr.h" | |
13 #include "base/synchronization/lock.h" | |
14 #include "chrome/browser/extensions/api/api_resource.h" | |
15 #include "chrome/common/extensions/api/experimental.usb.h" | |
16 | |
17 class UsbDevice; | |
18 | |
19 namespace net { | |
20 class IOBuffer; | |
21 } // namespace net | |
22 | |
23 namespace extensions { | |
24 | |
25 class APIResourceEventNotifier; | |
26 | |
27 // A UsbDeviceResource is an APIResource wrapper for a UsbDevice. When invoking | |
28 // transfers on the underlying device it will use the APIResourceEventNotifier | |
29 // associated with the underlying APIResource to deliver completion messages. | |
30 class UsbDeviceResource : public APIResource { | |
31 public: | |
32 UsbDeviceResource(APIResourceEventNotifier* notifier, UsbDevice* device); | |
33 virtual ~UsbDeviceResource(); | |
34 | |
35 // All of the *Transfer variants that are exposed here adapt their arguments | |
36 // for the underlying UsbDevice's interface and invoke the corresponding | |
37 // methods with completion callbacks that call OnTransferComplete on the event | |
38 // notifier. | |
39 void ControlTransfer( | |
40 const api::experimental_usb::ControlTransferInfo& transfer); | |
41 void InterruptTransfer( | |
42 const api::experimental_usb::GenericTransferInfo& transfer); | |
43 void BulkTransfer(const api::experimental_usb::GenericTransferInfo& transfer); | |
44 | |
45 private: | |
46 // Invoked by the underlying device's transfer callbacks. Indicates transfer | |
47 // completion to the APIResource's event notifier. | |
48 void TransferComplete(net::IOBuffer* buffer, const size_t length, | |
49 int success); | |
50 | |
51 scoped_refptr<UsbDevice> device_; | |
52 | |
53 // pending_transfers_ is used to track the number of transfers that are | |
54 // currently in flight. Access to pending_transfers_ is protected by lock_. | |
55 base::Lock lock_; | |
asargent_no_longer_on_chrome
2012/04/26 21:21:45
Danger Will Robinson! We almost never want to do e
Garret Kelly
2012/04/27 00:32:35
Hmm, then perhaps I need to do a bit more thinking
| |
56 int pending_transfers_; | |
57 | |
58 DISALLOW_EVIL_CONSTRUCTORS(UsbDeviceResource); | |
asargent_no_longer_on_chrome
2012/04/26 21:21:45
nit: I think the synonym DISALLOW_COPY_AND_ASSIGN
Garret Kelly
2012/04/27 00:32:35
Oh yeah, I'd forgotten about that. Done.
| |
59 }; | |
60 | |
61 } // namespace extensions | |
62 | |
63 #endif // CHROME_BROWSER_EXTENSIONS_API_USB_USB_DEVICE_RESOURCE_H_ | |
OLD | NEW |