summaryrefslogtreecommitdiffstats
path: root/printing/backend
diff options
context:
space:
mode:
authorvitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 22:50:54 +0000
committervitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-02 22:50:54 +0000
commit55e8e9fcaa7c61d44564a2c59338dc6abb1404a7 (patch)
tree291de084668ac5eac141b0a76ffc3355208728cc /printing/backend
parentea0b72bc5bba3ba3829ae849a201f320e99dcd5f (diff)
downloadchromium_src-55e8e9fcaa7c61d44564a2c59338dc6abb1404a7.zip
chromium_src-55e8e9fcaa7c61d44564a2c59338dc6abb1404a7.tar.gz
chromium_src-55e8e9fcaa7c61d44564a2c59338dc6abb1404a7.tar.bz2
Improved resource management by using ScopedPrinterHandle.
BUG=none TEST=none Review URL: http://codereview.chromium.org/9569029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124755 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/backend')
-rw-r--r--printing/backend/print_backend_win.cc25
1 files changed, 9 insertions, 16 deletions
diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc
index 01be277..9995005 100644
--- a/printing/backend/print_backend_win.cc
+++ b/printing/backend/print_backend_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -131,12 +131,11 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
DCHECK(SUCCEEDED(hr));
printer_info->caps_mime_type = "text/xml";
}
- // TODO(sanjeevr): Add ScopedPrinterHandle
- HANDLE printer_handle = NULL;
- OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()), &printer_handle,
- NULL);
+ ScopedPrinterHandle printer_handle;
+ OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()),
+ printer_handle.Receive(), NULL);
DCHECK(printer_handle);
- if (printer_handle) {
+ if (printer_handle.IsValid()) {
LONG devmode_size = DocumentProperties(
NULL, printer_handle, const_cast<LPTSTR>(printer_name_wide.c_str()),
NULL, NULL, 0);
@@ -166,7 +165,6 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
printer_info->defaults_mime_type = "text/xml";
}
}
- ClosePrinter(printer_handle);
}
XPSModule::CloseProvider(provider);
}
@@ -175,15 +173,10 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) {
std::wstring printer_name_wide = UTF8ToWide(printer_name);
- HANDLE printer_handle = NULL;
- OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()), &printer_handle,
- NULL);
- bool ret = false;
- if (printer_handle) {
- ret = true;
- ClosePrinter(printer_handle);
- }
- return ret;
+ ScopedPrinterHandle printer_handle;
+ OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()),
+ printer_handle.Receive(), NULL);
+ return printer_handle.IsValid();
}
scoped_refptr<PrintBackend> PrintBackend::CreateInstance(