diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-16 08:54:57 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-16 08:54:57 +0000 |
commit | 4f9dd83ebff74183730af6c0f1b4b8f67703b06e (patch) | |
tree | 7b1df04c06c6970d4efbeef20d6f877f27c454de | |
parent | 4b6ebd93159d5b4f1ea9151ab59fefaf7db725cb (diff) | |
download | chromium_src-4f9dd83ebff74183730af6c0f1b4b8f67703b06e.zip chromium_src-4f9dd83ebff74183730af6c0f1b4b8f67703b06e.tar.gz chromium_src-4f9dd83ebff74183730af6c0f1b4b8f67703b06e.tar.bz2 |
ScopedPrinterInfoSetter sets printer related information to be available for breakpad. This CL inserts ScopedPrinterInfoSetter in places where Cloud print accesses printers and crash is possible.
BUG=108194
TEST=none
Review URL: http://codereview.chromium.org/9693064
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127131 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/printing/print_system_task_proxy.cc | 3 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_cups.cc | 22 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_win.cc | 20 | ||||
-rw-r--r-- | chrome/utility/chrome_content_utility_client.cc | 5 | ||||
-rw-r--r-- | printing/backend/print_backend.h | 5 | ||||
-rw-r--r-- | printing/backend/print_backend_chromeos.cc | 7 | ||||
-rw-r--r-- | printing/backend/print_backend_cups.cc | 27 | ||||
-rw-r--r-- | printing/backend/print_backend_win.cc | 15 |
8 files changed, 78 insertions, 26 deletions
diff --git a/chrome/browser/printing/print_system_task_proxy.cc b/chrome/browser/printing/print_system_task_proxy.cc index 7386a6c..38c6c26 100644 --- a/chrome/browser/printing/print_system_task_proxy.cc +++ b/chrome/browser/printing/print_system_task_proxy.cc @@ -16,6 +16,7 @@ #include "base/values.h" #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" +#include "chrome/common/child_process_logging.h" #include "printing/backend/print_backend.h" #include "printing/print_job_constants.h" #include "printing/print_settings.h" @@ -518,6 +519,8 @@ void PrintSystemTaskProxy::GetPrinterCapabilitiesWin( void PrintSystemTaskProxy::GetPrinterCapabilities( const std::string& printer_name) { VLOG(1) << "Get printer capabilities start for " << printer_name; + child_process_logging::ScopedPrinterInfoSetter prn_info( + print_backend_->GetPrinterDriverInfo(printer_name)); printing::PrinterCapsAndDefaults printer_info; if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, &printer_info)) { diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc index e7fe1f8..e3440c7 100644 --- a/chrome/service/cloud_print/print_system_cups.cc +++ b/chrome/service/cloud_print/print_system_cups.cc @@ -25,6 +25,7 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/common/child_process_logging.h" #include "chrome/service/cloud_print/cloud_print_consts.h" #include "chrome/service/cloud_print/cloud_print_helpers.h" #include "googleurl/src/gurl.h" @@ -240,8 +241,8 @@ class PrinterWatcherCUPS PrinterWatcherCUPS(PrintSystemCUPS* print_system, const std::string& printer_name) : printer_name_(printer_name), - delegate_(NULL), - print_system_(print_system) { + delegate_(NULL), + print_system_(print_system) { } ~PrinterWatcherCUPS() { @@ -251,6 +252,10 @@ class PrinterWatcherCUPS // PrintSystem::PrinterWatcher implementation. virtual bool StartWatching( PrintSystem::PrinterWatcher::Delegate* delegate) OVERRIDE{ + scoped_refptr<printing::PrintBackend> print_backend( + printing::PrintBackend::CreateInstance(NULL)); + child_process_logging::ScopedPrinterInfoSetter prn_info( + print_backend->GetPrinterDriverInfo(printer_name_)); if (delegate_ != NULL) StopWatching(); delegate_ = delegate; @@ -340,7 +345,6 @@ class PrinterWatcherCUPS return base::MD5String(to_hash); } - std::string printer_name_; PrintSystem::PrinterWatcher::Delegate* delegate_; scoped_refptr<PrintSystemCUPS> print_system_; @@ -512,8 +516,9 @@ bool PrintSystemCUPS::ValidatePrintTicket(const std::string& printer_name, } // Print ticket on linux is a JSON string containing only one dictionary. -bool PrintSystemCUPS::ParsePrintTicket(const std::string& print_ticket, - std::map<std::string, std::string>* options) { +bool PrintSystemCUPS::ParsePrintTicket( + const std::string& print_ticket, + std::map<std::string, std::string>* options) { DCHECK(options); scoped_ptr<Value> ticket_value(base::JSONReader::Read(print_ticket, false)); if (ticket_value == NULL || !ticket_value->IsType(Value::TYPE_DICTIONARY)) @@ -552,6 +557,8 @@ bool PrintSystemCUPS::GetPrinterCapsAndDefaults( } // TODO(gene): Retry multiple times in case of error. + child_process_logging::ScopedPrinterInfoSetter prn_info( + server_info->backend->GetPrinterDriverInfo(short_printer_name)); if (!server_info->backend->GetPrinterCapsAndDefaults(short_printer_name, printer_info) ) { return false; @@ -573,6 +580,8 @@ bool PrintSystemCUPS::GetJobDetails(const std::string& printer_name, if (!server_info) return false; + child_process_logging::ScopedPrinterInfoSetter prn_info( + server_info->backend->GetPrinterDriverInfo(short_printer_name)); cups_job_t* jobs = NULL; int num_jobs = GetJobs(&jobs, server_info->url, short_printer_name.c_str(), 1, -1); @@ -738,6 +747,9 @@ PlatformJobId PrintSystemCUPS::SpoolPrintJob( if (!server_info) return false; + child_process_logging::ScopedPrinterInfoSetter prn_info( + server_info->backend->GetPrinterDriverInfo(printer_name)); + // We need to store options as char* string for the duration of the // cupsPrintFile2 call. We'll use map here to store options, since // Dictionary value from JSON parser returns wchat_t. diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc index 6b1d5df..048a3ab 100644 --- a/chrome/service/cloud_print/print_system_win.cc +++ b/chrome/service/cloud_print/print_system_win.cc @@ -17,6 +17,7 @@ #include "base/win/scoped_bstr.h" #include "base/win/scoped_comptr.h" #include "base/win/scoped_hdc.h" +#include "chrome/common/child_process_logging.h" #include "chrome/service/service_process.h" #include "chrome/service/service_utility_process_host.h" #include "grit/generated_resources.h" @@ -162,6 +163,11 @@ class PrintSystemWatcherWin : public base::win::ObjectWatcher::Delegate { }; bool Start(const std::string& printer_name, Delegate* delegate) { + scoped_refptr<printing::PrintBackend> print_backend( + printing::PrintBackend::CreateInstance(NULL)); + printer_info_ = print_backend->GetPrinterDriverInfo(printer_name); + child_process_logging::ScopedPrinterInfoSetter prn_info(printer_info_); + delegate_ = delegate; // An empty printer name means watch the current server, we need to pass // NULL to OpenPrinter. @@ -194,6 +200,7 @@ class PrintSystemWatcherWin : public base::win::ObjectWatcher::Delegate { // base::ObjectWatcher::Delegate method virtual void OnObjectSignaled(HANDLE object) { + child_process_logging::ScopedPrinterInfoSetter prn_info(printer_info_); DWORD change = 0; FindNextPrinterChangeNotification(object, &change, NULL, NULL); @@ -254,6 +261,7 @@ class PrintSystemWatcherWin : public base::win::ObjectWatcher::Delegate { ScopedPrinterChangeHandle printer_change_; Delegate* delegate_; // Delegate to notify bool did_signal_; // DoneWaiting was called + std::string printer_info_; // For crash reporting. }; // This typedef is to workaround the issue with certain versions of @@ -377,6 +385,10 @@ class PrintSystemWin : public PrintSystem { const std::vector<std::string>& tags, JobSpooler::Delegate* delegate) OVERRIDE { // TODO(gene): add tags handling. + scoped_refptr<printing::PrintBackend> print_backend( + printing::PrintBackend::CreateInstance(NULL)); + child_process_logging::ScopedPrinterInfoSetter prn_info( + print_backend->GetPrinterDriverInfo(printer_name)); return core_->Spool(print_ticket, print_data_file_path, print_data_mime_type, printer_name, job_title, delegate); @@ -404,6 +416,10 @@ class PrintSystemWin : public PrintSystem { const std::string& printer_name, const std::string& job_title, JobSpooler::Delegate* delegate) { + scoped_refptr<printing::PrintBackend> print_backend( + printing::PrintBackend::CreateInstance(NULL)); + child_process_logging::ScopedPrinterInfoSetter prn_info( + print_backend->GetPrinterDriverInfo(printer_name)); if (delegate_) { // We are already in the process of printing. NOTREACHED(); @@ -780,6 +796,8 @@ bool PrintSystemWin::IsValidPrinter(const std::string& printer_name) { bool PrintSystemWin::ValidatePrintTicket( const std::string& printer_name, const std::string& print_ticket_data) { + child_process_logging::ScopedPrinterInfoSetter prn_info( + print_backend_->GetPrinterDriverInfo(printer_name)); printing::ScopedXPSInitializer xps_initializer; if (!xps_initializer.initialized()) { // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) @@ -819,6 +837,8 @@ bool PrintSystemWin::ValidatePrintTicket( bool PrintSystemWin::GetJobDetails(const std::string& printer_name, PlatformJobId job_id, PrintJobDetails *job_details) { + child_process_logging::ScopedPrinterInfoSetter prn_info( + print_backend_->GetPrinterDriverInfo(printer_name)); DCHECK(job_details); printing::ScopedPrinterHandle printer_handle; std::wstring printer_name_wide = UTF8ToWide(printer_name); diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc index b360b61..4e8bb38 100644 --- a/chrome/utility/chrome_content_utility_client.cc +++ b/chrome/utility/chrome_content_utility_client.cc @@ -12,6 +12,7 @@ #include "chrome/browser/importer/external_process_importer_bridge.h" #include "chrome/browser/importer/importer.h" #include "chrome/browser/importer/profile_import_process_messages.h" +#include "chrome/common/child_process_logging.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_utility_messages.h" #include "chrome/common/extensions/extension.h" @@ -372,6 +373,10 @@ void ChromeContentUtilityClient::OnGetPrinterCapsAndDefaults( scoped_refptr<printing::PrintBackend> print_backend = printing::PrintBackend::CreateInstance(NULL); printing::PrinterCapsAndDefaults printer_info; + + child_process_logging::ScopedPrinterInfoSetter prn_info( + print_backend->GetPrinterDriverInfo(printer_name)); + if (print_backend->GetPrinterCapsAndDefaults(printer_name, &printer_info)) { Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded( printer_name, printer_info)); diff --git a/printing/backend/print_backend.h b/printing/backend/print_backend.h index 59b16aa..8e28b2d 100644 --- a/printing/backend/print_backend.h +++ b/printing/backend/print_backend.h @@ -67,9 +67,8 @@ class PRINTING_EXPORT PrintBackend PrinterCapsAndDefaults* printer_info) = 0; // Gets the information about driver for a specific printer. - virtual bool GetPrinterDriverInfo( - const std::string& printer_name, - std::string* driver_info) = 0; + virtual std::string GetPrinterDriverInfo( + const std::string& printer_name) = 0; // Returns true if printer_name points to a valid printer. virtual bool IsValidPrinter(const std::string& printer_name) = 0; diff --git a/printing/backend/print_backend_chromeos.cc b/printing/backend/print_backend_chromeos.cc index b06683e..a70516c 100644 --- a/printing/backend/print_backend_chromeos.cc +++ b/printing/backend/print_backend_chromeos.cc @@ -22,8 +22,7 @@ class PrintBackendChromeOS : public PrintBackend { virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name, PrinterCapsAndDefaults* printer_info); - virtual bool GetPrinterDriverInfo(const std::string& printer_name, - std::string* driver_info); + virtual std::string GetPrinterDriverInfo(const std::string& printer_name); virtual bool IsValidPrinter(const std::string& printer_name); @@ -45,8 +44,8 @@ bool PrintBackendChromeOS::GetPrinterCapsAndDefaults( return false; } -bool PrintBackendChromeOS::GetPrinterDriverInfo(const std::string& printer_name, - std::string* driver_info) { +std::string PrintBackendChromeOS::GetPrinterDriverInfo( + const std::string& printer_name) { NOTREACHED(); return false; } diff --git a/printing/backend/print_backend_cups.cc b/printing/backend/print_backend_cups.cc index 9a17ddf..c14af03 100644 --- a/printing/backend/print_backend_cups.cc +++ b/printing/backend/print_backend_cups.cc @@ -98,6 +98,7 @@ namespace printing { static const char kCUPSPrinterInfoOpt[] = "printer-info"; static const char kCUPSPrinterStateOpt[] = "printer-state"; static const char kCUPSPrinterTypeOpt[] = "printer-type"; +static const char kCUPSPrinterMakeModelOpt[] = "printer-make-and-model"; class PrintBackendCUPS : public PrintBackend { public: @@ -113,8 +114,8 @@ class PrintBackendCUPS : public PrintBackend { const std::string& printer_name, PrinterCapsAndDefaults* printer_info) OVERRIDE; - virtual bool GetPrinterDriverInfo(const std::string& printer_name, - std::string* driver_info) OVERRIDE; + virtual std::string GetPrinterDriverInfo( + const std::string& printer_name) OVERRIDE; virtual bool IsValidPrinter(const std::string& printer_name) OVERRIDE; @@ -228,10 +229,24 @@ bool PrintBackendCUPS::GetPrinterCapsAndDefaults( return res; } -bool PrintBackendCUPS::GetPrinterDriverInfo(const std::string& printer_name, - std::string* driver_info) { - // TODO(vitalybuka): MAC implementation. http://crbug.com/108194 - return false; +std::string PrintBackendCUPS::GetPrinterDriverInfo( + const std::string& printer_name) { + cups_dest_t* destinations = NULL; + int num_dests = GetDests(&destinations); + std::string result; + for (int printer_index = 0; printer_index < num_dests; printer_index++) { + const cups_dest_t& printer = destinations[printer_index]; + if (printer_name == printer.name) { + const char* info = cupsGetOption(kCUPSPrinterMakeModelOpt, + printer.num_options, + printer.options); + if (info) + result = *info; + } + } + + cupsFreeDests(num_dests, destinations); + return result; } bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) { diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc index 9e3c98e..30da70e 100644 --- a/printing/backend/print_backend_win.cc +++ b/printing/backend/print_backend_win.cc @@ -50,8 +50,7 @@ class PrintBackendWin : public PrintBackend { virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name, PrinterCapsAndDefaults* printer_info); - virtual bool GetPrinterDriverInfo(const std::string& printer_name, - std::string* driver_info); + virtual std::string GetPrinterDriverInfo(const std::string& printer_name); virtual bool IsValidPrinter(const std::string& printer_name); }; @@ -178,9 +177,9 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults( } // Gets the information about driver for a specific printer. -bool PrintBackendWin::GetPrinterDriverInfo(const std::string& printer_name, - std::string* driver_info) { - DCHECK(driver_info); +std::string PrintBackendWin::GetPrinterDriverInfo( + const std::string& printer_name) { + std::string driver_info; ScopedPrinterHandle printer_handle; if (!::OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()), printer_handle.Receive(), NULL)) { @@ -217,11 +216,11 @@ bool PrintBackendWin::GetPrinterDriverInfo(const std::string& printer_name, for (size_t i = 0; i < arraysize(info); ++i) { std::replace(info[i].begin(), info[i].end(), ';', ','); - driver_info->append(info[i]); - driver_info->append(";"); + driver_info.append(info[i]); + driver_info.append(";"); } - return true; + return driver_info; } bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) { |