Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / service / cloud_print / print_system.h
blobc08a1074b7047f1b9a4582c51a7b6fa150310bf5
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 base::FilePath& print_data_file_path,
134 const std::string& print_data_mime_type,
135 const std::string& printer_name,
136 const std::string& job_title,
137 const std::vector<std::string>& tags,
138 JobSpooler::Delegate* delegate) = 0;
139 protected:
140 friend class base::RefCountedThreadSafe<JobSpooler>;
141 virtual ~JobSpooler();
144 class PrintSystemResult {
145 public:
146 PrintSystemResult(bool succeeded, const std::string& message)
147 : succeeded_(succeeded), message_(message) { }
148 bool succeeded() const { return succeeded_; }
149 std::string message() const { return message_; }
151 private:
152 PrintSystemResult() {}
154 bool succeeded_;
155 std::string message_;
158 typedef base::Callback<void(bool,
159 const std::string&,
160 const printing::PrinterCapsAndDefaults&)>
161 PrinterCapsAndDefaultsCallback;
163 // Initialize print system. This need to be called before any other function
164 // of PrintSystem.
165 virtual PrintSystemResult Init() = 0;
167 // Enumerates the list of installed local and network printers.
168 virtual PrintSystemResult EnumeratePrinters(
169 printing::PrinterList* printer_list) = 0;
171 // Gets the capabilities and defaults for a specific printer asynchronously.
172 virtual void GetPrinterCapsAndDefaults(
173 const std::string& printer_name,
174 const PrinterCapsAndDefaultsCallback& callback) = 0;
176 // Returns true if printer_name points to a valid printer.
177 virtual bool IsValidPrinter(const std::string& printer_name) = 0;
179 // Returns true if ticket is valid.
180 virtual bool ValidatePrintTicket(const std::string& printer_name,
181 const std::string& print_ticket_data) = 0;
183 // Get details for already spooled job.
184 virtual bool GetJobDetails(const std::string& printer_name,
185 PlatformJobId job_id,
186 PrintJobDetails* job_details) = 0;
188 // Factory methods to create corresponding watcher. Callee is responsible
189 // for deleting objects. Return NULL if failed.
190 virtual PrintServerWatcher* CreatePrintServerWatcher() = 0;
191 virtual PrinterWatcher* CreatePrinterWatcher(
192 const std::string& printer_name) = 0;
193 virtual JobSpooler* CreateJobSpooler() = 0;
195 // Returns a comma separated list of mimetypes for print data that are
196 // supported by this print system. The format of this string is the same as
197 // that used for the HTTP Accept: header.
198 virtual std::string GetSupportedMimeTypes() = 0;
200 // Generate unique for proxy.
201 static std::string GenerateProxyId();
203 // Call this function to obtain printing system for specified print server.
204 // If print settings are NULL, default settings will be used.
205 // Return NULL if no print system available.
206 static scoped_refptr<PrintSystem> CreateInstance(
207 const base::DictionaryValue* print_system_settings);
209 protected:
210 friend class base::RefCountedThreadSafe<PrintSystem>;
211 virtual ~PrintSystem();
214 } // namespace cloud_print
216 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINT_SYSTEM_H_