| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PRINTING_BACKEND_PRINTING_INFO_WIN_H_ | 5 #ifndef PRINTING_BACKEND_PRINTING_INFO_WIN_H_ |
| 6 #define PRINTING_BACKEND_PRINTING_INFO_WIN_H_ | 6 #define PRINTING_BACKEND_PRINTING_INFO_WIN_H_ |
| 7 | 7 |
| 8 #include <objidl.h> | 8 #include <objidl.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <winspool.h> | 10 #include <winspool.h> |
| 11 | 11 |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include <memory> |
| 13 |
| 13 #include "printing/printing_export.h" | 14 #include "printing/printing_export.h" |
| 14 | 15 |
| 15 namespace printing { | 16 namespace printing { |
| 16 | 17 |
| 17 namespace internal { | 18 namespace internal { |
| 18 | 19 |
| 19 PRINTING_EXPORT uint8_t* GetDriverInfo(HANDLE printer, int level); | 20 PRINTING_EXPORT uint8_t* GetDriverInfo(HANDLE printer, int level); |
| 20 PRINTING_EXPORT uint8_t* GetPrinterInfo(HANDLE printer, int level); | 21 PRINTING_EXPORT uint8_t* GetPrinterInfo(HANDLE printer, int level); |
| 21 | 22 |
| 22 // This class is designed to work with PRINTER_INFO_X structures | 23 // This class is designed to work with PRINTER_INFO_X structures |
| 23 // and calls GetPrinter internally with correctly allocated buffer. | 24 // and calls GetPrinter internally with correctly allocated buffer. |
| 24 template <typename PrinterInfoType, int level> | 25 template <typename PrinterInfoType, int level> |
| 25 class PrinterInfo { | 26 class PrinterInfo { |
| 26 public: | 27 public: |
| 27 bool Init(HANDLE printer) { | 28 bool Init(HANDLE printer) { |
| 28 buffer_.reset(GetPrinterInfo(printer, level)); | 29 buffer_.reset(GetPrinterInfo(printer, level)); |
| 29 return buffer_ != nullptr; | 30 return buffer_ != nullptr; |
| 30 } | 31 } |
| 31 | 32 |
| 32 const PrinterInfoType* get() const { | 33 const PrinterInfoType* get() const { |
| 33 return reinterpret_cast<const PrinterInfoType*>(buffer_.get()); | 34 return reinterpret_cast<const PrinterInfoType*>(buffer_.get()); |
| 34 } | 35 } |
| 35 | 36 |
| 36 private: | 37 private: |
| 37 scoped_ptr<uint8_t[]> buffer_; | 38 std::unique_ptr<uint8_t[]> buffer_; |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 // This class is designed to work with DRIVER_INFO_X structures | 41 // This class is designed to work with DRIVER_INFO_X structures |
| 41 // and calls GetDriverInfo internally with correctly allocated buffer. | 42 // and calls GetDriverInfo internally with correctly allocated buffer. |
| 42 template <typename DriverInfoType, int level> | 43 template <typename DriverInfoType, int level> |
| 43 class DriverInfo { | 44 class DriverInfo { |
| 44 public: | 45 public: |
| 45 bool Init(HANDLE printer) { | 46 bool Init(HANDLE printer) { |
| 46 buffer_.reset(GetDriverInfo(printer, level)); | 47 buffer_.reset(GetDriverInfo(printer, level)); |
| 47 return buffer_ != nullptr; | 48 return buffer_ != nullptr; |
| 48 } | 49 } |
| 49 | 50 |
| 50 const DriverInfoType* get() const { | 51 const DriverInfoType* get() const { |
| 51 return reinterpret_cast<const DriverInfoType*>(buffer_.get()); | 52 return reinterpret_cast<const DriverInfoType*>(buffer_.get()); |
| 52 } | 53 } |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 scoped_ptr<uint8_t[]> buffer_; | 56 std::unique_ptr<uint8_t[]> buffer_; |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 } // namespace internal | 59 } // namespace internal |
| 59 | 60 |
| 60 typedef internal::PrinterInfo<PRINTER_INFO_2, 2> PrinterInfo2; | 61 typedef internal::PrinterInfo<PRINTER_INFO_2, 2> PrinterInfo2; |
| 61 typedef internal::PrinterInfo<PRINTER_INFO_5, 5> PrinterInfo5; | 62 typedef internal::PrinterInfo<PRINTER_INFO_5, 5> PrinterInfo5; |
| 62 | 63 |
| 63 typedef internal::DriverInfo<DRIVER_INFO_6, 6> DriverInfo6; | 64 typedef internal::DriverInfo<DRIVER_INFO_6, 6> DriverInfo6; |
| 64 | 65 |
| 65 } // namespace printing | 66 } // namespace printing |
| 66 | 67 |
| 67 #endif // PRINTING_BACKEND_PRINTING_INFO_WIN_H_ | 68 #endif // PRINTING_BACKEND_PRINTING_INFO_WIN_H_ |
| OLD | NEW |