OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_SERVICE_CLOUD_PRINT_PRINTER_INFO_H_ | 5 #ifndef CHROME_SERVICE_CLOUD_PRINT_PRINT_SYSTEM_H_ |
6 #define CHROME_SERVICE_CLOUD_PRINT_PRINTER_INFO_H_ | 6 #define CHROME_SERVICE_CLOUD_PRINT_PRINT_SYSTEM_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/ref_counted.h" |
13 | 14 |
14 // This is the interface for platform-specific code for cloud print | 15 // This is the interface for platform-specific code for cloud print |
15 namespace cloud_print { | 16 namespace cloud_print { |
16 | 17 |
17 typedef int PlatformJobId; | 18 typedef int PlatformJobId; |
18 | 19 |
19 struct PrinterBasicInfo { | 20 struct PrinterBasicInfo { |
20 std::string printer_name; | 21 std::string printer_name; |
21 std::string printer_description; | 22 std::string printer_description; |
22 int printer_status; | 23 int printer_status; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 (platform_status_flags == other.platform_status_flags) && | 64 (platform_status_flags == other.platform_status_flags) && |
64 (status_message == other.status_message) && | 65 (status_message == other.status_message) && |
65 (total_pages == other.total_pages) && | 66 (total_pages == other.total_pages) && |
66 (pages_printed == other.pages_printed); | 67 (pages_printed == other.pages_printed); |
67 } | 68 } |
68 bool operator !=(const PrintJobDetails& other) const { | 69 bool operator !=(const PrintJobDetails& other) const { |
69 return !(*this == other); | 70 return !(*this == other); |
70 } | 71 } |
71 }; | 72 }; |
72 | 73 |
73 // Enumerates the list of installed local and network printers. | 74 // PrintSystem class will provide interface for different printing systems |
74 void EnumeratePrinters(PrinterList* printer_list); | 75 // (Windows, CUPS) to implement. User will call CreateInstance() to |
75 // Gets the capabilities and defaults for a specific printer. | 76 // obtain available printing system. |
76 bool GetPrinterCapsAndDefaults(const std::string& printer_name, | 77 // Please note, that PrintSystem is not platform specific, but rather |
77 PrinterCapsAndDefaults* printer_info); | 78 // print system specific. For example, CUPS is available on both Linux and Mac, |
78 bool ValidatePrintTicket(const std::string& printer_name, | 79 // but not avaialble on ChromeOS, etc. This design allows us to add more |
79 const std::string& print_ticket_data); | 80 // functionality on some platforms, while reusing core (CUPS) functions. |
80 std::string GenerateProxyId(); | 81 class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { |
81 bool SpoolPrintJob(const std::string& print_ticket, | 82 public: |
82 const FilePath& print_data_file_path, | 83 virtual ~PrintSystem() {} |
83 const std::string& print_data_mime_type, | |
84 const std::string& printer_name, | |
85 const std::string& job_title, | |
86 PlatformJobId* job_id_ret); | |
87 | 84 |
88 bool GetJobDetails(const std::string& printer_name, | 85 // Enumerates the list of installed local and network printers. |
89 PlatformJobId job_id, | 86 virtual void EnumeratePrinters(PrinterList* printer_list) = 0; |
90 PrintJobDetails *job_details); | |
91 bool IsValidPrinter(const std::string& printer_name); | |
92 | 87 |
93 // A class that watches changes to a printer or a print server. | 88 // Gets the capabilities and defaults for a specific printer. |
94 // The set of notifications are very coarse-grained (even though the Windows | 89 virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name, |
95 // API allows for listening to fine-grained details about a printer, this class | 90 PrinterCapsAndDefaults* printer_info) = 0; |
96 // does not support that level of fine-grained control. | 91 |
97 class PrinterChangeNotifier { | 92 // Returns true if ticket is valid. |
98 public: | 93 virtual bool ValidatePrintTicket(const std::string& printer_name, |
99 class Delegate { | 94 const std::string& print_ticket_data) = 0; |
100 public: | 95 |
101 virtual void OnPrinterAdded() = 0; | 96 // Send job to the printer. |
102 virtual void OnPrinterDeleted() = 0; | 97 virtual bool SpoolPrintJob(const std::string& print_ticket, |
103 virtual void OnPrinterChanged() = 0; | 98 const FilePath& print_data_file_path, |
104 virtual void OnJobChanged() = 0; | 99 const std::string& print_data_mime_type, |
| 100 const std::string& printer_name, |
| 101 const std::string& job_title, |
| 102 PlatformJobId* job_id_ret) = 0; |
| 103 |
| 104 // Get details for already spooled job. |
| 105 virtual bool GetJobDetails(const std::string& printer_name, |
| 106 PlatformJobId job_id, |
| 107 PrintJobDetails *job_details) = 0; |
| 108 |
| 109 // Returns true if printer_name points to a valid printer. |
| 110 virtual bool IsValidPrinter(const std::string& printer_name) = 0; |
| 111 |
| 112 class PrintServerWatcher |
| 113 : public base::RefCountedThreadSafe<PrintServerWatcher> { |
| 114 public: |
| 115 // Callback interface for new printer notifications. |
| 116 class Delegate { |
| 117 public: |
| 118 virtual void OnPrinterAdded() = 0; |
| 119 // TODO(gene): Do we need OnPrinterDeleted notification here? |
| 120 }; |
| 121 |
| 122 virtual ~PrintServerWatcher() {} |
| 123 virtual bool StartWatching(PrintServerWatcher::Delegate* delegate) = 0; |
| 124 virtual bool StopWatching() = 0; |
105 }; | 125 }; |
106 PrinterChangeNotifier(); | 126 |
107 ~PrinterChangeNotifier(); | 127 class PrinterWatcher : public base::RefCountedThreadSafe<PrinterWatcher> { |
108 bool StartWatching(const std::string& printer_name, Delegate* delegate); | 128 public: |
109 bool StopWatching(); | 129 // Callback interface for printer updates notifications. |
110 bool GetCurrentPrinterInfo(PrinterBasicInfo* printer_info); | 130 class Delegate { |
111 private: | 131 public: |
112 // Internal state maintained by the PrinterChangeNotifier class. | 132 virtual void OnPrinterDeleted() = 0; |
113 class NotificationState; | 133 virtual void OnPrinterChanged() = 0; |
114 NotificationState* state_; | 134 virtual void OnJobChanged() = 0; |
115 DISALLOW_COPY_AND_ASSIGN(PrinterChangeNotifier); | 135 }; |
| 136 |
| 137 virtual ~PrinterWatcher() {} |
| 138 virtual bool StartWatching(PrinterWatcher::Delegate* delegate) = 0; |
| 139 virtual bool StopWatching() = 0; |
| 140 virtual bool GetCurrentPrinterInfo(PrinterBasicInfo* printer_info) = 0; |
| 141 }; |
| 142 |
| 143 // Factory methods to create corresponding watcher. Callee is responsible |
| 144 // for deleting objects. Return NULL if failed. |
| 145 virtual PrintServerWatcher* CreatePrintServerWatcher() = 0; |
| 146 virtual PrinterWatcher* CreatePrinterWatcher( |
| 147 const std::string& printer_name) = 0; |
| 148 |
| 149 // Generate unique for proxy. |
| 150 static std::string GenerateProxyId(); |
| 151 |
| 152 // Call this function to obtain current printing system. Return NULL if no |
| 153 // print system available. Delete returned PrintSystem pointer using delete. |
| 154 static scoped_refptr<PrintSystem> CreateInstance(); |
116 }; | 155 }; |
117 | 156 |
| 157 |
118 // This typedef is to workaround the issue with certain versions of | 158 // This typedef is to workaround the issue with certain versions of |
119 // Visual Studio where it gets confused between multiple Delegate | 159 // Visual Studio where it gets confused between multiple Delegate |
120 // classes and gives a C2500 error. (I saw this error on the try bots - | 160 // classes and gives a C2500 error. (I saw this error on the try bots - |
121 // the workaround was not needed for my machine). | 161 // the workaround was not needed for my machine). |
122 typedef PrinterChangeNotifier::Delegate PrinterChangeNotifierDelegate; | 162 typedef PrintSystem::PrintServerWatcher::Delegate PrintServerWatcherDelegate; |
| 163 typedef PrintSystem::PrinterWatcher::Delegate PrinterWatcherDelegate; |
123 | 164 |
124 } // namespace cloud_print | 165 } // namespace cloud_print |
125 | 166 |
126 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_INFO_H_ | 167 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINT_SYSTEM_H_ |
127 | 168 |
OLD | NEW |