summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-28 21:50:29 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-28 21:50:29 +0000
commitffcb1ca31ec8deda19bb02475a1084be549e15b7 (patch)
tree2417a45447e92595ca840899388147acd78f7e0f
parenta751c1a98e3379a946377bf7c5e5188575ed99b6 (diff)
downloadchromium_src-ffcb1ca31ec8deda19bb02475a1084be549e15b7.zip
chromium_src-ffcb1ca31ec8deda19bb02475a1084be549e15b7.tar.gz
chromium_src-ffcb1ca31ec8deda19bb02475a1084be549e15b7.tar.bz2
Printing: Add ability to get the default printer from the print backend.
BUG=84126 TEST=none Review URL: http://codereview.chromium.org/7087011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87187 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--printing/backend/print_backend.h3
-rw-r--r--printing/backend/print_backend_cups.cc11
-rw-r--r--printing/backend/print_backend_win.cc20
3 files changed, 25 insertions, 9 deletions
diff --git a/printing/backend/print_backend.h b/printing/backend/print_backend.h
index a6caa51..f53eaa5 100644
--- a/printing/backend/print_backend.h
+++ b/printing/backend/print_backend.h
@@ -54,6 +54,9 @@ class PrintBackend : public base::RefCountedThreadSafe<PrintBackend> {
// Enumerates the list of installed local and network printers.
virtual bool EnumeratePrinters(PrinterList* printer_list) = 0;
+ // Get the default printer name. Empty string if no default printer.
+ virtual std::string GetDefaultPrinterName() = 0;
+
// Gets the capabilities and defaults for a specific printer.
virtual bool GetPrinterCapsAndDefaults(
const std::string& printer_name,
diff --git a/printing/backend/print_backend_cups.cc b/printing/backend/print_backend_cups.cc
index 2e63145..9b6976c 100644
--- a/printing/backend/print_backend_cups.cc
+++ b/printing/backend/print_backend_cups.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -86,6 +86,8 @@ class PrintBackendCUPS : public PrintBackend {
// PrintBackend implementation.
virtual bool EnumeratePrinters(PrinterList* printer_list);
+ virtual std::string GetDefaultPrinterName();
+
virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info);
@@ -153,6 +155,13 @@ bool PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) {
return true;
}
+std::string PrintBackendCUPS::GetDefaultPrinterName() {
+ // TODO(thestig) Figure out why cupsGetDefault() lies about the default
+ // printer. :-(
+ // Return an empty string for now.
+ return std::string();
+}
+
bool PrintBackendCUPS::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc
index d482a91..3fb0573 100644
--- a/printing/backend/print_backend_win.cc
+++ b/printing/backend/print_backend_win.cc
@@ -42,6 +42,8 @@ class PrintBackendWin : public PrintBackend {
virtual bool EnumeratePrinters(PrinterList* printer_list);
+ virtual std::string GetDefaultPrinterName();
+
virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info);
@@ -64,19 +66,13 @@ bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) {
if (!ret)
return false;
- // Getting the name of the default printer.
- DWORD size = MAX_PATH;
- TCHAR default_printer_name[MAX_PATH];
- BOOL default_printer_exists = ::GetDefaultPrinter(
- default_printer_name, &size);
-
+ std::string default_printer = GetDefaultPrinterName();
PRINTER_INFO_2* printer_info =
reinterpret_cast<PRINTER_INFO_2*>(printer_info_buffer.get());
for (DWORD index = 0; index < count_returned; index++) {
PrinterBasicInfo info;
info.printer_name = WideToUTF8(printer_info[index].pPrinterName);
- if (default_printer_exists)
- info.is_default = (info.printer_name == WideToUTF8(default_printer_name));
+ info.is_default = (info.printer_name == default_printer);
if (printer_info[index].pComment)
info.printer_description = WideToUTF8(printer_info[index].pComment);
info.printer_status = printer_info[index].Status;
@@ -91,6 +87,14 @@ bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) {
return true;
}
+std::string PrintBackendWin::GetDefaultPrinterName() {
+ DWORD size = MAX_PATH;
+ TCHAR default_printer_name[MAX_PATH];
+ if (!::GetDefaultPrinter(default_printer_name, &size))
+ return std::string();
+ return WideToUTF8(default_printer_name);
+}
+
bool PrintBackendWin::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {