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; | 13 class Profile; |
14 | 14 |
15 namespace chromeos { | 15 namespace chromeos { |
16 | 16 |
17 // Interface for printer discovery. Constructs Printer objects from USB and | 17 // Interface for printer discovery. Constructs Printer objects from USB and |
18 // zeroconf (DNS-SD) printers. All functions in this class must be called | 18 // zeroconf (DNS-SD) printers. All functions in this class must be called |
19 // from a sequenced context. | 19 // from a sequenced context. |
20 class CHROMEOS_EXPORT PrinterDiscoverer { | 20 class CHROMEOS_EXPORT PrinterDiscoverer { |
21 public: | 21 public: |
22 // Interface for objects interested in detected printers. | 22 // Interface for objects interested in detected printers. |
23 class Observer { | 23 class Observer { |
24 public: | 24 public: |
25 virtual ~Observer() = default; | 25 virtual ~Observer() = default; |
26 | 26 |
27 // Called when we are done with the initial scan for printers. We may | |
28 // still call OnPrintersFound if the set of available printers | |
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; | |
32 | |
33 // Called with a collection of printers as they are discovered. On each | 27 // Called with a collection of printers as they are discovered. On each |
34 // call |printers| is the full set of known printers; it is not | 28 // call |printers| is the full set of known printers; it is not |
35 // incremental; printers may be added or removed. | 29 // incremental; printers may be added or removed. |scan_done| is true after |
30 // the initial scan has been completed. Observers will not receive | |
Carlson
2017/05/26 20:10:20
This comment is a little imprecise, as we may call
skau
2017/05/26 20:23:52
Done.
| |
31 // notifications after scan completion unless a new printer is added to the | |
32 // environment. | |
36 // | 33 // |
37 // Observers will get an OnPrintersFound callback after registration | 34 // Observers will get an OnPrintersFound callback after registration |
38 // with the existing list of printers (which may be empty) and will get | 35 // with the existing list of printers (which may be empty) and will get |
39 // additional calls whenever the set of printers changes. | 36 // additional calls whenever the set of printers changes. |
40 virtual void OnPrintersFound(const std::vector<Printer>& printers) = 0; | 37 virtual void OnPrintersFound(bool scan_done, |
38 const std::vector<Printer>& printers) = 0; | |
41 }; | 39 }; |
42 | 40 |
43 // Static factory | 41 // Static factory |
44 static std::unique_ptr<PrinterDiscoverer> CreateForProfile(Profile* profile); | 42 static std::unique_ptr<PrinterDiscoverer> CreateForProfile(Profile* profile); |
45 | 43 |
46 virtual ~PrinterDiscoverer() = default; | 44 virtual ~PrinterDiscoverer() = default; |
47 | 45 |
48 // Add an observer that will be notified of discovered printers. Ownership of | 46 // Add an observer that will be notified of discovered printers. Ownership of |
49 // |observer| is not taken by the discoverer. It is an error to add an | 47 // |observer| is not taken by the discoverer. It is an error to add an |
50 // observer more than once. Calls to |observer| methods will take place on | 48 // observer more than once. Calls to |observer| methods will take place on |
51 // the thread PrinterDiscoverer was instantiated on. | 49 // the thread PrinterDiscoverer was instantiated on. |
52 virtual void AddObserver(PrinterDiscoverer::Observer* observer) = 0; | 50 virtual void AddObserver(PrinterDiscoverer::Observer* observer) = 0; |
53 | 51 |
54 // Remove an observer of printer discovery. | 52 // Remove an observer of printer discovery. |
55 virtual void RemoveObserver(PrinterDiscoverer::Observer* observer) = 0; | 53 virtual void RemoveObserver(PrinterDiscoverer::Observer* observer) = 0; |
56 }; | 54 }; |
57 | 55 |
58 } // namespace chromeos | 56 } // namespace chromeos |
59 | 57 |
60 #endif // CHROME_BROWSER_CHROMEOS_PRINTING_PRINTER_DISCOVERER_H_ | 58 #endif // CHROME_BROWSER_CHROMEOS_PRINTING_PRINTER_DISCOVERER_H_ |
OLD | NEW |