Added SetPrinterInfo to include information about printer driver. This...

Added SetPrinterInfo to include information about printer driver. This information will be added by Chrome (in different CL) just before performing error-prone printer related operations.

BUG=108194
TEST=none

Review URL: http://codereview.chromium.org/9600060

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126866 0039d316-1c4b-4281-b951-d872f2087c98
parent ebb7c1fd
...@@ -574,6 +574,19 @@ void HandleCrashDump(const BreakpadInfo& info) { ...@@ -574,6 +574,19 @@ void HandleCrashDump(const BreakpadInfo& info) {
false /* Don't strip whitespace. */); false /* Don't strip whitespace. */);
} }
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 (my_strlen(child_process_logging::g_num_switches)) { if (my_strlen(child_process_logging::g_num_switches)) {
writer.AddPairString("num-switches", writer.AddPairString("num-switches",
child_process_logging::g_num_switches); child_process_logging::g_num_switches);
......
...@@ -74,6 +74,7 @@ static size_t g_num_of_extensions_offset; ...@@ -74,6 +74,7 @@ static size_t g_num_of_extensions_offset;
static size_t g_extension_ids_offset; static size_t g_extension_ids_offset;
static size_t g_client_id_offset; static size_t g_client_id_offset;
static size_t g_gpu_info_offset; static size_t g_gpu_info_offset;
static size_t g_printer_info_offset;
static size_t g_num_of_views_offset; static size_t g_num_of_views_offset;
static size_t g_num_switches_offset; static size_t g_num_switches_offset;
static size_t g_switches_offset; static size_t g_switches_offset;
...@@ -257,19 +258,29 @@ google_breakpad::CustomClientInfo* GetCustomInfo(const std::wstring& exe_path, ...@@ -257,19 +258,29 @@ google_breakpad::CustomClientInfo* GetCustomInfo(const std::wstring& exe_path,
base::StringPrintf(L"extension-%i", i + 1).c_str(), L"")); base::StringPrintf(L"extension-%i", i + 1).c_str(), L""));
} }
// Add empty values for the gpu_info. We'll put the actual values // Add empty values for the gpu_info. We'll put the actual values when we
// when we collect them at this location. // collect them at this location.
g_gpu_info_offset = g_custom_entries->size(); g_gpu_info_offset = g_custom_entries->size();
g_custom_entries->push_back( static const wchar_t* const kGpuEntries[] = {
google_breakpad::CustomInfoEntry(L"gpu-venid", L"")); L"gpu-venid",
g_custom_entries->push_back( L"gpu-devid",
google_breakpad::CustomInfoEntry(L"gpu-devid", L"")); L"gpu-driver",
g_custom_entries->push_back( L"gpu-psver",
google_breakpad::CustomInfoEntry(L"gpu-driver", L"")); L"gpu-vsver",
g_custom_entries->push_back( };
google_breakpad::CustomInfoEntry(L"gpu-psver", L"")); for (size_t i = 0; i < arraysize(kGpuEntries); ++i) {
g_custom_entries->push_back( g_custom_entries->push_back(
google_breakpad::CustomInfoEntry(L"gpu-vsver", L"")); google_breakpad::CustomInfoEntry(kGpuEntries[i], L""));
}
// 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();
for (size_t i = 0; i < kMaxReportedPrinterRecords; ++i) {
g_custom_entries->push_back(
google_breakpad::CustomInfoEntry(
base::StringPrintf(L"prn-info-%d", i + 1).c_str(), L""));
}
// Read the id from registry. If reporting has never been enabled // Read the id from registry. If reporting has never been enabled
// the result will be empty string. Its OK since when user enables reporting // the result will be empty string. Its OK since when user enables reporting
...@@ -487,21 +498,34 @@ extern "C" void __declspec(dllexport) __cdecl SetGpuInfo( ...@@ -487,21 +498,34 @@ extern "C" void __declspec(dllexport) __cdecl SetGpuInfo(
if (!g_custom_entries) if (!g_custom_entries)
return; return;
base::wcslcpy((*g_custom_entries)[g_gpu_info_offset].value, const wchar_t* info[] = {
vendor_id, vendor_id,
google_breakpad::CustomInfoEntry::kValueMaxLength); device_id,
base::wcslcpy((*g_custom_entries)[g_gpu_info_offset+1].value, driver_version,
device_id, pixel_shader_version,
google_breakpad::CustomInfoEntry::kValueMaxLength); vertex_shader_version
base::wcslcpy((*g_custom_entries)[g_gpu_info_offset+2].value, };
driver_version,
google_breakpad::CustomInfoEntry::kValueMaxLength); for (size_t i = 0; i < arraysize(info); ++i) {
base::wcslcpy((*g_custom_entries)[g_gpu_info_offset+3].value, base::wcslcpy((*g_custom_entries)[g_gpu_info_offset + i].value,
pixel_shader_version, info[i],
google_breakpad::CustomInfoEntry::kValueMaxLength); google_breakpad::CustomInfoEntry::kValueMaxLength);
base::wcslcpy((*g_custom_entries)[g_gpu_info_offset+4].value, }
vertex_shader_version, }
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); google_breakpad::CustomInfoEntry::kValueMaxLength);
}
} }
extern "C" void __declspec(dllexport) __cdecl SetNumberOfViews( extern "C" void __declspec(dllexport) __cdecl SetNumberOfViews(
......
...@@ -24,6 +24,9 @@ struct GPUInfo; ...@@ -24,6 +24,9 @@ struct GPUInfo;
// dependency. // dependency.
static const int kMaxReportedActiveExtensions = 10; static const int kMaxReportedActiveExtensions = 10;
// 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 // 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 // report's metadata. Note that the mini-dump itself will also contain the
// (original) command line arguments within the PEB. // (original) command line arguments within the PEB.
...@@ -48,6 +51,7 @@ extern char g_gpu_vs_ver[]; ...@@ -48,6 +51,7 @@ extern char g_gpu_vs_ver[];
extern char g_num_extensions[]; extern char g_num_extensions[];
extern char g_num_switches[]; extern char g_num_switches[];
extern char g_num_views[]; extern char g_num_views[];
extern char g_prn_info[];
extern char g_switches[]; extern char g_switches[];
// Assume IDs are 32 bytes long. // Assume IDs are 32 bytes long.
...@@ -55,6 +59,9 @@ static const size_t kExtensionLen = 32; ...@@ -55,6 +59,9 @@ static const size_t kExtensionLen = 32;
// Assume command line switches are less than 64 chars. // Assume command line switches are less than 64 chars.
static const size_t kSwitchLen = 64; static const size_t kSwitchLen = 64;
// Assume printer info strings are less than 64 chars.
static const size_t kPrinterInfoStrLen = 64;
#endif #endif
// Sets the URL that is logged if the child process crashes. Use GURL() to clear // Sets the URL that is logged if the child process crashes. Use GURL() to clear
...@@ -82,6 +89,11 @@ void SetNumberOfViews(int number_of_views); ...@@ -82,6 +89,11 @@ void SetNumberOfViews(int number_of_views);
// Sets the data on the gpu to send along with crash reports. // Sets the data on the gpu to send along with crash reports.
void SetGpuInfo(const content::GPUInfo& gpu_info); void SetGpuInfo(const content::GPUInfo& gpu_info);
// 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 // Sets the command line arguments to send along with crash reports to the
// values in |command_line|. // values in |command_line|.
void SetCommandLine(const CommandLine* command_line); void SetCommandLine(const CommandLine* command_line);
...@@ -107,6 +119,21 @@ class ScopedActiveURLSetter { ...@@ -107,6 +119,21 @@ class ScopedActiveURLSetter {
DISALLOW_COPY_AND_ASSIGN(ScopedActiveURLSetter); DISALLOW_COPY_AND_ASSIGN(ScopedActiveURLSetter);
}; };
// Set/clear information about currently accessed printer.
class ScopedPrinterInfoSetter {
public:
explicit ScopedPrinterInfoSetter(const char* printer_info) {
SetPrinterInfo(printer_info);
}
~ScopedPrinterInfoSetter() {
SetPrinterInfo("");
}
private:
DISALLOW_COPY_AND_ASSIGN(ScopedPrinterInfoSetter);
};
} // namespace child_process_logging } // namespace child_process_logging
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/string_split.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/sys_string_conversions.h" #include "base/sys_string_conversions.h"
...@@ -36,6 +37,7 @@ const char *kGPUGLVersionParamName = "gpu-glver"; ...@@ -36,6 +37,7 @@ const char *kGPUGLVersionParamName = "gpu-glver";
const char *kNumberOfViews = "num-views"; const char *kNumberOfViews = "num-views";
NSString* const kNumExtensionsName = @"num-extensions"; NSString* const kNumExtensionsName = @"num-extensions";
NSString* const kExtensionNameFormat = @"extension-%d"; NSString* const kExtensionNameFormat = @"extension-%d";
NSString* const kPrinterInfoNameFormat = @"prn-info-%d";
// Account for the terminating null character. // Account for the terminating null character.
static const size_t kClientIdSize = 32 + 1; static const size_t kClientIdSize = 32 + 1;
...@@ -163,6 +165,19 @@ void SetGpuInfo(const content::GPUInfo& gpu_info) { ...@@ -163,6 +165,19 @@ void SetGpuInfo(const content::GPUInfo& gpu_info) {
SetGpuInfoImpl(gpu_info, SetCrashKeyValue); SetGpuInfoImpl(gpu_info, SetCrashKeyValue);
} }
void SetPrinterInfo(const char* printer_info) {
std::vector<std::string> info;
base::SplitString(printer_info, L';', &info);
info.resize(kMaxReportedPrinterRecords);
for (size_t i = 0; i < info.size(); ++i) {
NSString* key = [NSString stringWithFormat:kPrinterInfoNameFormat, i];
ClearCrashKey(key);
if (!info[i].empty()) {
NSString *value = [NSString stringWithUTF8String:info[i].c_str()];
SetCrashKeyValue(key, value);
}
}
}
void SetNumberOfViewsImpl(int number_of_views, void SetNumberOfViewsImpl(int number_of_views,
SetCrashKeyValueFuncPtr set_key_func) { SetCrashKeyValueFuncPtr set_key_func) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/string_split.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/installer/util/google_update_settings.h" #include "chrome/installer/util/google_update_settings.h"
...@@ -29,13 +30,14 @@ char g_client_id[kClientIdSize]; ...@@ -29,13 +30,14 @@ char g_client_id[kClientIdSize];
char g_channel[kChannelSize] = ""; char g_channel[kChannelSize] = "";
static const size_t kGpuStringSize = 32; static const size_t kGpuStringSize = 32;
char g_gpu_vendor_id[kGpuStringSize] = ""; char g_gpu_vendor_id[kGpuStringSize] = "";
char g_gpu_device_id[kGpuStringSize] = ""; char g_gpu_device_id[kGpuStringSize] = "";
char g_gpu_driver_ver[kGpuStringSize] = ""; char g_gpu_driver_ver[kGpuStringSize] = "";
char g_gpu_ps_ver[kGpuStringSize] = ""; char g_gpu_ps_ver[kGpuStringSize] = "";
char g_gpu_vs_ver[kGpuStringSize] = ""; char g_gpu_vs_ver[kGpuStringSize] = "";
char g_printer_info[kPrinterInfoStrLen * kMaxReportedPrinterRecords + 1] = "";
static const size_t kNumSize = 32; static const size_t kNumSize = 32;
char g_num_extensions[kNumSize] = ""; char g_num_extensions[kNumSize] = "";
char g_num_switches[kNumSize] = ""; char g_num_switches[kNumSize] = "";
...@@ -103,6 +105,22 @@ void SetGpuInfo(const content::GPUInfo& gpu_info) { ...@@ -103,6 +105,22 @@ void SetGpuInfo(const content::GPUInfo& gpu_info) {
g_gpu_vs_ver[kGpuStringSize - 1] = '\0'; g_gpu_vs_ver[kGpuStringSize - 1] = '\0';
} }
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);
info.resize(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, ' ');
}
strncpy(g_printer_info, printer_info_str.c_str(),
arraysize(g_printer_info) - 1);
g_printer_info[arraysize(g_printer_info) - 1] = '\0';
}
void SetNumberOfViews(int number_of_views) { void SetNumberOfViews(int number_of_views) {
snprintf(g_num_views, kNumSize - 1, "%d", number_of_views); snprintf(g_num_views, kNumSize - 1, "%d", number_of_views);
g_num_views[kNumSize - 1] = '\0'; g_num_views[kNumSize - 1] = '\0';
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -36,6 +36,10 @@ typedef void (__cdecl *MainSetGpuInfo)(const wchar_t*, const wchar_t*, ...@@ -36,6 +36,10 @@ typedef void (__cdecl *MainSetGpuInfo)(const wchar_t*, const wchar_t*,
const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*,
const wchar_t*); 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: // exported in breakpad_win.cc:
// void __declspec(dllexport) __cdecl SetNumberOfViews. // void __declspec(dllexport) __cdecl SetNumberOfViews.
typedef void (__cdecl *MainSetNumberOfViews)(int); typedef void (__cdecl *MainSetNumberOfViews)(int);
...@@ -150,6 +154,20 @@ void SetGpuInfo(const content::GPUInfo& gpu_info) { ...@@ -150,6 +154,20 @@ void SetGpuInfo(const content::GPUInfo& gpu_info) {
UTF8ToUTF16(gpu_info.vertex_shader_version).c_str()); UTF8ToUTF16(gpu_info.vertex_shader_version).c_str());
} }
void SetPrinterInfo(const char* printer_info) {
static MainSetPrinterInfo set_printer_info = NULL;
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) { void SetCommandLine(const CommandLine* command_line) {
static MainSetCommandLine set_command_line = NULL; static MainSetCommandLine set_command_line = NULL;
if (!set_command_line) { if (!set_command_line) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment