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

Side by Side Diff: chrome/browser/usb/usb_service.h

Issue 12226137: Fix missing callback chaining in UsbService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 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 | « chrome/browser/extensions/api/usb/usb_api.cc ('k') | chrome/browser/usb/usb_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_USB_USB_SERVICE_H_ 5 #ifndef CHROME_BROWSER_USB_USB_SERVICE_H_
6 #define CHROME_BROWSER_USB_USB_SERVICE_H_ 6 #define CHROME_BROWSER_USB_USB_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 15 matching lines...) Expand all
26 public: 26 public:
27 UsbService(); 27 UsbService();
28 virtual ~UsbService(); 28 virtual ~UsbService();
29 29
30 // Cleanup must be invoked before the service is destroyed. It interrupts the 30 // Cleanup must be invoked before the service is destroyed. It interrupts the
31 // event handling thread and disposes of open devices. 31 // event handling thread and disposes of open devices.
32 void Cleanup(); 32 void Cleanup();
33 33
34 // Find all of the devices attached to the system that are identified by 34 // Find all of the devices attached to the system that are identified by
35 // |vendor_id| and |product_id|, inserting them into |devices|. Clears 35 // |vendor_id| and |product_id|, inserting them into |devices|. Clears
36 // |devices| before use. 36 // |devices| before use. Calls |callback| once |devices| is populated.
37 void FindDevices(const uint16 vendor_id, 37 void FindDevices(const uint16 vendor_id,
38 const uint16 product_id, 38 const uint16 product_id,
39 std::vector<scoped_refptr<UsbDevice> >* devices); 39 std::vector<scoped_refptr<UsbDevice> >* devices,
40 const base::Callback<void()>& callback);
40 41
41 // This function should not be called by normal code. It is invoked by a 42 // This function should not be called by normal code. It is invoked by a
42 // UsbDevice's Close function and disposes of the associated platform handle. 43 // UsbDevice's Close function and disposes of the associated platform handle.
43 void CloseDevice(scoped_refptr<UsbDevice> device); 44 void CloseDevice(scoped_refptr<UsbDevice> device);
44 45
45 private: 46 private:
46 // RefCountedPlatformUsbDevice takes care of managing the underlying reference 47 // RefCountedPlatformUsbDevice takes care of managing the underlying reference
47 // count of a single PlatformUsbDevice. This allows us to construct things 48 // count of a single PlatformUsbDevice. This allows us to construct things
48 // like vectors of RefCountedPlatformUsbDevices and not worry about having to 49 // like vectors of RefCountedPlatformUsbDevices and not worry about having to
49 // explicitly unreference them after use. 50 // explicitly unreference them after use.
(...skipping 16 matching lines...) Expand all
66 const uint16 vendor_id, 67 const uint16 vendor_id,
67 const uint16 product_id); 68 const uint16 product_id);
68 69
69 // FindDevicesImpl is called by FindDevices on ChromeOS after the permission 70 // FindDevicesImpl is called by FindDevices on ChromeOS after the permission
70 // broker has signalled that permission has been granted to access the 71 // broker has signalled that permission has been granted to access the
71 // underlying device nodes. On other platforms, it is called directly by 72 // underlying device nodes. On other platforms, it is called directly by
72 // FindDevices. 73 // FindDevices.
73 void FindDevicesImpl(const uint16 vendor_id, 74 void FindDevicesImpl(const uint16 vendor_id,
74 const uint16 product_id, 75 const uint16 product_id,
75 std::vector<scoped_refptr<UsbDevice> >* devices, 76 std::vector<scoped_refptr<UsbDevice> >* devices,
77 const base::Callback<void()>& callback,
76 bool success); 78 bool success);
77 79
78 // Populates |output| with the result of enumerating all attached USB devices. 80 // Populates |output| with the result of enumerating all attached USB devices.
79 void EnumerateDevices(DeviceVector* output); 81 void EnumerateDevices(DeviceVector* output);
80 82
81 // If a UsbDevice wrapper corresponding to |device| has already been created, 83 // If a UsbDevice wrapper corresponding to |device| has already been created,
82 // returns it. Otherwise, opens the device, creates a wrapper, and associates 84 // returns it. Otherwise, opens the device, creates a wrapper, and associates
83 // the wrapper with the device internally. 85 // the wrapper with the device internally.
84 UsbDevice* LookupOrCreateDevice(PlatformUsbDevice device); 86 UsbDevice* LookupOrCreateDevice(PlatformUsbDevice device);
85 87
86 PlatformUsbContext context_; 88 PlatformUsbContext context_;
87 UsbEventHandler* event_handler_; 89 UsbEventHandler* event_handler_;
88 90
89 // The devices_ map contains scoped_refptrs to all open devices, indicated by 91 // The devices_ map contains scoped_refptrs to all open devices, indicated by
90 // their vendor and product id. This allows for reusing an open device without 92 // their vendor and product id. This allows for reusing an open device without
91 // creating another platform handle for it. 93 // creating another platform handle for it.
92 typedef std::map<PlatformUsbDevice, scoped_refptr<UsbDevice> > DeviceMap; 94 typedef std::map<PlatformUsbDevice, scoped_refptr<UsbDevice> > DeviceMap;
93 DeviceMap devices_; 95 DeviceMap devices_;
94 96
95 DISALLOW_COPY_AND_ASSIGN(UsbService); 97 DISALLOW_COPY_AND_ASSIGN(UsbService);
96 }; 98 };
97 99
98 #endif // CHROME_BROWSER_USB_USB_SERVICE_H_ 100 #endif // CHROME_BROWSER_USB_USB_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/usb/usb_api.cc ('k') | chrome/browser/usb/usb_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698