Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / service / cloud_print / print_system.h
blob6e06bae11db71944f96441ac1cda806032c5ed0b
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_SERVICE_CLOUD_PRINT_PRINT_SYSTEM_H_
6 #define CHROME_SERVICE_CLOUD_PRINT_PRINT_SYSTEM_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "printing/backend/print_backend.h"
16 namespace base {
17 class DictionaryValue;
18 class FilePath;
21 namespace printing {
22 struct PrinterBasicInfo;
23 struct PrinterCapsAndDefaults;
26 // This is the interface for platform-specific code for cloud print
27 namespace cloud_print {
29 typedef int PlatformJobId;
31 enum PrintJobStatus {
32 PRINT_JOB_STATUS_INVALID,
33 PRINT_JOB_STATUS_IN_PROGRESS,
34 PRINT_JOB_STATUS_ERROR,
35 PRINT_JOB_STATUS_COMPLETED,
36 PRINT_JOB_STATUS_MAX,
39 struct PrintJobDetails {
40 PrintJobDetails();
42 void Clear();
44 bool operator ==(const PrintJobDetails& other) const {
45 return (status == other.status) &&
46 (platform_status_flags == other.platform_status_flags) &&
47 (status_message == other.status_message) &&
48 (total_pages == other.total_pages) &&
49 (pages_printed == other.pages_printed);
52 bool operator !=(const PrintJobDetails& other) const {
53 return !(*this == other);
56 PrintJobStatus status;
57 int platform_status_flags;
58 std::string status_message;
59 int total_pages;
60 int pages_printed;
63 // PrintSystem class will provide interface for different printing systems
64 // (Windows, CUPS) to implement. User will call CreateInstance() to
65 // obtain available printing system.
66 // Please note, that PrintSystem is not platform specific, but rather
67 // print system specific. For example, CUPS is available on both Linux and Mac,
68 // but not available on ChromeOS, etc. This design allows us to add more
69 // functionality on some platforms, while reusing core (CUPS) functions.
70 class PrintSystem : public base::RefCountedThreadSafe<PrintSystem> {
71 public:
72 class PrintServerWatcher
73 : public base::RefCountedThreadSafe<PrintServerWatcher> {
74 public:
75 // Callback interface for new printer notifications.
76 class Delegate {
77 public:
78 virtual void OnPrinterAdded() = 0;
79 // TODO(gene): Do we need OnPrinterDeleted notification here?
81 protected:
82 virtual ~Delegate() {}
85 virtual bool StartWatching(PrintServerWatcher::Delegate* delegate) = 0;
86 virtual bool StopWatching() = 0;
88 protected:
89 friend class base::RefCountedThreadSafe<PrintServerWatcher>;
90 virtual ~PrintServerWatcher();
93 class PrinterWatcher : public base::RefCountedThreadSafe<PrinterWatcher> {
94 public:
95 // Callback interface for printer updates notifications.
96 class Delegate {
97 public:
98 virtual void OnPrinterDeleted() = 0;
99 virtual void OnPrinterChanged() = 0;
100 virtual void OnJobChanged() = 0;
102 protected:
103 virtual ~Delegate() {}
106 virtual bool StartWatching(PrinterWatcher::Delegate* delegate) = 0;
107 virtual bool StopWatching() = 0;
108 virtual bool GetCurrentPrinterInfo(
109 printing::PrinterBasicInfo* printer_info) = 0;
111 protected:
112 friend class base::RefCountedThreadSafe<PrinterWatcher>;
113 virtual ~PrinterWatcher();
116 class JobSpooler : public base::RefCountedThreadSafe<JobSpooler> {
117 public:
118 // Callback interface for JobSpooler notifications.
119 class Delegate {
120 public:
121 virtual void OnJobSpoolSucceeded(const PlatformJobId& job_id) = 0;
122 virtual void OnJobSpoolFailed() = 0;
124 protected:
125 virtual ~Delegate() {}
128 // Spool job to the printer asynchronously. Caller will be notified via
129 // |delegate|. Note that only one print job can be in progress at any given
130 // time. Subsequent calls to Spool (before the Delegate::OnJobSpoolSucceeded
131 // or Delegate::OnJobSpoolFailed methods are called) can fail.
132 virtual bool Spool(const std::string& print_ticket,
133 const std::string& print_ticket_mime_type,
134 const base::FilePath& print_data_file_path,
135 const std::string& print_data_mime_type,
136 const std::string& printer_name,
137 const std::string& job_title,
138 const std::vector<std::string>& tags,
139 JobSpooler::Delegate* delegate) = 0;
140 protected:
141 friend class base::RefCountedThreadSafe<JobSpooler>;
142 virtual ~JobSpooler();
145 class PrintSystemResult {
146 public:
147 PrintSystemResult(bool succeeded, const std::string& message)
148 : succeeded_(succeeded), message_(message) { }
149 bool succeeded() const { return succeeded_; }
150 std::string message() const { return message_; }
152 private:
153 PrintSystemResult() {}
155 bool succeeded_;
156 std::string message_;
159 typedef base::Callback<void(bool,
160 const std::string&,
161 const printing::PrinterCapsAndDefaults&)>
162 PrinterCapsAndDefaultsCallback;
164 // Initialize print system. This need to be called before any other function
165 // of PrintSystem.
166 virtual PrintSystemResult Init() = 0;
168 // Enumerates the list of installed local and network printers.
169 virtual PrintSystemResult EnumeratePrinters(
170 printing::PrinterList* printer_list) = 0;
172 // Gets the capabilities and defaults for a specific printer asynchronously.
173 virtual void GetPrinterCapsAndDefaults(
174 const std::string& printer_name,
175 const PrinterCapsAndDefaultsCallback& callback) = 0;
177 // Returns true if printer_name points to a valid printer.
178 virtual bool IsValidPrinter(const std::string& printer_name) = 0;
180 // Returns true if ticket is valid.
181 virtual bool ValidatePrintTicket(
182 const std::string& printer_name,
183 const std::string& print_ticket_data,
184 const std::string& print_ticket_mime_type) = 0;
186 // Get details for already spooled job.
187 virtual bool GetJobDetails(const std::string& printer_name,
188 PlatformJobId job_id,
189 PrintJobDetails* job_details) = 0;
191 // Factory methods to create corresponding watcher. Callee is responsible
192 // for deleting objects. Return NULL if failed.
193 virtual PrintServerWatcher* CreatePrintServerWatcher() = 0;
194 virtual PrinterWatcher* CreatePrinterWatcher(
195 const std::string& printer_name) = 0;
196 virtual JobSpooler* CreateJobSpooler() = 0;
198 // Returns a true if connector should use CDD for capabilities and CJT as
199 // print ticket.
200 virtual bool UseCddAndCjt() = 0;
202 // Returns a comma separated list of mimetypes for print data that are
203 // supported by this print system. The format of this string is the same as
204 // that used for the HTTP Accept: header.
205 virtual std::string GetSupportedMimeTypes() = 0;
207 // Generate unique for proxy.
208 static std::string GenerateProxyId();
210 // Call this function to obtain printing system for specified print server.
211 // If print settings are NULL, default settings will be used.
212 // Return NULL if no print system available.
213 static scoped_refptr<PrintSystem> CreateInstance(
214 const base::DictionaryValue* print_system_settings);
216 protected:
217 friend class base::RefCountedThreadSafe<PrintSystem>;
218 virtual ~PrintSystem();
221 } // namespace cloud_print
223 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINT_SYSTEM_H_