Fixed channel references in apps and extension intros
[chromium-blink-merge.git] / printing / backend / printing_info_win.h
blob1e9afd930acbed8d3df910dc75e64eccee599ab4
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 PRINTING_BACKEND_PRINTING_INFO_WIN_H_
6 #define PRINTING_BACKEND_PRINTING_INFO_WIN_H_
8 #include <objidl.h>
9 #include <winspool.h>
11 #include "base/memory/scoped_ptr.h"
12 #include "printing/printing_export.h"
14 namespace printing {
16 namespace internal {
18 PRINTING_EXPORT uint8* GetDriverInfo(HANDLE printer, int level);
19 PRINTING_EXPORT uint8* GetPrinterInfo(HANDLE printer, int level);
21 // This class is designed to work with PRINTER_INFO_X structures
22 // and calls GetPrinter internally with correctly allocated buffer.
23 template <typename PrinterInfoType, int level>
24 class PrinterInfo {
25 public:
26 bool Init(HANDLE printer) {
27 buffer_.reset(GetPrinterInfo(printer, level));
28 return buffer_;
31 const PrinterInfoType* get() const {
32 return reinterpret_cast<const PrinterInfoType*>(buffer_.get());
35 private:
36 scoped_array<uint8> buffer_;
39 // This class is designed to work with DRIVER_INFO_X structures
40 // and calls GetDriverInfo internally with correctly allocated buffer.
41 template <typename DriverInfoType, int level>
42 class DriverInfo {
43 public:
44 bool Init(HANDLE printer) {
45 buffer_.reset(GetDriverInfo(printer, level));
46 return buffer_;
49 const DriverInfoType* get() const {
50 return reinterpret_cast<const DriverInfoType*>(buffer_.get());
53 private:
54 scoped_array<uint8> buffer_;
57 } // namespace internal
59 typedef internal::PrinterInfo<PRINTER_INFO_2, 2> PrinterInfo2;
60 typedef internal::PrinterInfo<PRINTER_INFO_5, 5> PrinterInfo5;
61 typedef internal::PrinterInfo<PRINTER_INFO_8, 8> PrinterInfo8;
62 typedef internal::PrinterInfo<PRINTER_INFO_9, 9> PrinterInfo9;
64 typedef internal::DriverInfo<DRIVER_INFO_6, 6> DriverInfo6;
66 // Retrieves DEVMODE from PRINTER_INFO_* structures.
67 // Requests in following order:
68 // 9 (user-default),
69 // 8 (admin-default),
70 // 2 (printer-default).
71 class PRINTING_EXPORT UserDefaultDevMode {
72 public:
73 UserDefaultDevMode();
74 ~UserDefaultDevMode();
76 bool Init(HANDLE printer);
78 const DEVMODE* get() const {
79 return dev_mode_;
82 private:
83 PrinterInfo2 info_2_;
84 PrinterInfo8 info_8_;
85 PrinterInfo9 info_9_;
86 const DEVMODE* dev_mode_;
89 } // namespace printing
91 #endif // PRINTING_BACKEND_PRINTING_INFO_WIN_H_