OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "printing/backend/print_backend.h" | 5 #include "printing/backend/print_backend.h" |
6 | 6 |
7 #include <objidl.h> | 7 #include <objidl.h> |
8 #include <winspool.h> | 8 #include <winspool.h> |
9 | 9 |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 namespace printing { | 39 namespace printing { |
40 | 40 |
41 class PrintBackendWin : public PrintBackend { | 41 class PrintBackendWin : public PrintBackend { |
42 public: | 42 public: |
43 PrintBackendWin() {} | 43 PrintBackendWin() {} |
44 virtual ~PrintBackendWin() {} | 44 virtual ~PrintBackendWin() {} |
45 | 45 |
46 virtual void EnumeratePrinters(PrinterList* printer_list); | 46 virtual bool EnumeratePrinters(PrinterList* printer_list); |
47 | 47 |
48 virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name, | 48 virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name, |
49 PrinterCapsAndDefaults* printer_info); | 49 PrinterCapsAndDefaults* printer_info); |
50 | 50 |
51 virtual bool IsValidPrinter(const std::string& printer_name); | 51 virtual bool IsValidPrinter(const std::string& printer_name); |
52 }; | 52 }; |
53 | 53 |
54 void PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) { | 54 bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) { |
55 DCHECK(printer_list); | 55 DCHECK(printer_list); |
56 DWORD bytes_needed = 0; | 56 DWORD bytes_needed = 0; |
57 DWORD count_returned = 0; | 57 DWORD count_returned = 0; |
58 BOOL ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, | 58 BOOL ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, |
59 NULL, 0, &bytes_needed, &count_returned); | 59 NULL, 0, &bytes_needed, &count_returned); |
60 if (0 != bytes_needed) { | 60 if (!bytes_needed) |
Scott Byer
2011/01/24 20:02:07
Check the return value as well?
| |
61 scoped_ptr<BYTE> printer_info_buffer(new BYTE[bytes_needed]); | 61 return false; |
62 ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, | 62 scoped_ptr<BYTE> printer_info_buffer(new BYTE[bytes_needed]); |
63 printer_info_buffer.get(), bytes_needed, &bytes_needed, | 63 ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, |
64 &count_returned); | 64 printer_info_buffer.get(), bytes_needed, &bytes_needed, |
65 DCHECK(ret); | 65 &count_returned); |
66 PRINTER_INFO_2* printer_info = | 66 DCHECK(ret); |
67 reinterpret_cast<PRINTER_INFO_2*>(printer_info_buffer.get()); | 67 if (!ret) |
68 for (DWORD index = 0; index < count_returned; index++) { | 68 return false; |
69 PrinterBasicInfo info; | 69 |
70 info.printer_name = WideToUTF8(printer_info[index].pPrinterName); | 70 PRINTER_INFO_2* printer_info = |
71 if (printer_info[index].pComment) | 71 reinterpret_cast<PRINTER_INFO_2*>(printer_info_buffer.get()); |
72 info.printer_description = WideToUTF8(printer_info[index].pComment); | 72 for (DWORD index = 0; index < count_returned; index++) { |
73 info.printer_status = printer_info[index].Status; | 73 PrinterBasicInfo info; |
74 if (printer_info[index].pLocation) | 74 info.printer_name = WideToUTF8(printer_info[index].pPrinterName); |
75 info.options[kLocationTagName] = | 75 if (printer_info[index].pComment) |
76 WideToUTF8(printer_info[index].pLocation); | 76 info.printer_description = WideToUTF8(printer_info[index].pComment); |
77 if (printer_info[index].pDriverName) | 77 info.printer_status = printer_info[index].Status; |
78 info.options[kDriverNameTagName] = | 78 if (printer_info[index].pLocation) |
79 WideToUTF8(printer_info[index].pDriverName); | 79 info.options[kLocationTagName] = |
80 printer_list->push_back(info); | 80 WideToUTF8(printer_info[index].pLocation); |
81 } | 81 if (printer_info[index].pDriverName) |
82 info.options[kDriverNameTagName] = | |
83 WideToUTF8(printer_info[index].pDriverName); | |
84 printer_list->push_back(info); | |
82 } | 85 } |
86 return true; | |
83 } | 87 } |
84 | 88 |
85 bool PrintBackendWin::GetPrinterCapsAndDefaults( | 89 bool PrintBackendWin::GetPrinterCapsAndDefaults( |
86 const std::string& printer_name, | 90 const std::string& printer_name, |
87 PrinterCapsAndDefaults* printer_info) { | 91 PrinterCapsAndDefaults* printer_info) { |
88 ScopedXPSInitializer xps_initializer; | 92 ScopedXPSInitializer xps_initializer; |
89 if (!xps_initializer.initialized()) { | 93 if (!xps_initializer.initialized()) { |
90 // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) | 94 // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) |
91 return false; | 95 return false; |
92 } | 96 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 } | 175 } |
172 return ret; | 176 return ret; |
173 } | 177 } |
174 | 178 |
175 scoped_refptr<PrintBackend> PrintBackend::CreateInstance( | 179 scoped_refptr<PrintBackend> PrintBackend::CreateInstance( |
176 const DictionaryValue* print_backend_settings) { | 180 const DictionaryValue* print_backend_settings) { |
177 return new PrintBackendWin; | 181 return new PrintBackendWin; |
178 } | 182 } |
179 | 183 |
180 } // namespace printing | 184 } // namespace printing |
OLD | NEW |