| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/child_process_logging.h" | 5 #include "chrome/common/child_process_logging.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_split.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/installer/util/google_update_settings.h" | 13 #include "chrome/installer/util/google_update_settings.h" |
| 13 #include "content/public/common/gpu_info.h" | 14 #include "content/public/common/gpu_info.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 | 16 |
| 16 namespace child_process_logging { | 17 namespace child_process_logging { |
| 17 | 18 |
| 18 // Account for the terminating null character. | 19 // Account for the terminating null character. |
| 19 static const size_t kMaxActiveURLSize = 1024 + 1; | 20 static const size_t kMaxActiveURLSize = 1024 + 1; |
| 20 static const size_t kClientIdSize = 32 + 1; | 21 static const size_t kClientIdSize = 32 + 1; |
| 21 static const size_t kChannelSize = 32; | 22 static const size_t kChannelSize = 32; |
| 22 | 23 |
| 23 // We use static strings to hold the most recent active url and the client | 24 // We use static strings to hold the most recent active url and the client |
| 24 // identifier. If we crash, the crash handler code will send the contents of | 25 // identifier. If we crash, the crash handler code will send the contents of |
| 25 // these strings to the browser. | 26 // these strings to the browser. |
| 26 char g_active_url[kMaxActiveURLSize]; | 27 char g_active_url[kMaxActiveURLSize]; |
| 27 char g_client_id[kClientIdSize]; | 28 char g_client_id[kClientIdSize]; |
| 28 | 29 |
| 29 char g_channel[kChannelSize] = ""; | 30 char g_channel[kChannelSize] = ""; |
| 30 | 31 |
| 31 static const size_t kGpuStringSize = 32; | 32 static const size_t kGpuStringSize = 32; |
| 32 | |
| 33 char g_gpu_vendor_id[kGpuStringSize] = ""; | 33 char g_gpu_vendor_id[kGpuStringSize] = ""; |
| 34 char g_gpu_device_id[kGpuStringSize] = ""; | 34 char g_gpu_device_id[kGpuStringSize] = ""; |
| 35 char g_gpu_driver_ver[kGpuStringSize] = ""; | 35 char g_gpu_driver_ver[kGpuStringSize] = ""; |
| 36 char g_gpu_ps_ver[kGpuStringSize] = ""; | 36 char g_gpu_ps_ver[kGpuStringSize] = ""; |
| 37 char g_gpu_vs_ver[kGpuStringSize] = ""; | 37 char g_gpu_vs_ver[kGpuStringSize] = ""; |
| 38 | 38 |
| 39 char g_printer_info[kPrinterInfoStrLen * kMaxReportedPrinterRecords + 1] = ""; |
| 40 |
| 39 static const size_t kNumSize = 32; | 41 static const size_t kNumSize = 32; |
| 40 char g_num_extensions[kNumSize] = ""; | 42 char g_num_extensions[kNumSize] = ""; |
| 41 char g_num_switches[kNumSize] = ""; | 43 char g_num_switches[kNumSize] = ""; |
| 42 char g_num_views[kNumSize] = ""; | 44 char g_num_views[kNumSize] = ""; |
| 43 | 45 |
| 44 static const size_t kMaxExtensionSize = | 46 static const size_t kMaxExtensionSize = |
| 45 kExtensionLen * kMaxReportedActiveExtensions + 1; | 47 kExtensionLen * kMaxReportedActiveExtensions + 1; |
| 46 char g_extension_ids[kMaxExtensionSize] = ""; | 48 char g_extension_ids[kMaxExtensionSize] = ""; |
| 47 | 49 |
| 48 // Assume command line switches are less than 64 chars. | 50 // Assume command line switches are less than 64 chars. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 strncpy(g_gpu_ps_ver, | 98 strncpy(g_gpu_ps_ver, |
| 97 gpu_info.pixel_shader_version.c_str(), | 99 gpu_info.pixel_shader_version.c_str(), |
| 98 kGpuStringSize - 1); | 100 kGpuStringSize - 1); |
| 99 g_gpu_ps_ver[kGpuStringSize - 1] = '\0'; | 101 g_gpu_ps_ver[kGpuStringSize - 1] = '\0'; |
| 100 strncpy(g_gpu_vs_ver, | 102 strncpy(g_gpu_vs_ver, |
| 101 gpu_info.vertex_shader_version.c_str(), | 103 gpu_info.vertex_shader_version.c_str(), |
| 102 kGpuStringSize - 1); | 104 kGpuStringSize - 1); |
| 103 g_gpu_vs_ver[kGpuStringSize - 1] = '\0'; | 105 g_gpu_vs_ver[kGpuStringSize - 1] = '\0'; |
| 104 } | 106 } |
| 105 | 107 |
| 108 void SetPrinterInfo(const char* printer_info) { |
| 109 std::string printer_info_str; |
| 110 std::vector<std::string> info; |
| 111 base::SplitString(printer_info, L';', &info); |
| 112 DCHECK_LE(info.size(), kMaxReportedPrinterRecords); |
| 113 info.resize(kMaxReportedPrinterRecords); |
| 114 for (size_t i = 0; i < info.size(); ++i) { |
| 115 printer_info_str += info[i]; |
| 116 // Truncate long switches, align short ones with spaces to be trimmed later. |
| 117 printer_info_str.resize((i + 1) * kPrinterInfoStrLen, ' '); |
| 118 } |
| 119 strncpy(g_printer_info, printer_info_str.c_str(), |
| 120 kPrinterInfoStrLen * kMaxReportedPrinterRecords); |
| 121 g_printer_info[arraysize(g_printer_info) - 1] = '\0'; |
| 122 } |
| 123 |
| 106 void SetNumberOfViews(int number_of_views) { | 124 void SetNumberOfViews(int number_of_views) { |
| 107 snprintf(g_num_views, kNumSize - 1, "%d", number_of_views); | 125 snprintf(g_num_views, kNumSize - 1, "%d", number_of_views); |
| 108 g_num_views[kNumSize - 1] = '\0'; | 126 g_num_views[kNumSize - 1] = '\0'; |
| 109 } | 127 } |
| 110 | 128 |
| 111 void SetCommandLine(const CommandLine* command_line) { | 129 void SetCommandLine(const CommandLine* command_line) { |
| 112 const CommandLine::StringVector& argv = command_line->argv(); | 130 const CommandLine::StringVector& argv = command_line->argv(); |
| 113 | 131 |
| 114 snprintf(g_num_switches, kNumSize - 1, "%" PRIuS, argv.size() - 1); | 132 snprintf(g_num_switches, kNumSize - 1, "%" PRIuS, argv.size() - 1); |
| 115 g_num_switches[kNumSize - 1] = '\0'; | 133 g_num_switches[kNumSize - 1] = '\0'; |
| 116 | 134 |
| 117 std::string command_line_str; | 135 std::string command_line_str; |
| 118 for (size_t argv_i = 1; | 136 for (size_t argv_i = 1; |
| 119 argv_i < argv.size() && argv_i <= kMaxSwitches; | 137 argv_i < argv.size() && argv_i <= kMaxSwitches; |
| 120 ++argv_i) { | 138 ++argv_i) { |
| 121 command_line_str += argv[argv_i]; | 139 command_line_str += argv[argv_i]; |
| 122 // Truncate long switches, align short ones with spaces to be trimmed later. | 140 // Truncate long switches, align short ones with spaces to be trimmed later. |
| 123 command_line_str.resize(argv_i * kSwitchLen, ' '); | 141 command_line_str.resize(argv_i * kSwitchLen, ' '); |
| 124 } | 142 } |
| 125 strncpy(g_switches, command_line_str.c_str(), kMaxSwitchesSize - 1); | 143 strncpy(g_switches, command_line_str.c_str(), kMaxSwitchesSize - 1); |
| 126 g_switches[kMaxSwitchesSize - 1] = '\0'; | 144 g_switches[kMaxSwitchesSize - 1] = '\0'; |
| 127 } | 145 } |
| 128 | 146 |
| 129 void SetChannel(const std::string& channel) { | 147 void SetChannel(const std::string& channel) { |
| 130 strncpy(g_channel, channel.c_str(), kChannelSize - 1); | 148 strncpy(g_channel, channel.c_str(), kChannelSize - 1); |
| 131 g_channel[kChannelSize - 1] = '\0'; | 149 g_channel[kChannelSize - 1] = '\0'; |
| 132 } | 150 } |
| 133 | 151 |
| 134 } // namespace child_process_logging | 152 } // namespace child_process_logging |
| OLD | NEW |