diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-24 23:47:41 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-24 23:47:41 +0000 |
commit | 402197a5a7eb74fbc1fe9317abe94b1812af5c92 (patch) | |
tree | 2a38f1ba579d385eeacce4adbb52fbe52f2678c8 /printing | |
parent | 2c81bcd1677ef4237c84462cbf2c5ff02301a46f (diff) | |
download | chromium_src-402197a5a7eb74fbc1fe9317abe94b1812af5c92.zip chromium_src-402197a5a7eb74fbc1fe9317abe94b1812af5c92.tar.gz chromium_src-402197a5a7eb74fbc1fe9317abe94b1812af5c92.tar.bz2 |
Added a diagnostic user message when enumerating printers fails. Also tweaked some of the strings.
BUG=None
TEST=Test Cloud Print Proxy.
Review URL: http://codereview.chromium.org/6356007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72422 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/backend/print_backend.h | 2 | ||||
-rw-r--r-- | printing/backend/print_backend_cups.cc | 7 | ||||
-rw-r--r-- | printing/backend/print_backend_win.cc | 52 |
3 files changed, 34 insertions, 27 deletions
diff --git a/printing/backend/print_backend.h b/printing/backend/print_backend.h index 3b55268..63c00c9 100644 --- a/printing/backend/print_backend.h +++ b/printing/backend/print_backend.h @@ -48,7 +48,7 @@ class PrintBackend : public base::RefCountedThreadSafe<PrintBackend> { virtual ~PrintBackend(); // Enumerates the list of installed local and network printers. - virtual void EnumeratePrinters(PrinterList* printer_list) = 0; + virtual bool EnumeratePrinters(PrinterList* printer_list) = 0; // Gets the capabilities and defaults for a specific printer. virtual bool GetPrinterCapsAndDefaults( diff --git a/printing/backend/print_backend_cups.cc b/printing/backend/print_backend_cups.cc index 01aa18d..3b38c3f 100644 --- a/printing/backend/print_backend_cups.cc +++ b/printing/backend/print_backend_cups.cc @@ -84,7 +84,7 @@ class PrintBackendCUPS : public PrintBackend { virtual ~PrintBackendCUPS() {} // PrintBackend implementation. - virtual void EnumeratePrinters(PrinterList* printer_list); + virtual bool EnumeratePrinters(PrinterList* printer_list); virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name, PrinterCapsAndDefaults* printer_info); @@ -107,12 +107,14 @@ PrintBackendCUPS::PrintBackendCUPS(const GURL& print_server_url, bool blocking) : print_server_url_(print_server_url), blocking_(blocking) { } -void PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) { +bool PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) { DCHECK(printer_list); printer_list->clear(); cups_dest_t* destinations = NULL; int num_dests = GetDests(&destinations); + // TODO(gene): Figure out how to get an error code from cupsGetDests so we can + // differentiate between the enumeration failing and there being 0 printers. for (int printer_index = 0; printer_index < num_dests; printer_index++) { const cups_dest_t& printer = destinations[printer_index]; @@ -142,6 +144,7 @@ void PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) { cupsFreeDests(num_dests, destinations); VLOG(1) << "CUPS: Enumerated " << printer_list->size() << " printers."; + return true; } bool PrintBackendCUPS::GetPrinterCapsAndDefaults( diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc index 41d9ee3..3b7608c 100644 --- a/printing/backend/print_backend_win.cc +++ b/printing/backend/print_backend_win.cc @@ -43,7 +43,7 @@ class PrintBackendWin : public PrintBackend { PrintBackendWin() {} virtual ~PrintBackendWin() {} - virtual void EnumeratePrinters(PrinterList* printer_list); + virtual bool EnumeratePrinters(PrinterList* printer_list); virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name, PrinterCapsAndDefaults* printer_info); @@ -51,35 +51,39 @@ class PrintBackendWin : public PrintBackend { virtual bool IsValidPrinter(const std::string& printer_name); }; -void PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) { +bool PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) { DCHECK(printer_list); DWORD bytes_needed = 0; DWORD count_returned = 0; BOOL ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &bytes_needed, &count_returned); - if (0 != bytes_needed) { - scoped_ptr<BYTE> printer_info_buffer(new BYTE[bytes_needed]); - ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, - printer_info_buffer.get(), bytes_needed, &bytes_needed, - &count_returned); - DCHECK(ret); - 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 (printer_info[index].pComment) - info.printer_description = WideToUTF8(printer_info[index].pComment); - info.printer_status = printer_info[index].Status; - if (printer_info[index].pLocation) - info.options[kLocationTagName] = - WideToUTF8(printer_info[index].pLocation); - if (printer_info[index].pDriverName) - info.options[kDriverNameTagName] = - WideToUTF8(printer_info[index].pDriverName); - printer_list->push_back(info); - } + if (!bytes_needed) + return false; + scoped_ptr<BYTE> printer_info_buffer(new BYTE[bytes_needed]); + ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, + printer_info_buffer.get(), bytes_needed, &bytes_needed, + &count_returned); + DCHECK(ret); + if (!ret) + return false; + + 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 (printer_info[index].pComment) + info.printer_description = WideToUTF8(printer_info[index].pComment); + info.printer_status = printer_info[index].Status; + if (printer_info[index].pLocation) + info.options[kLocationTagName] = + WideToUTF8(printer_info[index].pLocation); + if (printer_info[index].pDriverName) + info.options[kDriverNameTagName] = + WideToUTF8(printer_info[index].pDriverName); + printer_list->push_back(info); } + return true; } bool PrintBackendWin::GetPrinterCapsAndDefaults( |