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

Unified Diff: printing/print_settings_initializer_win.cc

Issue 2637243002: Refactor code in print_settings_intializer_win.cc (Closed)
Patch Set: Created 3 years, 11 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/print_settings_initializer_win.cc
diff --git a/printing/print_settings_initializer_win.cc b/printing/print_settings_initializer_win.cc
index e72033d04ffa46511978e7a2f9a8f8b538dfa54a..0776e9e5c0e5636864e8d611edbbc704ae5686d4 100644
--- a/printing/print_settings_initializer_win.cc
+++ b/printing/print_settings_initializer_win.cc
@@ -12,26 +12,29 @@ namespace printing {
namespace {
-bool IsPrinterXPS(HDC hdc) {
- int device_type = ::GetDeviceCaps(hdc, TECHNOLOGY);
- if (device_type != DT_RASPRINTER)
+bool HasEscapeSupprt(HDC hdc, DWORD escape) {
+ const char* ptr = reinterpret_cast<const char*>(&escape);
+ return ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), ptr, 0, nullptr) > 0;
+}
+
+bool IsTechnology(HDC hdc, const char* technology) {
+ if (::GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASPRINTER)
return false;
- const DWORD escape = GETTECHNOLOGY;
- const char* escape_ptr = reinterpret_cast<const char*>(&escape);
- int ret =
- ExtEscape(hdc, QUERYESCSUPPORT, sizeof(escape), escape_ptr, 0, nullptr);
- if (ret <= 0)
+ if (!HasEscapeSupprt(hdc, GETTECHNOLOGY))
return false;
- char buffer[256];
- memset(buffer, 0, sizeof(buffer));
- ret = ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buffer) - 1, buffer);
- if (ret <= 0)
+ char buf[256];
+ memset(buf, 0, sizeof(buf));
+ if (ExtEscape(hdc, GETTECHNOLOGY, 0, nullptr, sizeof(buf) - 1, buf) <= 0)
return false;
+ return strcmp(buf, technology) == 0;
+}
- static const char kXPSDriver[] = "http://schemas.microsoft.com/xps/2005/06";
- return strcmp(buffer, kXPSDriver) == 0;
+bool IsPrinterXPS(HDC hdc) {
+ static constexpr char kXPSDriver[] =
+ "http://schemas.microsoft.com/xps/2005/06";
+ return IsTechnology(hdc, kXPSDriver);
}
} // namespace
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698