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

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

Issue 236203019: Move UsbService to its own component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move usb_service component symbols into usb_service namespace Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/usb/usb_interface.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
(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_USB_USB_SERVICE_H_
6 #define CHROME_BROWSER_USB_USB_SERVICE_H_
7
8 #include <map>
9 #include <utility>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/threading/non_thread_safe.h"
17
18 typedef struct libusb_device* PlatformUsbDevice;
19 typedef struct libusb_context* PlatformUsbContext;
20
21 class UsbContext;
22 class UsbDevice;
23
24 // The USB service handles creating and managing an event handler thread that is
25 // used to manage and dispatch USB events. It is also responsible for device
26 // discovery on the system, which allows it to re-use device handles to prevent
27 // competition for the same USB device.
28 class UsbService : public base::MessageLoop::DestructionObserver,
29 public base::NonThreadSafe {
30 public:
31 typedef scoped_ptr<std::vector<scoped_refptr<UsbDevice> > >
32 ScopedDeviceVector;
33
34 // Must be called on FILE thread.
35 // Returns NULL when failed to initialized.
36 static UsbService* GetInstance();
37
38 scoped_refptr<UsbDevice> GetDeviceById(uint32 unique_id);
39
40 // Get all of the devices attached to the system, inserting them into
41 // |devices|. Clears |devices| before use. The result will be sorted by id
42 // in increasing order. Must be called on FILE thread.
43 void GetDevices(std::vector<scoped_refptr<UsbDevice> >* devices);
44
45 // base::MessageLoop::DestructionObserver implementation.
46 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
47
48 private:
49 friend struct base::DefaultDeleter<UsbService>;
50
51 explicit UsbService(PlatformUsbContext context);
52 virtual ~UsbService();
53
54 // Enumerate USB devices from OS and Update devices_ map.
55 void RefreshDevices();
56
57 scoped_refptr<UsbContext> context_;
58
59 // TODO(ikarienator): Figure out a better solution.
60 uint32 next_unique_id_;
61
62 // The map from PlatformUsbDevices to UsbDevices.
63 typedef std::map<PlatformUsbDevice, scoped_refptr<UsbDevice> > DeviceMap;
64 DeviceMap devices_;
65
66 DISALLOW_COPY_AND_ASSIGN(UsbService);
67 };
68
69 #endif // CHROME_BROWSER_USB_USB_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/usb/usb_interface.cc ('k') | chrome/browser/usb/usb_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698