Chromium Code Reviews| 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 "base/memory/scoped_ptr.h" |
| 13 #include "printing/printing_export.h" | 13 #include "printing/printing_export.h" |
| 14 | 14 |
| 15 namespace printing { | 15 namespace printing { |
| 16 | 16 |
| 17 namespace internal { | 17 namespace internal { |
| 18 | 18 |
| 19 PRINTING_EXPORT uint8_t* GetDriverInfo(HANDLE printer, int level); | 19 PRINTING_EXPORT uint8_t* GetDriverInfo(HANDLE printer, int level); |
| 20 PRINTING_EXPORT uint8_t* GetPrinterInfo(HANDLE printer, int level); | 20 PRINTING_EXPORT uint8_t* GetPrinterInfo(HANDLE printer, int level); |
| 21 | 21 |
| 22 // This class is designed to work with PRINTER_INFO_X structures | 22 // This class is designed to work with PRINTER_INFO_X structures |
| 23 // and calls GetPrinter internally with correctly allocated buffer. | 23 // and calls GetPrinter internally with correctly allocated buffer. |
| 24 template <typename PrinterInfoType, int level> | 24 template <typename PrinterInfoType, int level> |
| 25 class PrinterInfo { | 25 class PrinterInfo { |
| 26 public: | 26 public: |
| 27 bool Init(HANDLE printer) { | 27 bool Init(HANDLE printer) { |
| 28 buffer_.reset(GetPrinterInfo(printer, level)); | 28 buffer_.reset(GetPrinterInfo(printer, level)); |
| 29 return buffer_; | 29 return buffer_ != nullptr; |
|
Vitaly Buka (NO REVIEWS)
2016/03/04 18:25:17
is any warning without this?
I thought Chromium pr
dcheng
2016/03/04 18:28:59
It depends on the reviewer =P
With C++11 and expl
Vitaly Buka (NO REVIEWS)
2016/03/04 18:34:39
Thanks. I like !! too, but current one is lgtm too
joedow
2016/03/04 20:46:19
I like !! as well to boolify but I have seen feedb
| |
| 30 } | 30 } |
| 31 | 31 |
| 32 const PrinterInfoType* get() const { | 32 const PrinterInfoType* get() const { |
| 33 return reinterpret_cast<const PrinterInfoType*>(buffer_.get()); | 33 return reinterpret_cast<const PrinterInfoType*>(buffer_.get()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 scoped_ptr<uint8_t[]> buffer_; | 37 scoped_ptr<uint8_t[]> buffer_; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 // This class is designed to work with DRIVER_INFO_X structures | 40 // This class is designed to work with DRIVER_INFO_X structures |
| 41 // and calls GetDriverInfo internally with correctly allocated buffer. | 41 // and calls GetDriverInfo internally with correctly allocated buffer. |
| 42 template <typename DriverInfoType, int level> | 42 template <typename DriverInfoType, int level> |
| 43 class DriverInfo { | 43 class DriverInfo { |
| 44 public: | 44 public: |
| 45 bool Init(HANDLE printer) { | 45 bool Init(HANDLE printer) { |
| 46 buffer_.reset(GetDriverInfo(printer, level)); | 46 buffer_.reset(GetDriverInfo(printer, level)); |
| 47 return buffer_; | 47 return buffer_ != nullptr; |
| 48 } | 48 } |
| 49 | 49 |
| 50 const DriverInfoType* get() const { | 50 const DriverInfoType* get() const { |
| 51 return reinterpret_cast<const DriverInfoType*>(buffer_.get()); | 51 return reinterpret_cast<const DriverInfoType*>(buffer_.get()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 scoped_ptr<uint8_t[]> buffer_; | 55 scoped_ptr<uint8_t[]> buffer_; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 } // namespace internal | 58 } // namespace internal |
| 59 | 59 |
| 60 typedef internal::PrinterInfo<PRINTER_INFO_2, 2> PrinterInfo2; | 60 typedef internal::PrinterInfo<PRINTER_INFO_2, 2> PrinterInfo2; |
| 61 typedef internal::PrinterInfo<PRINTER_INFO_5, 5> PrinterInfo5; | 61 typedef internal::PrinterInfo<PRINTER_INFO_5, 5> PrinterInfo5; |
| 62 | 62 |
| 63 typedef internal::DriverInfo<DRIVER_INFO_6, 6> DriverInfo6; | 63 typedef internal::DriverInfo<DRIVER_INFO_6, 6> DriverInfo6; |
| 64 | 64 |
| 65 } // namespace printing | 65 } // namespace printing |
| 66 | 66 |
| 67 #endif // PRINTING_BACKEND_PRINTING_INFO_WIN_H_ | 67 #endif // PRINTING_BACKEND_PRINTING_INFO_WIN_H_ |
| OLD | NEW |