Chromium Code Reviews| 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/win_helper.h" | 5 #include "printing/backend/win_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name, | 10 typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 BSTR* error_message); | 30 BSTR* error_message); |
| 31 typedef HRESULT (WINAPI *PTMergeAndValidatePrintTicketProc)( | 31 typedef HRESULT (WINAPI *PTMergeAndValidatePrintTicketProc)( |
| 32 HPTPROVIDER provider, | 32 HPTPROVIDER provider, |
| 33 IStream* base_ticket, | 33 IStream* base_ticket, |
| 34 IStream* delta_ticket, | 34 IStream* delta_ticket, |
| 35 EPrintTicketScope scope, | 35 EPrintTicketScope scope, |
| 36 IStream* result_ticket, | 36 IStream* result_ticket, |
| 37 BSTR* error_message); | 37 BSTR* error_message); |
| 38 typedef HRESULT (WINAPI *PTReleaseMemoryProc)(PVOID buffer); | 38 typedef HRESULT (WINAPI *PTReleaseMemoryProc)(PVOID buffer); |
| 39 typedef HRESULT (WINAPI *PTCloseProviderProc)(HPTPROVIDER provider); | 39 typedef HRESULT (WINAPI *PTCloseProviderProc)(HPTPROVIDER provider); |
| 40 typedef HRESULT (WINAPI *StartXpsPrintJobProc)( | |
| 41 const LPCWSTR printer_name, | |
| 42 const LPCWSTR job_name, | |
| 43 const LPCWSTR output_file_name, | |
| 44 HANDLE progress_event, | |
| 45 HANDLE completion_event, | |
| 46 UINT8 *printable_pages_on, | |
| 47 UINT32 printable_pages_on_count, | |
| 48 IXpsPrintJob **xps_print_job, | |
| 49 IXpsPrintJobStream **document_stream, | |
| 50 IXpsPrintJobStream **print_ticket_stream); | |
| 40 | 51 |
| 41 PTOpenProviderProc g_open_provider_proc = NULL; | 52 PTOpenProviderProc g_open_provider_proc = NULL; |
| 42 PTGetPrintCapabilitiesProc g_get_print_capabilities_proc = NULL; | 53 PTGetPrintCapabilitiesProc g_get_print_capabilities_proc = NULL; |
| 43 PTConvertDevModeToPrintTicketProc g_convert_devmode_to_print_ticket_proc = NULL; | 54 PTConvertDevModeToPrintTicketProc g_convert_devmode_to_print_ticket_proc = NULL; |
| 44 PTConvertPrintTicketToDevModeProc g_convert_print_ticket_to_devmode_proc = NULL; | 55 PTConvertPrintTicketToDevModeProc g_convert_print_ticket_to_devmode_proc = NULL; |
| 45 PTMergeAndValidatePrintTicketProc g_merge_and_validate_print_ticket_proc = NULL; | 56 PTMergeAndValidatePrintTicketProc g_merge_and_validate_print_ticket_proc = NULL; |
| 46 PTReleaseMemoryProc g_release_memory_proc = NULL; | 57 PTReleaseMemoryProc g_release_memory_proc = NULL; |
| 47 PTCloseProviderProc g_close_provider_proc = NULL; | 58 PTCloseProviderProc g_close_provider_proc = NULL; |
| 59 StartXpsPrintJobProc g_start_xps_print_job_proc = NULL; | |
| 48 } | 60 } |
| 49 | 61 |
| 50 namespace printing { | 62 namespace printing { |
| 51 | 63 |
| 52 bool XPSModule::Init() { | 64 bool XPSModule::Init() { |
| 53 static bool initialized = InitImpl(); | 65 static bool initialized = InitImpl(); |
| 54 return initialized; | 66 return initialized; |
| 55 } | 67 } |
| 56 | 68 |
| 57 bool XPSModule::InitImpl() { | 69 bool XPSModule::InitImpl() { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 initialized_ = true; | 212 initialized_ = true; |
| 201 } | 213 } |
| 202 } | 214 } |
| 203 | 215 |
| 204 ScopedXPSInitializer::~ScopedXPSInitializer() { | 216 ScopedXPSInitializer::~ScopedXPSInitializer() { |
| 205 if (initialized_) | 217 if (initialized_) |
| 206 CoUninitialize(); | 218 CoUninitialize(); |
| 207 initialized_ = false; | 219 initialized_ = false; |
| 208 } | 220 } |
| 209 | 221 |
| 222 bool XPSPrintModule::Init() { | |
| 223 static bool initialized = InitImpl(); | |
|
Scott Byer
2011/02/17 00:31:02
This isn't thread safe, really. Use LazyInstance i
sanjeevr
2011/02/17 00:53:52
Yes, I know this isn't thread-safe. But it does no
| |
| 224 return initialized; | |
| 225 } | |
| 226 | |
| 227 bool XPSPrintModule::InitImpl() { | |
| 228 HMODULE xpsprint_module = LoadLibrary(L"xpsprint.dll"); | |
| 229 if (xpsprint_module == NULL) | |
| 230 return false; | |
| 231 g_start_xps_print_job_proc = reinterpret_cast<StartXpsPrintJobProc>( | |
| 232 GetProcAddress(xpsprint_module, "StartXpsPrintJob")); | |
| 233 if (!g_start_xps_print_job_proc) { | |
| 234 NOTREACHED(); | |
| 235 return false; | |
| 236 } | |
| 237 return true; | |
| 238 } | |
| 239 | |
| 240 HRESULT XPSPrintModule::StartXpsPrintJob( | |
| 241 const LPCWSTR printer_name, | |
| 242 const LPCWSTR job_name, | |
| 243 const LPCWSTR output_file_name, | |
| 244 HANDLE progress_event, | |
| 245 HANDLE completion_event, | |
| 246 UINT8 *printable_pages_on, | |
| 247 UINT32 printable_pages_on_count, | |
| 248 IXpsPrintJob **xps_print_job, | |
| 249 IXpsPrintJobStream **document_stream, | |
| 250 IXpsPrintJobStream **print_ticket_stream) { | |
| 251 return g_start_xps_print_job_proc(printer_name, | |
| 252 job_name, | |
| 253 output_file_name, | |
| 254 progress_event, | |
| 255 completion_event, | |
| 256 printable_pages_on, | |
| 257 printable_pages_on_count, | |
| 258 xps_print_job, | |
| 259 document_stream, | |
| 260 print_ticket_stream); | |
| 261 } | |
| 262 | |
| 210 } // namespace printing | 263 } // namespace printing |
| OLD | NEW |