Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / device / usb / usb_service.h
bloba2dfa9ec9151368a0acde32b39cf07f2168f9c75
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);
38 // For observers that need to process device removal after others have run.
39 // Should not depend on any other service's knowledge of connected devices.
40 virtual void OnDeviceRemovedCleanup(scoped_refptr<UsbDevice> device);
43 // The UI task runner reference is used to talk to the PermissionBrokerClient
44 // on ChromeOS (UI thread). Returns NULL when initialization fails.
45 static UsbService* GetInstance(
46 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
48 static void SetInstanceForTest(UsbService* instance);
50 virtual scoped_refptr<UsbDevice> GetDeviceById(uint32 unique_id) = 0;
52 // Get all of the devices attached to the system, inserting them into
53 // |devices|. Clears |devices| before use. The result will be sorted by id
54 // in increasing order.
55 virtual void GetDevices(std::vector<scoped_refptr<UsbDevice> >* devices) = 0;
57 void AddObserver(Observer* observer);
58 void RemoveObserver(Observer* observer);
60 protected:
61 UsbService();
62 virtual ~UsbService();
64 void NotifyDeviceAdded(scoped_refptr<UsbDevice> device);
65 void NotifyDeviceRemoved(scoped_refptr<UsbDevice> device);
67 ObserverList<Observer, true> observer_list_;
69 private:
70 class Destroyer;
72 DISALLOW_COPY_AND_ASSIGN(UsbService);
75 } // namespace device
77 #endif // DEVICE_USB_USB_SERVICE_H_