[Storage] Blob Storage Refactoring pt 1:
[chromium-blink-merge.git] / device / usb / usb_service.h
blob4655bfdbfa64d2ee640edbbde783f51aa10fc46c
1 // Copyright 2014 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.
5 #ifndef DEVICE_USB_USB_SERVICE_H_
6 #define DEVICE_USB_USB_SERVICE_H_
8 #include <vector>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/threading/non_thread_safe.h"
15 namespace base {
16 class SingleThreadTaskRunner;
19 namespace device {
21 class UsbDevice;
23 // The USB service handles creating and managing an event handler thread that is
24 // used to manage and dispatch USB events. It is also responsible for device
25 // discovery on the system, which allows it to re-use device handles to prevent
26 // competition for the same USB device.
28 // All functions on this object must be called from a thread with a
29 // MessageLoopForIO (for example, BrowserThread::FILE).
30 class UsbService : public base::NonThreadSafe {
31 public:
32 class Observer {
33 public:
34 // These events are delivered from the thread on which the UsbService object
35 // was created.
36 virtual void OnDeviceAdded(scoped_refptr<UsbDevice> device);
37 virtual void OnDeviceRemoved(scoped_refptr<UsbDevice> device);
40 // The UI task runner reference is used to talk to the PermissionBrokerClient
41 // on ChromeOS (UI thread). Returns NULL when initialization fails.
42 static UsbService* GetInstance(
43 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
45 static void SetInstanceForTest(UsbService* instance);
47 virtual scoped_refptr<UsbDevice> GetDeviceById(uint32 unique_id) = 0;
49 // Get all of the devices attached to the system, inserting them into
50 // |devices|. Clears |devices| before use. The result will be sorted by id
51 // in increasing order.
52 virtual void GetDevices(std::vector<scoped_refptr<UsbDevice> >* devices) = 0;
54 void AddObserver(Observer* observer);
55 void RemoveObserver(Observer* observer);
57 protected:
58 UsbService();
59 virtual ~UsbService();
61 void NotifyDeviceAdded(scoped_refptr<UsbDevice> device);
62 void NotifyDeviceRemoved(scoped_refptr<UsbDevice> device);
64 ObserverList<Observer, true> observer_list_;
66 private:
67 class Destroyer;
69 DISALLOW_COPY_AND_ASSIGN(UsbService);
72 } // namespace device
74 #endif // DEVICE_USB_USB_SERVICE_H_