Add owners for offlinepages
[chromium-blink-merge.git] / device / usb / usb_service.h
blob519feb6f5947dda25d15461b900f46929933b5aa
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 <string>
9 #include <vector>
11 #include "base/bind_helpers.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/threading/non_thread_safe.h"
17 namespace base {
18 class SequencedTaskRunner;
21 namespace device {
23 class UsbDevice;
25 // The USB service handles creating and managing an event handler thread that is
26 // used to manage and dispatch USB events. It is also responsible for device
27 // discovery on the system, which allows it to re-use device handles to prevent
28 // competition for the same USB device.
29 class UsbService : public base::NonThreadSafe {
30 public:
31 using GetDevicesCallback =
32 base::Callback<void(const std::vector<scoped_refptr<UsbDevice>>&)>;
34 class Observer {
35 public:
36 virtual ~Observer();
38 // These events are delivered from the thread on which the UsbService object
39 // was created.
40 virtual void OnDeviceAdded(scoped_refptr<UsbDevice> device);
41 virtual void OnDeviceRemoved(scoped_refptr<UsbDevice> device);
42 // For observers that need to process device removal after others have run.
43 // Should not depend on any other service's knowledge of connected devices.
44 virtual void OnDeviceRemovedCleanup(scoped_refptr<UsbDevice> device);
46 // Notifies the observer that the UsbService it depends on is shutting down.
47 virtual void WillDestroyUsbService();
50 // The file task runner reference is used for blocking I/O operations.
51 // Returns nullptr when initialization fails.
52 static scoped_ptr<UsbService> Create(
53 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
55 virtual ~UsbService();
57 virtual scoped_refptr<UsbDevice> GetDevice(const std::string& guid) = 0;
59 // Enumerates available devices.
60 virtual void GetDevices(const GetDevicesCallback& callback) = 0;
62 void AddObserver(Observer* observer);
63 void RemoveObserver(Observer* observer);
65 protected:
66 UsbService();
68 void NotifyDeviceAdded(scoped_refptr<UsbDevice> device);
69 void NotifyDeviceRemoved(scoped_refptr<UsbDevice> device);
71 base::ObserverList<Observer, true> observer_list_;
73 private:
74 friend void base::DeletePointer<UsbService>(UsbService* service);
76 DISALLOW_COPY_AND_ASSIGN(UsbService);
79 } // namespace device
81 #endif // DEVICE_USB_USB_SERVICE_H_