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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_PRINTER_DETECTOR_H_
6 #define CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_PRINTER_DETECTOR_H_
10 #include "base/memory/weak_ptr.h"
11 #include "base/scoped_observer.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "device/usb/usb_service.h"
15 class NotificationUIManager
;
24 // Observes device::UsbService for addition of USB printers (devices with
25 // interface class 7).
26 // When a printer is detected, a shows a notification depending on whether there
27 // are printer provider apps that declared support for the USB device installed.
28 // If such app exists, the notification notifies the user the printer is ready.
29 // Otherwise the notification offers user to search Chrome Web Store for apps
30 // that support the printer. Clicking the notification launches webstore_widget
31 // app for the printer.
32 // The notification is shown only for active user's profile.
33 class PrinterDetector
: public KeyedService
,
34 public device::UsbService::Observer
{
36 explicit PrinterDetector(Profile
* profile
);
37 ~PrinterDetector() override
;
40 friend class PrinterDetectorAppSearchEnabledTest
;
42 void SetNotificationUIManagerForTesting(NotificationUIManager
* manager
);
44 // KeyedService override:
45 void Shutdown() override
;
47 // UsbService::observer override:
48 void OnDeviceAdded(scoped_refptr
<device::UsbDevice
> device
) override
;
50 // Initializes the printer detector.
54 NotificationUIManager
* notification_ui_manager_
;
55 ScopedObserver
<device::UsbService
, device::UsbService::Observer
> observer_
;
56 base::WeakPtrFactory
<PrinterDetector
> weak_ptr_factory_
;
58 DISALLOW_COPY_AND_ASSIGN(PrinterDetector
);
61 } // namespace chromeos
63 #endif // CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_PRINTER_DETECTOR_H_