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