Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CHROME_BROWSER_CHROMEOS_PRINTING_PRINTER_DISCOVERER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_PRINTING_PRINTER_DISCOVERER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_PRINTING_PRINTER_DISCOVERER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_PRINTING_PRINTER_DISCOVERER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "chromeos/printing/printer_configuration.h" | 11 #include "chromeos/printing/printer_configuration.h" |
| 12 | 12 |
| 13 class Profile; | |
| 14 | |
| 13 namespace chromeos { | 15 namespace chromeos { |
| 14 | 16 |
| 15 // Interface for printer discovery. Constructs Printer objects from USB and | 17 // Interface for printer discovery. Constructs Printer objects from USB and |
| 16 // zeroconf (DNS-SD) printers. | 18 // zeroconf (DNS-SD) printers. All functions in this class must be called |
| 19 // from a sequenced context. | |
| 17 class CHROMEOS_EXPORT PrinterDiscoverer { | 20 class CHROMEOS_EXPORT PrinterDiscoverer { |
| 18 public: | 21 public: |
| 19 // Interface for objects interested in detected printers. | 22 // Interface for objects interested in detected printers. |
| 20 class Observer { | 23 class Observer { |
| 21 public: | 24 public: |
| 22 // Called after discovery has started. | 25 virtual ~Observer() = default; |
| 23 virtual void OnDiscoveryStarted() {} | |
| 24 | 26 |
| 25 // Called when discovery is stopping. OnPrintersFound will not be | 27 // Called when we are done with the initial scan for printers. We may |
| 26 // called after this occurs. | 28 // still call OnPrintersFound if the set of available printers |
| 27 virtual void OnDiscoveryStopping() {} | 29 // changes, but the user can conclude that if a printer is currently |
| 30 // available and not in the list, we're not still looking for it. | |
| 31 virtual void OnDiscoveryInitialScanDone() = 0; | |
| 28 | 32 |
| 29 // Called after all printers have been discovered and the observers | 33 // Called with a collection of printers as they are discovered. On each |
| 30 // notified. | 34 // call |printers| is the full set of known printers; it is not |
| 31 virtual void OnDiscoveryDone() {} | 35 // incremental; printers may be added or removed. |
| 32 | 36 // |
| 33 // Called with a collection of printers as they are discovered. Printer | 37 // Observers will get an OnPrintersFound callback after registration |
| 34 // objects must be copied if they are retained outside of the scope of this | 38 // with the existing list of printers (which may be empty) and will get |
| 35 // function. | 39 // additional calls whenever the set of printers changes. |
| 36 virtual void OnPrintersFound(const std::vector<Printer>& printers) {} | 40 virtual void OnPrintersFound(const std::vector<Printer>& printers) = 0; |
| 37 }; | 41 }; |
| 38 | 42 |
| 39 // Static factory | 43 // Static factory |
| 40 static std::unique_ptr<PrinterDiscoverer> Create(); | 44 static std::unique_ptr<PrinterDiscoverer> Create(Profile* profile); |
|
stevenjb
2017/04/10 19:49:55
Maybe rename this CreateForProfile for clarity?
Carlson
2017/04/10 22:16:42
Done.
| |
| 41 | 45 |
| 42 virtual ~PrinterDiscoverer() {} | 46 virtual ~PrinterDiscoverer() = default; |
| 43 | |
| 44 // Begin scanning for printers. Found printers will be reported to the | |
| 45 // attached observer. | |
| 46 virtual bool StartDiscovery() = 0; | |
| 47 | |
| 48 // Stop scanning for printers. Returns false if scanning could not be stopped | |
| 49 // and new results will continue to be be sent to observers. Returns true if | |
| 50 // scanning was stopped successfully. No calls to the attached observer will | |
| 51 // be made after this returns if it returned true. | |
| 52 virtual bool StopDiscovery() = 0; | |
| 53 | 47 |
| 54 // Add an observer that will be notified of discovered printers. Ownership of | 48 // Add an observer that will be notified of discovered printers. Ownership of |
| 55 // |observer| is not taken by the discoverer. It is an error to add an | 49 // |observer| is not taken by the discoverer. It is an error to add an |
| 56 // oberserver more than once. | 50 // oberserver more than once. Callbacks to the observer will take place |
|
stevenjb
2017/04/10 19:49:55
nit: 'Calls to |observer| methods'
Carlson
2017/04/10 22:16:42
Done.
| |
| 51 // on the thread PrinterDiscoverer was instantiated on. | |
| 57 virtual void AddObserver(PrinterDiscoverer::Observer* observer) = 0; | 52 virtual void AddObserver(PrinterDiscoverer::Observer* observer) = 0; |
| 58 | 53 |
| 59 // Remove an observer of printer discovery. | 54 // Remove an observer of printer discovery. |
| 60 virtual void RemoveObserver(PrinterDiscoverer::Observer* observer) = 0; | 55 virtual void RemoveObserver(PrinterDiscoverer::Observer* observer) = 0; |
| 61 }; | 56 }; |
| 62 | 57 |
| 63 } // namespace chromeos | 58 } // namespace chromeos |
| 64 | 59 |
| 65 #endif // CHROME_BROWSER_CHROMEOS_PRINTING_PRINTER_DISCOVERER_H_ | 60 #endif // CHROME_BROWSER_CHROMEOS_PRINTING_PRINTER_DISCOVERER_H_ |
| OLD | NEW |