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_PRINT_SYSTEM_H_ | 5 #ifndef PRINTING_BACKEND_PRINT_BACKEND_H_ |
6 #define CHROME_SERVICE_CLOUD_PRINT_PRINT_SYSTEM_H_ | 6 #define PRINTING_BACKEND_PRINT_BACKEND_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
14 | 14 |
15 class DictionaryValue; | 15 class DictionaryValue; |
16 class FilePath; | |
17 | 16 |
18 // This is the interface for platform-specific code for cloud print | 17 // This is the interface for platform-specific code for a print backend |
19 namespace cloud_print { | 18 namespace printing { |
20 | |
21 typedef int PlatformJobId; | |
22 | 19 |
23 struct PrinterBasicInfo { | 20 struct PrinterBasicInfo { |
| 21 PrinterBasicInfo(); |
| 22 ~PrinterBasicInfo(); |
| 23 |
24 std::string printer_name; | 24 std::string printer_name; |
25 std::string printer_description; | 25 std::string printer_description; |
26 int printer_status; | 26 int printer_status; |
27 std::map<std::string, std::string> options; | 27 std::map<std::string, std::string> options; |
28 PrinterBasicInfo() : printer_status(0) { | |
29 } | |
30 }; | 28 }; |
31 | 29 |
32 typedef std::vector<PrinterBasicInfo> PrinterList; | 30 typedef std::vector<PrinterBasicInfo> PrinterList; |
33 | 31 |
34 struct PrinterCapsAndDefaults { | 32 struct PrinterCapsAndDefaults { |
35 std::string printer_capabilities; | 33 std::string printer_capabilities; |
36 std::string caps_mime_type; | 34 std::string caps_mime_type; |
37 std::string printer_defaults; | 35 std::string printer_defaults; |
38 std::string defaults_mime_type; | 36 std::string defaults_mime_type; |
39 }; | 37 }; |
40 | 38 |
41 enum PrintJobStatus { | 39 // PrintBackend class will provide interface for different print backends |
42 PRINT_JOB_STATUS_INVALID, | |
43 PRINT_JOB_STATUS_IN_PROGRESS, | |
44 PRINT_JOB_STATUS_ERROR, | |
45 PRINT_JOB_STATUS_COMPLETED | |
46 }; | |
47 | |
48 struct PrintJobDetails { | |
49 PrintJobStatus status; | |
50 int platform_status_flags; | |
51 std::string status_message; | |
52 int total_pages; | |
53 int pages_printed; | |
54 PrintJobDetails() : status(PRINT_JOB_STATUS_INVALID), | |
55 platform_status_flags(0), total_pages(0), | |
56 pages_printed(0) { | |
57 } | |
58 void Clear() { | |
59 status = PRINT_JOB_STATUS_INVALID; | |
60 platform_status_flags = 0; | |
61 status_message.clear(); | |
62 total_pages = 0; | |
63 pages_printed = 0; | |
64 } | |
65 bool operator ==(const PrintJobDetails& other) const { | |
66 return (status == other.status) && | |
67 (platform_status_flags == other.platform_status_flags) && | |
68 (status_message == other.status_message) && | |
69 (total_pages == other.total_pages) && | |
70 (pages_printed == other.pages_printed); | |
71 } | |
72 bool operator !=(const PrintJobDetails& other) const { | |
73 return !(*this == other); | |
74 } | |
75 }; | |
76 | |
77 // PrintSystem class will provide interface for different printing systems | |
78 // (Windows, CUPS) to implement. User will call CreateInstance() to | 40 // (Windows, CUPS) to implement. User will call CreateInstance() to |
79 // obtain available printing system. | 41 // obtain available print backend. |
80 // Please note, that PrintSystem is not platform specific, but rather | 42 // Please note, that PrintBackend is not platform specific, but rather |
81 // print system specific. For example, CUPS is available on both Linux and Mac, | 43 // print system specific. For example, CUPS is available on both Linux and Mac, |
82 // but not avaialble on ChromeOS, etc. This design allows us to add more | 44 // but not available on ChromeOS, etc. This design allows us to add more |
83 // functionality on some platforms, while reusing core (CUPS) functions. | 45 // functionality on some platforms, while reusing core (CUPS) functions. |
84 class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> { | 46 class PrintBackend : public base::RefCountedThreadSafe<PrintBackend> { |
85 public: | 47 public: |
86 class PrintServerWatcher | 48 virtual ~PrintBackend(); |
87 : public base::RefCountedThreadSafe<PrintServerWatcher> { | |
88 public: | |
89 // Callback interface for new printer notifications. | |
90 class Delegate { | |
91 public: | |
92 virtual void OnPrinterAdded() = 0; | |
93 // TODO(gene): Do we need OnPrinterDeleted notification here? | |
94 | |
95 protected: | |
96 virtual ~Delegate() {} | |
97 }; | |
98 | |
99 virtual ~PrintServerWatcher() {} | |
100 virtual bool StartWatching(PrintServerWatcher::Delegate* delegate) = 0; | |
101 virtual bool StopWatching() = 0; | |
102 }; | |
103 | |
104 class PrinterWatcher : public base::RefCountedThreadSafe<PrinterWatcher> { | |
105 public: | |
106 // Callback interface for printer updates notifications. | |
107 class Delegate { | |
108 public: | |
109 virtual void OnPrinterDeleted() = 0; | |
110 virtual void OnPrinterChanged() = 0; | |
111 virtual void OnJobChanged() = 0; | |
112 | |
113 protected: | |
114 virtual ~Delegate() {} | |
115 }; | |
116 | |
117 virtual ~PrinterWatcher() {} | |
118 virtual bool StartWatching(PrinterWatcher::Delegate* delegate) = 0; | |
119 virtual bool StopWatching() = 0; | |
120 virtual bool GetCurrentPrinterInfo(PrinterBasicInfo* printer_info) = 0; | |
121 }; | |
122 | |
123 class JobSpooler : public base::RefCountedThreadSafe<JobSpooler> { | |
124 public: | |
125 // Callback interface for JobSpooler notifications. | |
126 class Delegate { | |
127 public: | |
128 virtual ~Delegate() { } | |
129 virtual void OnJobSpoolSucceeded(const PlatformJobId& job_id) = 0; | |
130 virtual void OnJobSpoolFailed() = 0; | |
131 }; | |
132 | |
133 virtual ~JobSpooler() {} | |
134 // Spool job to the printer asynchronously. Caller will be notified via | |
135 // |delegate|. Note that only one print job can be in progress at any given | |
136 // time. Subsequent calls to Spool (before the Delegate::OnJobSpoolSucceeded | |
137 // or Delegate::OnJobSpoolFailed methods are called) can fail. | |
138 virtual bool Spool(const std::string& print_ticket, | |
139 const FilePath& print_data_file_path, | |
140 const std::string& print_data_mime_type, | |
141 const std::string& printer_name, | |
142 const std::string& job_title, | |
143 JobSpooler::Delegate* delegate) = 0; | |
144 }; | |
145 | |
146 virtual ~PrintSystem() {} | |
147 | 49 |
148 // Enumerates the list of installed local and network printers. | 50 // Enumerates the list of installed local and network printers. |
149 virtual void EnumeratePrinters(PrinterList* printer_list) = 0; | 51 virtual void EnumeratePrinters(PrinterList* printer_list) = 0; |
150 | 52 |
151 // Gets the capabilities and defaults for a specific printer. | 53 // Gets the capabilities and defaults for a specific printer. |
152 virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name, | 54 virtual bool GetPrinterCapsAndDefaults( |
153 PrinterCapsAndDefaults* printer_info) = 0; | 55 const std::string& printer_name, |
154 | 56 PrinterCapsAndDefaults* printer_info) = 0; |
155 // Returns true if ticket is valid. | |
156 virtual bool ValidatePrintTicket(const std::string& printer_name, | |
157 const std::string& print_ticket_data) = 0; | |
158 | |
159 // Get details for already spooled job. | |
160 virtual bool GetJobDetails(const std::string& printer_name, | |
161 PlatformJobId job_id, | |
162 PrintJobDetails *job_details) = 0; | |
163 | 57 |
164 // Returns true if printer_name points to a valid printer. | 58 // Returns true if printer_name points to a valid printer. |
165 virtual bool IsValidPrinter(const std::string& printer_name) = 0; | 59 virtual bool IsValidPrinter(const std::string& printer_name) = 0; |
166 | 60 |
167 // Factory methods to create corresponding watcher. Callee is responsible | 61 // Allocate a print backend. If |print_backend_settings| is NULL, default |
168 // for deleting objects. Return NULL if failed. | 62 // settings will be used. |
169 virtual PrintServerWatcher* CreatePrintServerWatcher() = 0; | 63 // Return NULL if no print backend available. |
170 virtual PrinterWatcher* CreatePrinterWatcher( | 64 static scoped_refptr<PrintBackend> CreateInstance( |
171 const std::string& printer_name) = 0; | 65 const DictionaryValue* print_backend_settings); |
172 virtual JobSpooler* CreateJobSpooler() = 0; | |
173 | |
174 // Generate unique for proxy. | |
175 static std::string GenerateProxyId(); | |
176 | |
177 // Call this function to obtain printing system for specified print server. | |
178 // If print settings are NULL, default settings will be used. | |
179 // Return NULL if no print system available. | |
180 static scoped_refptr<PrintSystem> CreateInstance( | |
181 const DictionaryValue* print_system_settings); | |
182 }; | 66 }; |
183 | 67 |
| 68 } // namespace printing |
184 | 69 |
185 // This typedef is to workaround the issue with certain versions of | 70 #endif // PRINTING_BACKEND_PRINT_BACKEND_H_ |
186 // Visual Studio where it gets confused between multiple Delegate | |
187 // classes and gives a C2500 error. (I saw this error on the try bots - | |
188 // the workaround was not needed for my machine). | |
189 typedef PrintSystem::PrintServerWatcher::Delegate PrintServerWatcherDelegate; | |
190 typedef PrintSystem::PrinterWatcher::Delegate PrinterWatcherDelegate; | |
191 typedef PrintSystem::JobSpooler::Delegate JobSpoolerDelegate; | |
192 | |
193 } // namespace cloud_print | |
194 | |
195 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINT_SYSTEM_H_ | |
OLD | NEW |