diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-17 13:59:22 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-17 13:59:22 +0000 |
commit | 43a5c2c3c442a605f843c013085f5ea60d9d49b6 (patch) | |
tree | f2cacc49af4d6a07bb4e54ab923edaae7323894c /chrome | |
parent | f1d09bf885c2516e8758875767d1199d0d4f8949 (diff) | |
download | chromium_src-43a5c2c3c442a605f843c013085f5ea60d9d49b6.zip chromium_src-43a5c2c3c442a605f843c013085f5ea60d9d49b6.tar.gz chromium_src-43a5c2c3c442a605f843c013085f5ea60d9d49b6.tar.bz2 |
Set the printer info in crash reports using the crash key logging system.
BUG=77656
R=jochen@chromium.org
Review URL: https://codereview.chromium.org/23604061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223610 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/breakpad_linux.cc | 18 | ||||
-rw-r--r-- | chrome/app/breakpad_win.cc | 26 | ||||
-rw-r--r-- | chrome/browser/printing/print_system_task_proxy.cc | 4 | ||||
-rw-r--r-- | chrome/common/child_process_logging.h | 27 | ||||
-rw-r--r-- | chrome/common/child_process_logging_mac.mm | 15 | ||||
-rw-r--r-- | chrome/common/child_process_logging_posix.cc | 16 | ||||
-rw-r--r-- | chrome/common/child_process_logging_win.cc | 19 | ||||
-rw-r--r-- | chrome/common/crash_keys.cc | 36 | ||||
-rw-r--r-- | chrome/common/crash_keys.h | 16 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_cups.cc | 10 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_win.cc | 14 | ||||
-rw-r--r-- | chrome/utility/chrome_content_utility_client.cc | 4 |
12 files changed, 68 insertions, 137 deletions
diff --git a/chrome/app/breakpad_linux.cc b/chrome/app/breakpad_linux.cc index 32c23ba..e8ae81b 100644 --- a/chrome/app/breakpad_linux.cc +++ b/chrome/app/breakpad_linux.cc @@ -1157,11 +1157,6 @@ void HandleCrashDump(const BreakpadInfo& info) { // abcdef \r\n // BOUNDARY \r\n // - // zero to 4: - // Content-Disposition: form-data; name="prn-info-1" \r\n \r\n - // abcdefghijklmnopqrstuvwxyzabcdef \r\n - // BOUNDARY \r\n - // // zero or one: // Content-Disposition: form-data; name="num-switches" \r\n \r\n // 5 \r\n @@ -1279,19 +1274,6 @@ void HandleCrashDump(const BreakpadInfo& info) { writer.Flush(); } - unsigned printer_info_len = - my_strlen(child_process_logging::g_printer_info); - if (printer_info_len) { - static const char printer_info_msg[] = "prn-info-"; - static const unsigned kMaxPrnInfoLen = - kMaxReportedPrinterRecords * child_process_logging::kPrinterInfoStrLen; - writer.AddPairDataInChunks(printer_info_msg, sizeof(printer_info_msg) - 1, - child_process_logging::g_printer_info, - std::min(printer_info_len, kMaxPrnInfoLen), - child_process_logging::kPrinterInfoStrLen, - true); - } - if (*child_process_logging::g_num_switches) { writer.AddPairString("num-switches", child_process_logging::g_num_switches); diff --git a/chrome/app/breakpad_win.cc b/chrome/app/breakpad_win.cc index f615f02..cb8a5ab 100644 --- a/chrome/app/breakpad_win.cc +++ b/chrome/app/breakpad_win.cc @@ -105,7 +105,6 @@ typedef NTSTATUS (WINAPI* NtTerminateProcessPtr)(HANDLE ProcessHandle, char* g_real_terminate_process_stub = NULL; static size_t g_client_id_offset = 0; -static size_t g_printer_info_offset = 0; static size_t g_num_switches_offset = 0; static size_t g_switches_offset = 0; static size_t g_dynamic_keys_offset = 0; @@ -458,16 +457,6 @@ google_breakpad::CustomClientInfo* GetCustomInfo(const std::wstring& exe_path, g_custom_entries->push_back(google_breakpad::CustomInfoEntry( L"special", UTF16ToWide(special_build).c_str())); - // Add empty values for the prn_info-*. We'll put the actual values when we - // collect them at this location. - g_printer_info_offset = g_custom_entries->size(); - // one-based index for the name suffix. - for (size_t i = 1; i <= kMaxReportedPrinterRecords; ++i) { - g_custom_entries->push_back( - google_breakpad::CustomInfoEntry( - base::StringPrintf(L"prn-info-%d", i).c_str(), L"")); - } - // Read the id from registry. If reporting has never been enabled // the result will be empty string. Its OK since when user enables reporting // we will insert the new value at this location. @@ -653,21 +642,6 @@ extern "C" void __declspec(dllexport) __cdecl SetClientId( google_breakpad::CustomInfoEntry::kValueMaxLength); } -extern "C" void __declspec(dllexport) __cdecl SetPrinterInfo( - const wchar_t* printer_info) { - if (!g_custom_entries) - return; - std::vector<string16> info; - base::SplitString(printer_info, L';', &info); - DCHECK_LE(info.size(), kMaxReportedPrinterRecords); - info.resize(kMaxReportedPrinterRecords); - for (size_t i = 0; i < info.size(); ++i) { - base::wcslcpy((*g_custom_entries)[g_printer_info_offset + i].value, - info[i].c_str(), - google_breakpad::CustomInfoEntry::kValueMaxLength); - } -} - // NOTE: This function is used by SyzyASAN to annotate crash reports. If you // change the name or signature of this function you will break SyzyASAN // instrumented releases of Chrome. Please contact syzygy-team@chromium.org diff --git a/chrome/browser/printing/print_system_task_proxy.cc b/chrome/browser/printing/print_system_task_proxy.cc index 0868c1d..2b8ad4e 100644 --- a/chrome/browser/printing/print_system_task_proxy.cc +++ b/chrome/browser/printing/print_system_task_proxy.cc @@ -12,7 +12,7 @@ #include "base/metrics/histogram.h" #include "base/values.h" #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" -#include "chrome/common/child_process_logging.h" +#include "chrome/common/crash_keys.h" #include "printing/backend/print_backend.h" #include "printing/print_job_constants.h" #include "printing/print_settings.h" @@ -112,7 +112,7 @@ void PrintSystemTaskProxy::SetupPrinterList(ListValue* printers) { void PrintSystemTaskProxy::GetPrinterCapabilities( const std::string& printer_name) { VLOG(1) << "Get printer capabilities start for " << printer_name; - child_process_logging::ScopedPrinterInfoSetter prn_info( + crash_keys::ScopedPrinterInfo crash_key( print_backend_->GetPrinterDriverInfo(printer_name)); if (!print_backend_->IsValidPrinter(printer_name)) { diff --git a/chrome/common/child_process_logging.h b/chrome/common/child_process_logging.h index d152499..21dbfd6 100644 --- a/chrome/common/child_process_logging.h +++ b/chrome/common/child_process_logging.h @@ -25,9 +25,6 @@ static const size_t kMaxReportedVariationChunks = 15; // limit of google_breakpad::CustomInfoEntry::kValueMaxLength. static const size_t kMaxVariationChunkSize = 64; -// The maximum number of prn-info-* records. -static const size_t kMaxReportedPrinterRecords = 4; - // The maximum number of command line switches to include in the crash // report's metadata. Note that the mini-dump itself will also contain the // (original) command line arguments within the PEB. @@ -43,15 +40,11 @@ namespace child_process_logging { extern char g_client_id[]; extern char g_num_switches[]; extern char g_num_variations[]; -extern char g_printer_info[]; extern char g_switches[]; extern char g_variation_chunks[]; // Assume command line switches are less than 64 chars. static const size_t kSwitchLen = 64; - -// Assume printer info strings are less than 64 chars. -static const size_t kPrinterInfoStrLen = 64; #endif // Sets the Client ID that is used as GUID if a Chrome process crashes. @@ -61,11 +54,6 @@ void SetClientId(const std::string& client_id); // id in |client_id| if it's known, an empty string otherwise. std::string GetClientId(); -// Sets the data on the printer to send along with crash reports. Data may be -// separated by ';' up to kMaxReportedPrinterRecords strings. Each substring -// would be cut to 63 chars. -void SetPrinterInfo(const char* printer_info); - // Sets the command line arguments to send along with crash reports to the // values in |command_line|. void SetCommandLine(const CommandLine* command_line); @@ -73,21 +61,6 @@ void SetCommandLine(const CommandLine* command_line); // Initialize the list of experiment info to send along with crash reports. void SetExperimentList(const std::vector<string16>& state); -// Set/clear information about currently accessed printer. -class ScopedPrinterInfoSetter { - public: - explicit ScopedPrinterInfoSetter(const std::string& printer_info) { - SetPrinterInfo(printer_info.c_str()); - } - - ~ScopedPrinterInfoSetter() { - SetPrinterInfo(""); - } - - private: - DISALLOW_COPY_AND_ASSIGN(ScopedPrinterInfoSetter); -}; - } // namespace child_process_logging #if defined(OS_WIN) diff --git a/chrome/common/child_process_logging_mac.mm b/chrome/common/child_process_logging_mac.mm index a6ac715..a0b03b1 100644 --- a/chrome/common/child_process_logging_mac.mm +++ b/chrome/common/child_process_logging_mac.mm @@ -23,7 +23,6 @@ using base::debug::SetCrashKeyValue; using base::debug::ClearCrashKey; const char* kGuidParamName = "guid"; -const char* kPrinterInfoNameFormat = "prn-info-%zu"; // Account for the terminating null character. static const size_t kClientIdSize = 32 + 1; @@ -49,20 +48,6 @@ std::string GetClientId() { return std::string(g_client_id); } -void SetPrinterInfo(const char* printer_info) { - std::vector<std::string> info; - base::SplitString(printer_info, ';', &info); - info.resize(kMaxReportedPrinterRecords); - for (size_t i = 0; i < info.size(); ++i) { - std::string key = base::StringPrintf(kPrinterInfoNameFormat, i); - if (!info[i].empty()) { - SetCrashKeyValue(key, info[i]); - } else { - ClearCrashKey(key); - } - } -} - void SetCommandLine(const CommandLine* command_line) { DCHECK(command_line); if (!command_line) diff --git a/chrome/common/child_process_logging_posix.cc b/chrome/common/child_process_logging_posix.cc index e0c11a0..9bbb804 100644 --- a/chrome/common/child_process_logging_posix.cc +++ b/chrome/common/child_process_logging_posix.cc @@ -23,8 +23,6 @@ static const size_t kClientIdSize = 32 + 1; // these strings to the browser. char g_client_id[kClientIdSize]; -char g_printer_info[kPrinterInfoStrLen * kMaxReportedPrinterRecords + 1] = ""; - static const size_t kNumSize = 32; char g_num_switches[kNumSize] = ""; char g_num_variations[kNumSize] = ""; @@ -53,20 +51,6 @@ std::string GetClientId() { return std::string(g_client_id); } -void SetPrinterInfo(const char* printer_info) { - std::string printer_info_str; - std::vector<std::string> info; - base::SplitString(printer_info, L';', &info); - DCHECK_LE(info.size(), kMaxReportedPrinterRecords); - for (size_t i = 0; i < info.size(); ++i) { - printer_info_str += info[i]; - // Truncate long switches, align short ones with spaces to be trimmed later. - printer_info_str.resize((i + 1) * kPrinterInfoStrLen, ' '); - } - base::strlcpy(g_printer_info, printer_info_str.c_str(), - arraysize(g_printer_info)); -} - void SetCommandLine(const CommandLine* command_line) { const CommandLine::StringVector& argv = command_line->argv(); diff --git a/chrome/common/child_process_logging_win.cc b/chrome/common/child_process_logging_win.cc index c7cd7ac..50956e2 100644 --- a/chrome/common/child_process_logging_win.cc +++ b/chrome/common/child_process_logging_win.cc @@ -23,10 +23,6 @@ namespace { typedef void (__cdecl *MainSetClientId)(const wchar_t*); // exported in breakpad_win.cc: -// void __declspec(dllexport) __cdecl SetPrinterInfo. -typedef void (__cdecl *MainSetPrinterInfo)(const wchar_t*); - -// exported in breakpad_win.cc: // void __declspec(dllexport) __cdecl SetCommandLine2 typedef void (__cdecl *MainSetCommandLine)(const wchar_t**, size_t); @@ -90,21 +86,6 @@ std::string GetClientId() { return std::string(); } -void SetPrinterInfo(const char* printer_info) { - static MainSetPrinterInfo set_printer_info = NULL; - // note: benign race condition on set_printer_info. - if (!set_printer_info) { - HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName); - if (!exe_module) - return; - set_printer_info = reinterpret_cast<MainSetPrinterInfo>( - GetProcAddress(exe_module, "SetPrinterInfo")); - if (!set_printer_info) - return; - } - (set_printer_info)(UTF8ToWide(printer_info).c_str()); -} - void SetCommandLine(const CommandLine* command_line) { static MainSetCommandLine set_command_line = NULL; // note: benign race condition on set_command_line. diff --git a/chrome/common/crash_keys.cc b/chrome/common/crash_keys.cc index 7a3e6ec..9d9f24b 100644 --- a/chrome/common/crash_keys.cc +++ b/chrome/common/crash_keys.cc @@ -6,6 +6,7 @@ #include "base/format_macros.h" #include "base/logging.h" +#include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" @@ -71,6 +72,8 @@ const char kGPURenderer[] = "gpu-gl-renderer"; const char kGPUGLVersion[] = "gpu-glver"; #endif +const char kPrinterInfo[] = "prn-info-%" PRIuS; + #if defined(OS_MACOSX) namespace mac { @@ -160,6 +163,20 @@ size_t RegisterChromeCrashKeys() { } } + // Register the printer info. + { + static char formatted_keys[kPrinterInfoCount][sizeof(kPrinterInfo) + 1] = + {{ 0 }}; + const size_t formatted_key_len = sizeof(formatted_keys[0]); + for (size_t i = 1; i <= kPrinterInfoCount; ++i) { + int n = base::snprintf( + formatted_keys[i], formatted_key_len, kPrinterInfo, i); + DCHECK_GT(n, 0); + base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize }; + keys.push_back(crash_key); + } + } + return base::debug::InitCrashKeys(&keys.at(0), keys.size(), kSingleChunkLength); } @@ -180,4 +197,23 @@ void SetActiveExtensions(const std::set<std::string>& extensions) { } } +ScopedPrinterInfo::ScopedPrinterInfo(const base::StringPiece& data) { + std::vector<std::string> info; + base::SplitString(data.as_string(), ';', &info); + for (size_t i = 1; i <= kPrinterInfoCount; ++i) { + std::string key = base::StringPrintf(kPrinterInfo, i); + std::string value; + if (i < info.size()) + value = info[i]; + base::debug::SetCrashKeyValue(key, value); + } +} + +ScopedPrinterInfo::~ScopedPrinterInfo() { + for (size_t i = 1; i <= kPrinterInfoCount; ++i) { + std::string key = base::StringPrintf(kPrinterInfo, i); + base::debug::ClearCrashKey(key); + } +} + } // namespace crash_keys diff --git a/chrome/common/crash_keys.h b/chrome/common/crash_keys.h index 75d34eb..22d5374 100644 --- a/chrome/common/crash_keys.h +++ b/chrome/common/crash_keys.h @@ -24,6 +24,17 @@ size_t RegisterChromeCrashKeys(); // multiple because of process collapsing). void SetActiveExtensions(const std::set<std::string>& extensions); +// Sets the printer info. Data should be separated by ';' up to +// kPrinterInfoCount substrings. Each substring will be truncated if necessary. +class ScopedPrinterInfo { + public: + explicit ScopedPrinterInfo(const base::StringPiece& data); + ~ScopedPrinterInfo(); + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedPrinterInfo); +}; + // Crash Key Name Constants //////////////////////////////////////////////////// // The product release/distribution channel. @@ -59,6 +70,11 @@ extern const char kGPURenderer[]; extern const char kGPUGLVersion[]; #endif +// The user's printers, up to kPrinterInfoCount. Should be set with +// ScopedPrinterInfo. +const size_t kPrinterInfoCount = 4; +extern const char kPrinterInfo[]; + #if defined(OS_MACOSX) namespace mac { diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc index 0d8f270..18c4d4c 100644 --- a/chrome/service/cloud_print/print_system_cups.cc +++ b/chrome/service/cloud_print/print_system_cups.cc @@ -25,8 +25,8 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" -#include "chrome/common/child_process_logging.h" #include "chrome/common/cloud_print/cloud_print_constants.h" +#include "chrome/common/crash_keys.h" #include "chrome/service/cloud_print/cloud_print_helpers.h" #include "grit/generated_resources.h" #include "printing/backend/cups_helper.h" @@ -264,7 +264,7 @@ class PrinterWatcherCUPS PrintSystem::PrinterWatcher::Delegate* delegate) OVERRIDE{ scoped_refptr<printing::PrintBackend> print_backend( printing::PrintBackend::CreateInstance(NULL)); - child_process_logging::ScopedPrinterInfoSetter prn_info( + crash_keys::ScopedPrinterInfo crash_key( print_backend->GetPrinterDriverInfo(printer_name_)); if (delegate_ != NULL) StopWatching(); @@ -595,7 +595,7 @@ bool PrintSystemCUPS::GetPrinterCapsAndDefaults( } // TODO(gene): Retry multiple times in case of error. - child_process_logging::ScopedPrinterInfoSetter prn_info( + crash_keys::ScopedPrinterInfo crash_key( server_info->backend->GetPrinterDriverInfo(short_printer_name)); if (!server_info->backend->GetPrinterCapsAndDefaults(short_printer_name, printer_info) ) { @@ -618,7 +618,7 @@ bool PrintSystemCUPS::GetJobDetails(const std::string& printer_name, if (!server_info) return false; - child_process_logging::ScopedPrinterInfoSetter prn_info( + crash_keys::ScopedPrinterInfo crash_key( server_info->backend->GetPrinterDriverInfo(short_printer_name)); cups_job_t* jobs = NULL; int num_jobs = GetJobs(&jobs, server_info->url, cups_encryption_, @@ -778,7 +778,7 @@ PlatformJobId PrintSystemCUPS::SpoolPrintJob( if (!server_info) return false; - child_process_logging::ScopedPrinterInfoSetter prn_info( + crash_keys::ScopedPrinterInfo crash_key( server_info->backend->GetPrinterDriverInfo(printer_name)); // We need to store options as char* string for the duration of the diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc index e70e398b..6d4fa9a 100644 --- a/chrome/service/cloud_print/print_system_win.cc +++ b/chrome/service/cloud_print/print_system_win.cc @@ -18,7 +18,7 @@ #include "base/win/scoped_com_initializer.h" #include "base/win/scoped_comptr.h" #include "base/win/scoped_hdc.h" -#include "chrome/common/child_process_logging.h" +#include "chrome/common/crash_keys.h" #include "chrome/service/service_process.h" #include "chrome/service/service_utility_process_host.h" #include "grit/generated_resources.h" @@ -170,7 +170,7 @@ class PrintSystemWatcherWin : public base::win::ObjectWatcher::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_); + crash_keys::ScopedPrinterInfo crash_key(printer_info_); delegate_ = delegate; // An empty printer name means watch the current server, we need to pass @@ -203,7 +203,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_); + crash_keys::ScopedPrinterInfo crash_key(printer_info_); DWORD change = 0; FindNextPrinterChangeNotification(object, &change, NULL, NULL); @@ -370,7 +370,7 @@ class PrintSystemWin : public PrintSystem { // TODO(gene): add tags handling. scoped_refptr<printing::PrintBackend> print_backend( printing::PrintBackend::CreateInstance(NULL)); - child_process_logging::ScopedPrinterInfoSetter prn_info( + crash_keys::ScopedPrinterInfo crash_key( print_backend->GetPrinterDriverInfo(printer_name)); return core_->Spool(print_ticket, print_data_file_path, print_data_mime_type, printer_name, job_title, @@ -403,7 +403,7 @@ class PrintSystemWin : public PrintSystem { JobSpooler::Delegate* delegate) { scoped_refptr<printing::PrintBackend> print_backend( printing::PrintBackend::CreateInstance(NULL)); - child_process_logging::ScopedPrinterInfoSetter prn_info( + crash_keys::ScopedPrinterInfo crash_key( print_backend->GetPrinterDriverInfo(printer_name)); if (delegate_) { // We are already in the process of printing. @@ -792,7 +792,7 @@ 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( + crash_keys::ScopedPrinterInfo crash_key( print_backend_->GetPrinterDriverInfo(printer_name)); printing::ScopedXPSInitializer xps_initializer; if (!xps_initializer.initialized()) { @@ -833,7 +833,7 @@ bool PrintSystemWin::ValidatePrintTicket( bool PrintSystemWin::GetJobDetails(const std::string& printer_name, PlatformJobId job_id, PrintJobDetails *job_details) { - child_process_logging::ScopedPrinterInfoSetter prn_info( + crash_keys::ScopedPrinterInfo crash_key( print_backend_->GetPrinterDriverInfo(printer_name)); DCHECK(job_details); printing::ScopedPrinterHandle printer_handle; diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc index a753d6f..b8f83f0 100644 --- a/chrome/utility/chrome_content_utility_client.cc +++ b/chrome/utility/chrome_content_utility_client.cc @@ -54,7 +54,7 @@ #endif // defined(OS_WIN) || defined(OS_MACOSX) #if defined(ENABLE_FULL_PRINTING) -#include "chrome/common/child_process_logging.h" +#include "chrome/common/crash_keys.h" #include "printing/backend/print_backend.h" #endif @@ -504,7 +504,7 @@ void ChromeContentUtilityClient::OnGetPrinterCapsAndDefaults( printing::PrintBackend::CreateInstance(NULL); printing::PrinterCapsAndDefaults printer_info; - child_process_logging::ScopedPrinterInfoSetter prn_info( + crash_keys::ScopedPrinterInfo crash_key( print_backend->GetPrinterDriverInfo(printer_name)); if (print_backend->GetPrinterCapsAndDefaults(printer_name, &printer_info)) { |