Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3265)

Unified Diff: printing/backend/print_backend_win.cc

Issue 2904353002: CHECK XPS initialization succeeds on Windows. (Closed)
Patch Set: MakeUnique instead Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/service/cloud_print/print_system_win.cc ('k') | printing/backend/win_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/backend/print_backend_win.cc
diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc
index 7a657142f5934f136abd79b41d587a9cfc297729..ac29e6715885a72282f95033150e1547acee3445 100644
--- a/printing/backend/print_backend_win.cc
+++ b/printing/backend/print_backend_win.cc
@@ -11,6 +11,7 @@
#include <memory>
#include "base/memory/free_deleter.h"
+#include "base/memory/ptr_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
@@ -187,7 +188,8 @@ bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) {
nullptr, 0, &bytes_needed, &count_returned);
if (!bytes_needed)
return false;
- std::unique_ptr<BYTE[]> printer_info_buffer(new BYTE[bytes_needed]);
+
+ auto printer_info_buffer = base::MakeUnique<BYTE[]>(bytes_needed);
if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, nullptr,
kLevel, printer_info_buffer.get(), bytes_needed,
&bytes_needed, &count_returned)) {
@@ -307,27 +309,29 @@ bool PrintBackendWin::GetPrinterSemanticCapsAndDefaults(
bool PrintBackendWin::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
+ DCHECK(printer_info);
+
ScopedXPSInitializer xps_initializer;
- if (!xps_initializer.initialized()) {
- // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll)
- return false;
- }
- if (!IsValidPrinter(printer_name)) {
+ CHECK(xps_initializer.initialized());
+
+ if (!IsValidPrinter(printer_name))
return false;
- }
- DCHECK(printer_info);
- HPTPROVIDER provider = NULL;
+
+ HPTPROVIDER provider = nullptr;
std::wstring printer_name_wide = base::UTF8ToWide(printer_name);
HRESULT hr = XPSModule::OpenProvider(printer_name_wide, 1, &provider);
- if (provider) {
+ if (!provider)
+ return true;
+
+ {
base::win::ScopedComPtr<IStream> print_capabilities_stream;
- hr = CreateStreamOnHGlobal(NULL, TRUE,
+ hr = CreateStreamOnHGlobal(nullptr, TRUE,
print_capabilities_stream.GetAddressOf());
DCHECK(SUCCEEDED(hr));
if (print_capabilities_stream.Get()) {
base::win::ScopedBstr error;
hr = XPSModule::GetPrintCapabilities(
- provider, NULL, print_capabilities_stream.Get(), error.Receive());
+ provider, nullptr, print_capabilities_stream.Get(), error.Receive());
DCHECK(SUCCEEDED(hr));
if (FAILED(hr)) {
return false;
@@ -340,11 +344,11 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
ScopedPrinterHandle printer_handle;
if (printer_handle.OpenPrinter(printer_name_wide.c_str())) {
std::unique_ptr<DEVMODE, base::FreeDeleter> devmode_out(
- CreateDevMode(printer_handle.Get(), NULL));
+ CreateDevMode(printer_handle.Get(), nullptr));
if (!devmode_out)
return false;
base::win::ScopedComPtr<IStream> printer_defaults_stream;
- hr = CreateStreamOnHGlobal(NULL, TRUE,
+ hr = CreateStreamOnHGlobal(nullptr, TRUE,
printer_defaults_stream.GetAddressOf());
DCHECK(SUCCEEDED(hr));
if (printer_defaults_stream.Get()) {
« no previous file with comments | « chrome/service/cloud_print/print_system_win.cc ('k') | printing/backend/win_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698