| 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_split.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/common/metrics/variations/variations_util.h" |
| 13 #include "chrome/installer/util/google_update_settings.h" | 14 #include "chrome/installer/util/google_update_settings.h" |
| 14 #include "content/public/common/gpu_info.h" | 15 #include "content/public/common/gpu_info.h" |
| 15 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 16 | 17 |
| 17 namespace child_process_logging { | 18 namespace child_process_logging { |
| 18 | 19 |
| 19 // Account for the terminating null character. | 20 // Account for the terminating null character. |
| 20 static const size_t kMaxActiveURLSize = 1024 + 1; | 21 static const size_t kMaxActiveURLSize = 1024 + 1; |
| 21 static const size_t kClientIdSize = 32 + 1; | 22 static const size_t kClientIdSize = 32 + 1; |
| 22 static const size_t kChannelSize = 32; | 23 static const size_t kChannelSize = 32; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 char g_gpu_device_id[kGpuStringSize] = ""; | 35 char g_gpu_device_id[kGpuStringSize] = ""; |
| 35 char g_gpu_driver_ver[kGpuStringSize] = ""; | 36 char g_gpu_driver_ver[kGpuStringSize] = ""; |
| 36 char g_gpu_ps_ver[kGpuStringSize] = ""; | 37 char g_gpu_ps_ver[kGpuStringSize] = ""; |
| 37 char g_gpu_vs_ver[kGpuStringSize] = ""; | 38 char g_gpu_vs_ver[kGpuStringSize] = ""; |
| 38 | 39 |
| 39 char g_printer_info[kPrinterInfoStrLen * kMaxReportedPrinterRecords + 1] = ""; | 40 char g_printer_info[kPrinterInfoStrLen * kMaxReportedPrinterRecords + 1] = ""; |
| 40 | 41 |
| 41 static const size_t kNumSize = 32; | 42 static const size_t kNumSize = 32; |
| 42 char g_num_extensions[kNumSize] = ""; | 43 char g_num_extensions[kNumSize] = ""; |
| 43 char g_num_switches[kNumSize] = ""; | 44 char g_num_switches[kNumSize] = ""; |
| 45 char g_num_variations[kNumSize] = ""; |
| 44 char g_num_views[kNumSize] = ""; | 46 char g_num_views[kNumSize] = ""; |
| 45 | 47 |
| 46 static const size_t kMaxExtensionSize = | 48 static const size_t kMaxExtensionSize = |
| 47 kExtensionLen * kMaxReportedActiveExtensions + 1; | 49 kExtensionLen * kMaxReportedActiveExtensions + 1; |
| 48 char g_extension_ids[kMaxExtensionSize] = ""; | 50 char g_extension_ids[kMaxExtensionSize] = ""; |
| 49 | 51 |
| 50 // Assume command line switches are less than 64 chars. | 52 // Assume command line switches are less than 64 chars. |
| 51 static const size_t kMaxSwitchesSize = kSwitchLen * kMaxSwitches + 1; | 53 static const size_t kMaxSwitchesSize = kSwitchLen * kMaxSwitches + 1; |
| 52 char g_switches[kMaxSwitchesSize] = ""; | 54 char g_switches[kMaxSwitchesSize] = ""; |
| 53 | 55 |
| 56 static const size_t kMaxVariationChunksSize = |
| 57 kMaxVariationChunkSize * kMaxReportedVariationChunks + 1; |
| 58 char g_variation_chunks[kMaxVariationChunksSize] = ""; |
| 59 |
| 54 void SetActiveURL(const GURL& url) { | 60 void SetActiveURL(const GURL& url) { |
| 55 base::strlcpy(g_active_url, | 61 base::strlcpy(g_active_url, url.possibly_invalid_spec().c_str(), |
| 56 url.possibly_invalid_spec().c_str(), | 62 arraysize(g_active_url)); |
| 57 kMaxActiveURLSize); | |
| 58 } | 63 } |
| 59 | 64 |
| 60 void SetClientId(const std::string& client_id) { | 65 void SetClientId(const std::string& client_id) { |
| 61 std::string str(client_id); | 66 std::string str(client_id); |
| 62 ReplaceSubstringsAfterOffset(&str, 0, "-", ""); | 67 ReplaceSubstringsAfterOffset(&str, 0, "-", ""); |
| 63 | 68 |
| 64 if (str.empty()) | 69 if (str.empty()) |
| 65 return; | 70 return; |
| 66 | 71 |
| 67 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); | 72 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); |
| 68 std::wstring wstr = ASCIIToWide(str); | 73 std::wstring wstr = ASCIIToWide(str); |
| 69 GoogleUpdateSettings::SetMetricsId(wstr); | 74 GoogleUpdateSettings::SetMetricsId(wstr); |
| 70 } | 75 } |
| 71 | 76 |
| 72 std::string GetClientId() { | 77 std::string GetClientId() { |
| 73 return std::string(g_client_id); | 78 return std::string(g_client_id); |
| 74 } | 79 } |
| 75 | 80 |
| 76 void SetActiveExtensions(const std::set<std::string>& extension_ids) { | 81 void SetActiveExtensions(const std::set<std::string>& extension_ids) { |
| 77 snprintf(g_num_extensions, kNumSize - 1, "%" PRIuS, extension_ids.size()); | 82 snprintf(g_num_extensions, arraysize(g_num_extensions), "%" PRIuS, |
| 78 g_num_extensions[kNumSize - 1] = '\0'; | 83 extension_ids.size()); |
| 79 | 84 |
| 80 std::string extension_str; | 85 std::string extension_str; |
| 81 std::set<std::string>::const_iterator iter = extension_ids.begin(); | 86 std::set<std::string>::const_iterator iter = extension_ids.begin(); |
| 82 for (int i = 0; | 87 for (size_t i = 0; |
| 83 i < kMaxReportedActiveExtensions && iter != extension_ids.end(); | 88 i < kMaxReportedActiveExtensions && iter != extension_ids.end(); |
| 84 ++i, ++iter) { | 89 ++i, ++iter) { |
| 85 extension_str += *iter; | 90 extension_str += *iter; |
| 86 } | 91 } |
| 87 strncpy(g_extension_ids, extension_str.c_str(), kMaxExtensionSize - 1); | 92 base::strlcpy(g_extension_ids, extension_str.c_str(), |
| 88 g_extension_ids[kMaxExtensionSize - 1] = '\0'; | 93 arraysize(g_extension_ids)); |
| 89 } | 94 } |
| 90 | 95 |
| 91 void SetGpuInfo(const content::GPUInfo& gpu_info) { | 96 void SetGpuInfo(const content::GPUInfo& gpu_info) { |
| 92 snprintf(g_gpu_vendor_id, kGpuStringSize, "0x%04x", gpu_info.gpu.vendor_id); | 97 snprintf(g_gpu_vendor_id, arraysize(g_gpu_vendor_id), "0x%04x", |
| 93 snprintf(g_gpu_device_id, kGpuStringSize, "0x%04x", gpu_info.gpu.device_id); | 98 gpu_info.gpu.vendor_id); |
| 94 strncpy(g_gpu_driver_ver, | 99 snprintf(g_gpu_device_id, arraysize(g_gpu_device_id), "0x%04x", |
| 95 gpu_info.driver_version.c_str(), | 100 gpu_info.gpu.device_id); |
| 96 kGpuStringSize - 1); | 101 base::strlcpy(g_gpu_driver_ver, gpu_info.driver_version.c_str(), |
| 97 g_gpu_driver_ver[kGpuStringSize - 1] = '\0'; | 102 arraysize(g_gpu_driver_ver)); |
| 98 strncpy(g_gpu_ps_ver, | 103 base::strlcpy(g_gpu_ps_ver, gpu_info.pixel_shader_version.c_str(), |
| 99 gpu_info.pixel_shader_version.c_str(), | 104 arraysize(g_gpu_ps_ver)); |
| 100 kGpuStringSize - 1); | 105 base::strlcpy(g_gpu_vs_ver, gpu_info.vertex_shader_version.c_str(), |
| 101 g_gpu_ps_ver[kGpuStringSize - 1] = '\0'; | 106 arraysize(g_gpu_vs_ver)); |
| 102 strncpy(g_gpu_vs_ver, | |
| 103 gpu_info.vertex_shader_version.c_str(), | |
| 104 kGpuStringSize - 1); | |
| 105 g_gpu_vs_ver[kGpuStringSize - 1] = '\0'; | |
| 106 } | 107 } |
| 107 | 108 |
| 108 void SetPrinterInfo(const char* printer_info) { | 109 void SetPrinterInfo(const char* printer_info) { |
| 109 std::string printer_info_str; | 110 std::string printer_info_str; |
| 110 std::vector<std::string> info; | 111 std::vector<std::string> info; |
| 111 base::SplitString(printer_info, L';', &info); | 112 base::SplitString(printer_info, L';', &info); |
| 112 DCHECK_LE(info.size(), kMaxReportedPrinterRecords); | 113 DCHECK_LE(info.size(), kMaxReportedPrinterRecords); |
| 113 for (size_t i = 0; i < info.size(); ++i) { | 114 for (size_t i = 0; i < info.size(); ++i) { |
| 114 printer_info_str += info[i]; | 115 printer_info_str += info[i]; |
| 115 // Truncate long switches, align short ones with spaces to be trimmed later. | 116 // Truncate long switches, align short ones with spaces to be trimmed later. |
| 116 printer_info_str.resize((i + 1) * kPrinterInfoStrLen, ' '); | 117 printer_info_str.resize((i + 1) * kPrinterInfoStrLen, ' '); |
| 117 } | 118 } |
| 118 strncpy(g_printer_info, printer_info_str.c_str(), | 119 base::strlcpy(g_printer_info, printer_info_str.c_str(), |
| 119 arraysize(g_printer_info) - 1); | 120 arraysize(g_printer_info)); |
| 120 g_printer_info[arraysize(g_printer_info) - 1] = '\0'; | |
| 121 } | 121 } |
| 122 | 122 |
| 123 void SetNumberOfViews(int number_of_views) { | 123 void SetNumberOfViews(int number_of_views) { |
| 124 snprintf(g_num_views, kNumSize - 1, "%d", number_of_views); | 124 snprintf(g_num_views, arraysize(g_num_views), "%d", number_of_views); |
| 125 g_num_views[kNumSize - 1] = '\0'; | |
| 126 } | 125 } |
| 127 | 126 |
| 128 void SetCommandLine(const CommandLine* command_line) { | 127 void SetCommandLine(const CommandLine* command_line) { |
| 129 const CommandLine::StringVector& argv = command_line->argv(); | 128 const CommandLine::StringVector& argv = command_line->argv(); |
| 130 | 129 |
| 131 snprintf(g_num_switches, kNumSize - 1, "%" PRIuS, argv.size() - 1); | 130 snprintf(g_num_switches, arraysize(g_num_switches), "%" PRIuS, |
| 132 g_num_switches[kNumSize - 1] = '\0'; | 131 argv.size() - 1); |
| 133 | 132 |
| 134 std::string command_line_str; | 133 std::string command_line_str; |
| 135 for (size_t argv_i = 1; | 134 for (size_t argv_i = 1; |
| 136 argv_i < argv.size() && argv_i <= kMaxSwitches; | 135 argv_i < argv.size() && argv_i <= kMaxSwitches; |
| 137 ++argv_i) { | 136 ++argv_i) { |
| 138 command_line_str += argv[argv_i]; | 137 command_line_str += argv[argv_i]; |
| 139 // Truncate long switches, align short ones with spaces to be trimmed later. | 138 // Truncate long switches, align short ones with spaces to be trimmed later. |
| 140 command_line_str.resize(argv_i * kSwitchLen, ' '); | 139 command_line_str.resize(argv_i * kSwitchLen, ' '); |
| 141 } | 140 } |
| 142 strncpy(g_switches, command_line_str.c_str(), kMaxSwitchesSize - 1); | 141 base::strlcpy(g_switches, command_line_str.c_str(), arraysize(g_switches)); |
| 143 g_switches[kMaxSwitchesSize - 1] = '\0'; | |
| 144 } | 142 } |
| 145 | 143 |
| 146 void SetExperimentList(const std::vector<string16>& state) { | 144 void SetExperimentList(const std::vector<string16>& experiments) { |
| 147 // TODO(mad): Implement this. | 145 std::vector<string16> chunks; |
| 146 chrome_variations::GenerateVariationChunks(experiments, &chunks); |
| 147 |
| 148 // Store up to |kMaxReportedVariationChunks| chunks. |
| 149 std::string chunks_str; |
| 150 const size_t number_of_chunks_to_report = |
| 151 std::min(chunks.size(), kMaxReportedVariationChunks); |
| 152 for (size_t i = 0; i < number_of_chunks_to_report; ++i) { |
| 153 chunks_str += UTF16ToUTF8(chunks[i]); |
| 154 // Align short chunks with spaces to be trimmed later. |
| 155 chunks_str.resize(i * kMaxVariationChunkSize, ' '); |
| 156 } |
| 157 base::strlcpy(g_variation_chunks, chunks_str.c_str(), |
| 158 arraysize(g_variation_chunks)); |
| 159 |
| 160 // Make note of the total number of experiments, which may be greater than |
| 161 // what was able to fit in |kMaxReportedVariationChunks|. This is useful when |
| 162 // correlating stability with the number of experiments running |
| 163 // simultaneously. |
| 164 snprintf(g_num_variations, arraysize(g_num_variations), "%" PRIuS, |
| 165 experiments.size()); |
| 148 } | 166 } |
| 149 | 167 |
| 150 void SetChannel(const std::string& channel) { | 168 void SetChannel(const std::string& channel) { |
| 151 strncpy(g_channel, channel.c_str(), kChannelSize - 1); | 169 base::strlcpy(g_channel, channel.c_str(), arraysize(g_channel)); |
| 152 g_channel[kChannelSize - 1] = '\0'; | |
| 153 } | 170 } |
| 154 | 171 |
| 155 } // namespace child_process_logging | 172 } // namespace child_process_logging |
| OLD | NEW |