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

Unified Diff: printing/backend/print_backend_win.cc

Issue 9569029: Improved resource management (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review Created 8 years, 10 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/printing_context_win.cc » ('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 01be277fe11f72dc23cb987fddaa2a5f30dcd6b2..a22a621e470bc34134ff0a8879492bb096da8af1 100644
--- a/printing/backend/print_backend_win.cc
+++ b/printing/backend/print_backend_win.cc
@@ -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(
« no previous file with comments | « chrome/service/cloud_print/print_system_win.cc ('k') | printing/printing_context_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698