| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/common/child_process_logging.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/format_macros.h" | |
| 9 #include "base/string_number_conversions.h" | |
| 10 #include "base/string_util.h" | |
| 11 #include "base/utf_string_conversions.h" | |
| 12 #include "chrome/installer/util/google_update_settings.h" | |
| 13 #include "content/public/common/gpu_info.h" | |
| 14 #include "googleurl/src/gurl.h" | |
| 15 | |
| 16 namespace child_process_logging { | |
| 17 | |
| 18 // Account for the terminating null character. | |
| 19 static const size_t kMaxActiveURLSize = 1024 + 1; | |
| 20 static const size_t kClientIdSize = 32 + 1; | |
| 21 static const size_t kChannelSize = 32; | |
| 22 | |
| 23 // 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 // these strings to the browser. | |
| 26 char g_active_url[kMaxActiveURLSize]; | |
| 27 char g_client_id[kClientIdSize]; | |
| 28 | |
| 29 char g_channel[kChannelSize] = ""; | |
| 30 | |
| 31 static const size_t kGpuStringSize = 32; | |
| 32 | |
| 33 char g_gpu_vendor_id[kGpuStringSize] = ""; | |
| 34 char g_gpu_device_id[kGpuStringSize] = ""; | |
| 35 char g_gpu_driver_ver[kGpuStringSize] = ""; | |
| 36 char g_gpu_ps_ver[kGpuStringSize] = ""; | |
| 37 char g_gpu_vs_ver[kGpuStringSize] = ""; | |
| 38 | |
| 39 static const size_t kNumSize = 32; | |
| 40 char g_num_extensions[kNumSize] = ""; | |
| 41 char g_num_switches[kNumSize] = ""; | |
| 42 char g_num_views[kNumSize] = ""; | |
| 43 | |
| 44 static const size_t kMaxExtensionSize = | |
| 45 kExtensionLen * kMaxReportedActiveExtensions + 1; | |
| 46 char g_extension_ids[kMaxExtensionSize] = ""; | |
| 47 | |
| 48 // Assume command line switches are less than 64 chars. | |
| 49 static const size_t kMaxSwitchesSize = kSwitchLen * kMaxSwitches + 1; | |
| 50 char g_switches[kMaxSwitchesSize] = ""; | |
| 51 | |
| 52 void SetActiveURL(const GURL& url) { | |
| 53 base::strlcpy(g_active_url, | |
| 54 url.possibly_invalid_spec().c_str(), | |
| 55 kMaxActiveURLSize); | |
| 56 } | |
| 57 | |
| 58 void SetClientId(const std::string& client_id) { | |
| 59 std::string str(client_id); | |
| 60 ReplaceSubstringsAfterOffset(&str, 0, "-", ""); | |
| 61 | |
| 62 if (str.empty()) | |
| 63 return; | |
| 64 | |
| 65 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); | |
| 66 std::wstring wstr = ASCIIToWide(str); | |
| 67 GoogleUpdateSettings::SetMetricsId(wstr); | |
| 68 } | |
| 69 | |
| 70 std::string GetClientId() { | |
| 71 return std::string(g_client_id); | |
| 72 } | |
| 73 | |
| 74 void SetActiveExtensions(const std::set<std::string>& extension_ids) { | |
| 75 snprintf(g_num_extensions, kNumSize - 1, "%" PRIuS, extension_ids.size()); | |
| 76 g_num_extensions[kNumSize - 1] = '\0'; | |
| 77 | |
| 78 std::string extension_str; | |
| 79 std::set<std::string>::const_iterator iter = extension_ids.begin(); | |
| 80 for (int i = 0; | |
| 81 i < kMaxReportedActiveExtensions && iter != extension_ids.end(); | |
| 82 ++i, ++iter) { | |
| 83 extension_str += *iter; | |
| 84 } | |
| 85 strncpy(g_extension_ids, extension_str.c_str(), kMaxExtensionSize - 1); | |
| 86 g_extension_ids[kMaxExtensionSize - 1] = '\0'; | |
| 87 } | |
| 88 | |
| 89 void SetGpuInfo(const content::GPUInfo& gpu_info) { | |
| 90 snprintf(g_gpu_vendor_id, kGpuStringSize, "0x%04x", gpu_info.vendor_id); | |
| 91 snprintf(g_gpu_device_id, kGpuStringSize, "0x%04x", gpu_info.device_id); | |
| 92 strncpy(g_gpu_driver_ver, | |
| 93 gpu_info.driver_version.c_str(), | |
| 94 kGpuStringSize - 1); | |
| 95 g_gpu_driver_ver[kGpuStringSize - 1] = '\0'; | |
| 96 strncpy(g_gpu_ps_ver, | |
| 97 gpu_info.pixel_shader_version.c_str(), | |
| 98 kGpuStringSize - 1); | |
| 99 g_gpu_ps_ver[kGpuStringSize - 1] = '\0'; | |
| 100 strncpy(g_gpu_vs_ver, | |
| 101 gpu_info.vertex_shader_version.c_str(), | |
| 102 kGpuStringSize - 1); | |
| 103 g_gpu_vs_ver[kGpuStringSize - 1] = '\0'; | |
| 104 } | |
| 105 | |
| 106 void SetNumberOfViews(int number_of_views) { | |
| 107 snprintf(g_num_views, kNumSize - 1, "%d", number_of_views); | |
| 108 g_num_views[kNumSize - 1] = '\0'; | |
| 109 } | |
| 110 | |
| 111 void SetCommandLine(const CommandLine* command_line) { | |
| 112 const CommandLine::StringVector& argv = command_line->argv(); | |
| 113 | |
| 114 snprintf(g_num_switches, kNumSize - 1, "%" PRIuS, argv.size() - 1); | |
| 115 g_num_switches[kNumSize - 1] = '\0'; | |
| 116 | |
| 117 std::string command_line_str; | |
| 118 for (size_t argv_i = 1; | |
| 119 argv_i < argv.size() && argv_i <= kMaxSwitches; | |
| 120 ++argv_i) { | |
| 121 command_line_str += argv[argv_i]; | |
| 122 // Truncate long switches, align short ones with spaces to be trimmed later. | |
| 123 command_line_str.resize(argv_i * kSwitchLen, ' '); | |
| 124 } | |
| 125 strncpy(g_switches, command_line_str.c_str(), kMaxSwitchesSize - 1); | |
| 126 g_switches[kMaxSwitchesSize - 1] = '\0'; | |
| 127 } | |
| 128 | |
| 129 void SetChannel(const std::string& channel) { | |
| 130 strncpy(g_channel, channel.c_str(), kChannelSize - 1); | |
| 131 g_channel[kChannelSize - 1] = '\0'; | |
| 132 } | |
| 133 | |
| 134 } // namespace child_process_logging | |
| OLD | NEW |