| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_SERVICE_CLOUD_PRINT_PRINTER_INFO_H_ | |
| 6 #define CHROME_SERVICE_CLOUD_PRINT_PRINTER_INFO_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/file_path.h" | |
| 13 | |
| 14 // This is the interface for platform-specific code for cloud print | |
| 15 namespace cloud_print { | |
| 16 | |
| 17 typedef int PlatformJobId; | |
| 18 | |
| 19 struct PrinterBasicInfo { | |
| 20 std::string printer_name; | |
| 21 std::string printer_description; | |
| 22 int printer_status; | |
| 23 std::map<std::string, std::string> options; | |
| 24 PrinterBasicInfo() : printer_status(0) { | |
| 25 } | |
| 26 }; | |
| 27 | |
| 28 typedef std::vector<PrinterBasicInfo> PrinterList; | |
| 29 | |
| 30 struct PrinterCapsAndDefaults { | |
| 31 std::string printer_capabilities; | |
| 32 std::string caps_mime_type; | |
| 33 std::string printer_defaults; | |
| 34 std::string defaults_mime_type; | |
| 35 }; | |
| 36 | |
| 37 enum PrintJobStatus { | |
| 38 PRINT_JOB_STATUS_INVALID, | |
| 39 PRINT_JOB_STATUS_IN_PROGRESS, | |
| 40 PRINT_JOB_STATUS_ERROR, | |
| 41 PRINT_JOB_STATUS_COMPLETED | |
| 42 }; | |
| 43 | |
| 44 struct PrintJobDetails { | |
| 45 PrintJobStatus status; | |
| 46 int platform_status_flags; | |
| 47 std::string status_message; | |
| 48 int total_pages; | |
| 49 int pages_printed; | |
| 50 PrintJobDetails() : status(PRINT_JOB_STATUS_INVALID), | |
| 51 platform_status_flags(0), total_pages(0), | |
| 52 pages_printed(0) { | |
| 53 } | |
| 54 void Clear() { | |
| 55 status = PRINT_JOB_STATUS_INVALID; | |
| 56 platform_status_flags = 0; | |
| 57 status_message.clear(); | |
| 58 total_pages = 0; | |
| 59 pages_printed = 0; | |
| 60 } | |
| 61 bool operator ==(const PrintJobDetails& other) const { | |
| 62 return (status == other.status) && | |
| 63 (platform_status_flags == other.platform_status_flags) && | |
| 64 (status_message == other.status_message) && | |
| 65 (total_pages == other.total_pages) && | |
| 66 (pages_printed == other.pages_printed); | |
| 67 } | |
| 68 bool operator !=(const PrintJobDetails& other) const { | |
| 69 return !(*this == other); | |
| 70 } | |
| 71 }; | |
| 72 | |
| 73 // Enumerates the list of installed local and network printers. | |
| 74 void EnumeratePrinters(PrinterList* printer_list); | |
| 75 // Gets the capabilities and defaults for a specific printer. | |
| 76 bool GetPrinterCapsAndDefaults(const std::string& printer_name, | |
| 77 PrinterCapsAndDefaults* printer_info); | |
| 78 bool ValidatePrintTicket(const std::string& printer_name, | |
| 79 const std::string& print_ticket_data); | |
| 80 std::string GenerateProxyId(); | |
| 81 bool SpoolPrintJob(const std::string& print_ticket, | |
| 82 const FilePath& print_data_file_path, | |
| 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 | |
| 88 bool GetJobDetails(const std::string& printer_name, | |
| 89 PlatformJobId job_id, | |
| 90 PrintJobDetails *job_details); | |
| 91 bool IsValidPrinter(const std::string& printer_name); | |
| 92 | |
| 93 // A class that watches changes to a printer or a print server. | |
| 94 // The set of notifications are very coarse-grained (even though the Windows | |
| 95 // API allows for listening to fine-grained details about a printer, this class | |
| 96 // does not support that level of fine-grained control. | |
| 97 class PrinterChangeNotifier { | |
| 98 public: | |
| 99 class Delegate { | |
| 100 public: | |
| 101 virtual void OnPrinterAdded() = 0; | |
| 102 virtual void OnPrinterDeleted() = 0; | |
| 103 virtual void OnPrinterChanged() = 0; | |
| 104 virtual void OnJobChanged() = 0; | |
| 105 }; | |
| 106 PrinterChangeNotifier(); | |
| 107 ~PrinterChangeNotifier(); | |
| 108 bool StartWatching(const std::string& printer_name, Delegate* delegate); | |
| 109 bool StopWatching(); | |
| 110 bool GetCurrentPrinterInfo(PrinterBasicInfo* printer_info); | |
| 111 private: | |
| 112 // Internal state maintained by the PrinterChangeNotifier class. | |
| 113 class NotificationState; | |
| 114 NotificationState* state_; | |
| 115 DISALLOW_COPY_AND_ASSIGN(PrinterChangeNotifier); | |
| 116 }; | |
| 117 | |
| 118 // This typedef is to workaround the issue with certain versions of | |
| 119 // Visual Studio where it gets confused between multiple Delegate | |
| 120 // classes and gives a C2500 error. (I saw this error on the try bots - | |
| 121 // the workaround was not needed for my machine). | |
| 122 typedef PrinterChangeNotifier::Delegate PrinterChangeNotifierDelegate; | |
| 123 | |
| 124 } // namespace cloud_print | |
| 125 | |
| 126 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_INFO_H_ | |
| 127 | |
| OLD | NEW |