OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 EXTENSIONS_BROWSER_API_USB_USB_EVENT_ROUTER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_USB_USB_EVENT_ROUTER_H_ |
6 #define EXTENSIONS_BROWSER_API_USB_USB_EVENT_ROUTER_H_ | 6 #define EXTENSIONS_BROWSER_API_USB_USB_EVENT_ROUTER_H_ |
7 | 7 |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "device/usb/usb_service.h" |
9 #include "extensions/browser/browser_context_keyed_api_factory.h" | 10 #include "extensions/browser/browser_context_keyed_api_factory.h" |
10 #include "extensions/browser/event_router.h" | 11 #include "extensions/browser/event_router.h" |
11 | 12 |
12 namespace device { | 13 namespace device { |
13 class UsbDevice; | 14 class UsbDevice; |
14 } | 15 } |
15 | 16 |
16 namespace extensions { | 17 namespace extensions { |
17 | 18 |
18 // A BrowserContext-scoped object which is registered as an observer of the | 19 // A BrowserContext-scoped object which is registered as an observer of the |
19 // EventRouter and UsbService in order to generate device add/remove events. | 20 // EventRouter and UsbService in order to generate device add/remove events. |
20 class UsbEventRouter : public BrowserContextKeyedAPI, | 21 class UsbEventRouter : public BrowserContextKeyedAPI, |
21 public EventRouter::Observer { | 22 public EventRouter::Observer, |
| 23 public device::UsbService::Observer { |
22 public: | 24 public: |
23 // BrowserContextKeyedAPI implementation. | 25 // BrowserContextKeyedAPI implementation. |
24 static BrowserContextKeyedAPIFactory<UsbEventRouter>* GetFactoryInstance(); | 26 static BrowserContextKeyedAPIFactory<UsbEventRouter>* GetFactoryInstance(); |
25 | 27 |
26 private: | 28 private: |
27 friend class BrowserContextKeyedAPIFactory<UsbEventRouter>; | 29 friend class BrowserContextKeyedAPIFactory<UsbEventRouter>; |
28 | 30 |
29 class FileThreadHelper; | |
30 | |
31 explicit UsbEventRouter(content::BrowserContext* context); | 31 explicit UsbEventRouter(content::BrowserContext* context); |
32 ~UsbEventRouter() override; | 32 ~UsbEventRouter() override; |
33 | 33 |
34 // BrowserContextKeyedAPI implementation. | 34 // BrowserContextKeyedAPI implementation. |
35 static const char* service_name() { return "UsbEventRouter"; } | 35 static const char* service_name() { return "UsbEventRouter"; } |
36 static const bool kServiceIsNULLWhileTesting = true; | 36 static const bool kServiceIsNULLWhileTesting = true; |
37 | 37 |
38 // KeyedService implementation. | 38 // KeyedService implementation. |
39 void Shutdown() override; | 39 void Shutdown() override; |
40 | 40 |
41 // EventRouter::Observer implementation. | 41 // EventRouter::Observer implementation. |
42 void OnListenerAdded(const EventListenerInfo& details) override; | 42 void OnListenerAdded(const EventListenerInfo& details) override; |
43 | 43 |
| 44 // UsbService::Observer implementation. |
| 45 void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override; |
| 46 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override; |
| 47 |
44 // Broadcasts a device add or remove event for the given device. | 48 // Broadcasts a device add or remove event for the given device. |
45 void DispatchEvent(const std::string& event_name, | 49 void DispatchEvent(const std::string& event_name, |
46 scoped_refptr<device::UsbDevice> device, | 50 scoped_refptr<device::UsbDevice> device); |
47 const base::string16& serial_number); | |
48 | 51 |
49 content::BrowserContext* const browser_context_; | 52 content::BrowserContext* const browser_context_; |
50 scoped_ptr<FileThreadHelper, content::BrowserThread::DeleteOnFileThread> | |
51 helper_; | |
52 | 53 |
53 base::WeakPtrFactory<UsbEventRouter> weak_factory_; | 54 ScopedObserver<device::UsbService, device::UsbService::Observer> observer_; |
54 | 55 |
55 DISALLOW_COPY_AND_ASSIGN(UsbEventRouter); | 56 DISALLOW_COPY_AND_ASSIGN(UsbEventRouter); |
56 }; | 57 }; |
57 | 58 |
58 } // namespace extensions | 59 } // namespace extensions |
59 | 60 |
60 #endif // EXTENSIONS_BROWSER_API_USB_USB_EVENT_ROUTER_H_ | 61 #endif // EXTENSIONS_BROWSER_API_USB_USB_EVENT_ROUTER_H_ |
OLD | NEW |