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

Unified Diff: printing/printing_context_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 | « printing/backend/print_backend_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/printing_context_win.cc
diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc
index 46093e77b41f0019180cf87a7db8978dff2da4b2..ae38c683611c8501b205a55f0de5b371091ac561 100644
--- a/printing/printing_context_win.cc
+++ b/printing/printing_context_win.cc
@@ -14,6 +14,7 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "printing/backend/win_helper.h"
#include "printing/print_job_constants.h"
#include "printing/print_settings_initializer_win.h"
#include "printing/printed_document.h"
@@ -381,9 +382,9 @@ PrintingContext::Result PrintingContextWin::UpdatePrinterSettings(
return OK;
}
- HANDLE printer;
+ ScopedPrinterHandle printer;
LPWSTR device_name_wide = const_cast<wchar_t*>(device_name.c_str());
- if (!OpenPrinter(device_name_wide, &printer, NULL))
+ if (!OpenPrinter(device_name_wide, printer.Receive(), NULL))
return OnError();
// Make printer changes local to Chrome.
@@ -403,7 +404,6 @@ PrintingContext::Result PrintingContextWin::UpdatePrinterSettings(
}
if (dev_mode == NULL) {
buffer.reset();
- ClosePrinter(printer);
return OnError();
}
@@ -433,19 +433,16 @@ PrintingContext::Result PrintingContextWin::UpdatePrinterSettings(
// Update data using DocumentProperties.
if (DocumentProperties(NULL, printer, device_name_wide, dev_mode, dev_mode,
DM_IN_BUFFER | DM_OUT_BUFFER) != IDOK) {
- ClosePrinter(printer);
return OnError();
}
// Set printer then refresh printer settings.
if (!AllocateContext(device_name, dev_mode, &context_)) {
- ClosePrinter(printer);
return OnError();
}
PrintSettingsInitializerWin::InitPrintSettings(context_, *dev_mode,
ranges, device_name,
false, &settings_);
- ClosePrinter(printer);
return OK;
}
@@ -456,10 +453,9 @@ PrintingContext::Result PrintingContextWin::InitWithSettings(
settings_ = settings;
// TODO(maruel): settings_.ToDEVMODE()
- HANDLE printer;
+ ScopedPrinterHandle printer;
if (!OpenPrinter(const_cast<wchar_t*>(settings_.device_name().c_str()),
- &printer,
- NULL))
+ printer.Receive(), NULL))
return FAILED;
Result status = OK;
@@ -467,9 +463,6 @@ PrintingContext::Result PrintingContextWin::InitWithSettings(
if (!GetPrinterSettings(printer, settings_.device_name()))
status = FAILED;
- // Close the printer after retrieving the context.
- ClosePrinter(printer);
-
if (status != OK)
ResetSettings();
return status;
« no previous file with comments | « printing/backend/print_backend_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698