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_PRINTERS_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_PRINTING_PRINTERS_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_PRINTING_PRINTERS_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_PRINTING_PRINTERS_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // Returns the printers that are saved in preferences. | 48 // Returns the printers that are saved in preferences. |
49 std::vector<std::unique_ptr<Printer>> GetPrinters() const; | 49 std::vector<std::unique_ptr<Printer>> GetPrinters() const; |
50 | 50 |
51 // Returns printers from enterprise policy. | 51 // Returns printers from enterprise policy. |
52 std::vector<std::unique_ptr<Printer>> GetRecommendedPrinters() const; | 52 std::vector<std::unique_ptr<Printer>> GetRecommendedPrinters() const; |
53 | 53 |
54 // Returns the printer with id |printer_id|, or nullptr if no such | 54 // Returns the printer with id |printer_id|, or nullptr if no such |
55 // printer exists. | 55 // printer exists. |
56 std::unique_ptr<Printer> GetPrinter(const std::string& printer_id) const; | 56 std::unique_ptr<Printer> GetPrinter(const std::string& printer_id) const; |
57 | 57 |
58 // Adds or updates a printer. Printers are identified by the id field. Use an | 58 // Adds or updates a printer in profile preferences. The |printer| is |
59 // empty id to add a new printer. | 59 // identified by its id field. Those with an empty id are treated as new |
| 60 // printers. |
60 void RegisterPrinter(std::unique_ptr<Printer> printer); | 61 void RegisterPrinter(std::unique_ptr<Printer> printer); |
61 | 62 |
62 // Remove printer from preferences with the id |printer_id|. Returns true if | 63 // Remove printer from preferences with the id |printer_id|. Returns true if |
63 // the printer was successfully removed. | 64 // the printer was successfully removed. |
64 bool RemovePrinter(const std::string& printer_id); | 65 bool RemovePrinter(const std::string& printer_id); |
65 | 66 |
66 // Attach |observer| for notification of events. |observer| is expected to | 67 // Attach |observer| for notification of events. |observer| is expected to |
67 // live on the same thread (UI) as this object. OnPrinter* methods are | 68 // live on the same thread (UI) as this object. OnPrinter* methods are |
68 // invoked inline so calling RegisterPrinter in response to OnPrinterAdded is | 69 // invoked inline so calling RegisterPrinter in response to OnPrinterAdded is |
69 // forbidden. | 70 // forbidden. |
70 void AddObserver(PrintersManager::Observer* observer); | 71 void AddObserver(PrintersManager::Observer* observer); |
71 | 72 |
72 // Remove |observer| so that it no longer receives notifications. After the | 73 // Remove |observer| so that it no longer receives notifications. After the |
73 // completion of this method, the |observer| can be safely destroyed. | 74 // completion of this method, the |observer| can be safely destroyed. |
74 void RemoveObserver(PrintersManager::Observer* observer); | 75 void RemoveObserver(PrintersManager::Observer* observer); |
75 | 76 |
76 // Returns a ModelTypeSyncBridge for the sync client. | 77 // Returns a ModelTypeSyncBridge for the sync client. |
77 PrintersSyncBridge* GetSyncBridge(); | 78 PrintersSyncBridge* GetSyncBridge(); |
78 | 79 |
| 80 // Registers that the printer was installed in CUPS. This is independent of |
| 81 // whether a printer is saved in profile preferences. |
| 82 void PrinterInstalled(const Printer& printer); |
| 83 |
| 84 // Returns true if |printer| is currently installed in CUPS. |
| 85 bool IsConfigurationCurrent(const Printer& printer) const; |
| 86 |
79 private: | 87 private: |
80 // Updates the in-memory recommended printer list. | 88 // Updates the in-memory recommended printer list. |
81 void UpdateRecommendedPrinters(); | 89 void UpdateRecommendedPrinters(); |
82 | 90 |
83 Profile* profile_; | 91 Profile* profile_; |
84 PrefChangeRegistrar pref_change_registrar_; | 92 PrefChangeRegistrar pref_change_registrar_; |
85 | 93 |
86 // The backend for profile printers. | 94 // The backend for profile printers. |
87 std::unique_ptr<PrintersSyncBridge> sync_bridge_; | 95 std::unique_ptr<PrintersSyncBridge> sync_bridge_; |
88 | 96 |
89 // Contains the keys for all recommended printers in order so we can return | 97 // Contains the keys for all recommended printers in order so we can return |
90 // the list of recommended printers in the order they were received. | 98 // the list of recommended printers in the order they were received. |
91 std::vector<std::string> recommended_printer_ids_; | 99 std::vector<std::string> recommended_printer_ids_; |
92 std::map<std::string, std::unique_ptr<base::DictionaryValue>> | 100 std::map<std::string, std::unique_ptr<Printer>> recommended_printers_; |
93 recommended_printers_; | 101 |
| 102 // Map of printer ids to installation timestamps. |
| 103 std::map<std::string, base::Time> installed_printer_timestamps_; |
94 | 104 |
95 base::ObserverList<Observer> observers_; | 105 base::ObserverList<Observer> observers_; |
96 | 106 |
97 DISALLOW_COPY_AND_ASSIGN(PrintersManager); | 107 DISALLOW_COPY_AND_ASSIGN(PrintersManager); |
98 }; | 108 }; |
99 | 109 |
100 } // namespace chromeos | 110 } // namespace chromeos |
101 | 111 |
102 #endif // CHROME_BROWSER_CHROMEOS_PRINTING_PRINTERS_MANAGER_H_ | 112 #endif // CHROME_BROWSER_CHROMEOS_PRINTING_PRINTERS_MANAGER_H_ |
OLD | NEW |