| 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_WIN_HELPER_H_ | 5 #ifndef PRINTING_BACKEND_WIN_HELPER_H_ |
| 6 #define PRINTING_BACKEND_WIN_HELPER_H_ | 6 #define PRINTING_BACKEND_WIN_HELPER_H_ |
| 7 | 7 |
| 8 #include <objidl.h> | 8 #include <objidl.h> |
| 9 #include <winspool.h> | 9 #include <winspool.h> |
| 10 #include <prntvpt.h> | 10 #include <prntvpt.h> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 DISALLOW_IMPLICIT_CONSTRUCTORS(PrinterHandleTraits); | 41 DISALLOW_IMPLICIT_CONSTRUCTORS(PrinterHandleTraits); |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 class ScopedPrinterHandle | 44 class ScopedPrinterHandle |
| 45 : public base::win::GenericScopedHandle<PrinterHandleTraits, | 45 : public base::win::GenericScopedHandle<PrinterHandleTraits, |
| 46 base::win::VerifierTraits> { | 46 base::win::VerifierTraits> { |
| 47 public: | 47 public: |
| 48 bool OpenPrinter(const wchar_t* printer) { | 48 bool OpenPrinter(const wchar_t* printer) { |
| 49 HANDLE temp_handle; | |
| 50 // ::OpenPrinter may return error but assign some value into handle. | 49 // ::OpenPrinter may return error but assign some value into handle. |
| 51 if (::OpenPrinter(const_cast<LPTSTR>(printer), &temp_handle, NULL)) { | 50 if (!::OpenPrinter(const_cast<LPTSTR>(printer), Receive(), NULL)) { |
| 52 Set(temp_handle); | 51 Take(); |
| 53 } | 52 } |
| 54 return IsValid(); | 53 return IsValid(); |
| 55 } | 54 } |
| 56 | 55 |
| 57 private: | 56 private: |
| 58 typedef base::win::GenericScopedHandle<PrinterHandleTraits, | 57 typedef base::win::GenericScopedHandle<PrinterHandleTraits, |
| 59 base::win::VerifierTraits> Base; | 58 base::win::VerifierTraits> Base; |
| 59 // Hide Receive to avoid assigning handle when ::OpenPrinter returned error. |
| 60 Base::Receiver Receive() { |
| 61 return Base::Receive(); |
| 62 } |
| 60 }; | 63 }; |
| 61 | 64 |
| 62 class PrinterChangeHandleTraits { | 65 class PrinterChangeHandleTraits { |
| 63 public: | 66 public: |
| 64 typedef HANDLE Handle; | 67 typedef HANDLE Handle; |
| 65 | 68 |
| 66 static bool CloseHandle(HANDLE handle) { | 69 static bool CloseHandle(HANDLE handle) { |
| 67 ::FindClosePrinterChangeNotification(handle); | 70 ::FindClosePrinterChangeNotification(handle); |
| 68 return true; | 71 return true; |
| 69 } | 72 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 }; | 168 }; |
| 166 | 169 |
| 167 PRINTING_EXPORT bool InitBasicPrinterInfo(HANDLE printer, | 170 PRINTING_EXPORT bool InitBasicPrinterInfo(HANDLE printer, |
| 168 PrinterBasicInfo* printer_info); | 171 PrinterBasicInfo* printer_info); |
| 169 | 172 |
| 170 PRINTING_EXPORT std::string GetDriverInfo(HANDLE printer); | 173 PRINTING_EXPORT std::string GetDriverInfo(HANDLE printer); |
| 171 | 174 |
| 172 } // namespace printing | 175 } // namespace printing |
| 173 | 176 |
| 174 #endif // PRINTING_BACKEND_WIN_HELPER_H_ | 177 #endif // PRINTING_BACKEND_WIN_HELPER_H_ |
| OLD | NEW |