print_backend.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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. 4 5#ifndef PRINTING_BACKEND_PRINT_BACKEND_H_ 6#define PRINTING_BACKEND_PRINT_BACKEND_H_ 7 8#include <map> 9#include <string> 10#include <vector> 11 12#include "base/memory/ref_counted.h" 13#include "base/string16.h" 14#include "printing/print_job_constants.h" 15#include "printing/printing_export.h" 16 17namespace base { 18class DictionaryValue; 19} 20 21// This is the interface for platform-specific code for a print backend 22namespace printing { 23 24struct PRINTING_EXPORT PrinterBasicInfo { 25 PrinterBasicInfo(); 26 ~PrinterBasicInfo(); 27 28 std::string printer_name; 29 std::string printer_description; 30 int printer_status; 31 int is_default; 32 std::map<std::string, std::string> options; 33}; 34 35typedef std::vector<PrinterBasicInfo> PrinterList; 36 37struct PRINTING_EXPORT PrinterSemanticCapsAndDefaults { 38 PrinterSemanticCapsAndDefaults(); 39 ~PrinterSemanticCapsAndDefaults(); 40 41 // Capabilities. 42 bool color_capable; 43 bool duplex_capable; 44 45 // Current defaults. 46 bool color_default; 47 DuplexMode duplex_default; 48}; 49 50struct PRINTING_EXPORT PrinterCapsAndDefaults { 51 PrinterCapsAndDefaults(); 52 ~PrinterCapsAndDefaults(); 53 54 std::string printer_capabilities; 55 std::string caps_mime_type; 56 std::string printer_defaults; 57 std::string defaults_mime_type; 58}; 59 60// PrintBackend class will provide interface for different print backends 61// (Windows, CUPS) to implement. User will call CreateInstance() to 62// obtain available print backend. 63// Please note, that PrintBackend is not platform specific, but rather 64// print system specific. For example, CUPS is available on both Linux and Mac, 65// but not available on ChromeOS, etc. This design allows us to add more 66// functionality on some platforms, while reusing core (CUPS) functions. 67class PRINTING_EXPORT PrintBackend 68 : public base::RefCountedThreadSafe<PrintBackend> { 69 public: 70 // Enumerates the list of installed local and network printers. 71 virtual bool EnumeratePrinters(PrinterList* printer_list) = 0; 72 73 // Get the default printer name. Empty string if no default printer. 74 virtual std::string GetDefaultPrinterName() = 0; 75 76 // Gets the semantic capabilities and defaults for a specific printer. 77 // This is usually a lighter implementation than GetPrinterCapsAndDefaults(). 78 // NOTE: on some old platforms (WinXP without XPS pack) 79 // GetPrinterCapsAndDefaults() will fail, while this function will succeed. 80 virtual bool GetPrinterSemanticCapsAndDefaults( 81 const std::string& printer_name, 82 PrinterSemanticCapsAndDefaults* printer_info) = 0; 83 84 // Gets the capabilities and defaults for a specific printer. 85 virtual bool GetPrinterCapsAndDefaults( 86 const std::string& printer_name, 87 PrinterCapsAndDefaults* printer_info) = 0; 88 89 // Gets the information about driver for a specific printer. 90 virtual std::string GetPrinterDriverInfo( 91 const std::string& printer_name) = 0; 92 93 // Returns true if printer_name points to a valid printer. 94 virtual bool IsValidPrinter(const std::string& printer_name) = 0; 95 96 // Simplify title to resolve issue with some drivers. 97 static string16 SimplifyDocumentTitle(const string16& title); 98 99 // Allocate a print backend. If |print_backend_settings| is NULL, default 100 // settings will be used. 101 // Return NULL if no print backend available. 102 static scoped_refptr<PrintBackend> CreateInstance( 103 const base::DictionaryValue* print_backend_settings); 104 105 protected: 106 friend class base::RefCountedThreadSafe<PrintBackend>; 107 virtual ~PrintBackend(); 108}; 109 110} // namespace printing 111 112#endif // PRINTING_BACKEND_PRINT_BACKEND_H_ 113