| 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/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/common/metrics/variations/variations_util.h" | 13 #include "chrome/common/metrics/variations/variations_util.h" |
| 14 #include "chrome/installer/util/google_update_settings.h" | 14 #include "chrome/installer/util/google_update_settings.h" |
| 15 | 15 |
| 16 namespace child_process_logging { | 16 namespace child_process_logging { |
| 17 | 17 |
| 18 // Account for the terminating null character. | 18 // Account for the terminating null character. |
| 19 static const size_t kClientIdSize = 32 + 1; | 19 static const size_t kClientIdSize = 32 + 1; |
| 20 | 20 |
| 21 // We use static strings to hold the most recent active url and the client | 21 // We use static strings to hold the most recent active url and the client |
| 22 // identifier. If we crash, the crash handler code will send the contents of | 22 // identifier. If we crash, the crash handler code will send the contents of |
| 23 // these strings to the browser. | 23 // these strings to the browser. |
| 24 char g_client_id[kClientIdSize]; | 24 char g_client_id[kClientIdSize]; |
| 25 | 25 |
| 26 char g_printer_info[kPrinterInfoStrLen * kMaxReportedPrinterRecords + 1] = ""; | |
| 27 | |
| 28 static const size_t kNumSize = 32; | 26 static const size_t kNumSize = 32; |
| 29 char g_num_switches[kNumSize] = ""; | 27 char g_num_switches[kNumSize] = ""; |
| 30 char g_num_variations[kNumSize] = ""; | 28 char g_num_variations[kNumSize] = ""; |
| 31 | 29 |
| 32 // Assume command line switches are less than 64 chars. | 30 // Assume command line switches are less than 64 chars. |
| 33 static const size_t kMaxSwitchesSize = kSwitchLen * kMaxSwitches + 1; | 31 static const size_t kMaxSwitchesSize = kSwitchLen * kMaxSwitches + 1; |
| 34 char g_switches[kMaxSwitchesSize] = ""; | 32 char g_switches[kMaxSwitchesSize] = ""; |
| 35 | 33 |
| 36 static const size_t kMaxVariationChunksSize = | 34 static const size_t kMaxVariationChunksSize = |
| 37 kMaxVariationChunkSize * kMaxReportedVariationChunks + 1; | 35 kMaxVariationChunkSize * kMaxReportedVariationChunks + 1; |
| 38 char g_variation_chunks[kMaxVariationChunksSize] = ""; | 36 char g_variation_chunks[kMaxVariationChunksSize] = ""; |
| 39 | 37 |
| 40 void SetClientId(const std::string& client_id) { | 38 void SetClientId(const std::string& client_id) { |
| 41 std::string str(client_id); | 39 std::string str(client_id); |
| 42 ReplaceSubstringsAfterOffset(&str, 0, "-", std::string()); | 40 ReplaceSubstringsAfterOffset(&str, 0, "-", std::string()); |
| 43 | 41 |
| 44 if (str.empty()) | 42 if (str.empty()) |
| 45 return; | 43 return; |
| 46 | 44 |
| 47 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); | 45 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); |
| 48 std::wstring wstr = ASCIIToWide(str); | 46 std::wstring wstr = ASCIIToWide(str); |
| 49 GoogleUpdateSettings::SetMetricsId(wstr); | 47 GoogleUpdateSettings::SetMetricsId(wstr); |
| 50 } | 48 } |
| 51 | 49 |
| 52 std::string GetClientId() { | 50 std::string GetClientId() { |
| 53 return std::string(g_client_id); | 51 return std::string(g_client_id); |
| 54 } | 52 } |
| 55 | 53 |
| 56 void SetPrinterInfo(const char* printer_info) { | |
| 57 std::string printer_info_str; | |
| 58 std::vector<std::string> info; | |
| 59 base::SplitString(printer_info, L';', &info); | |
| 60 DCHECK_LE(info.size(), kMaxReportedPrinterRecords); | |
| 61 for (size_t i = 0; i < info.size(); ++i) { | |
| 62 printer_info_str += info[i]; | |
| 63 // Truncate long switches, align short ones with spaces to be trimmed later. | |
| 64 printer_info_str.resize((i + 1) * kPrinterInfoStrLen, ' '); | |
| 65 } | |
| 66 base::strlcpy(g_printer_info, printer_info_str.c_str(), | |
| 67 arraysize(g_printer_info)); | |
| 68 } | |
| 69 | |
| 70 void SetCommandLine(const CommandLine* command_line) { | 54 void SetCommandLine(const CommandLine* command_line) { |
| 71 const CommandLine::StringVector& argv = command_line->argv(); | 55 const CommandLine::StringVector& argv = command_line->argv(); |
| 72 | 56 |
| 73 snprintf(g_num_switches, arraysize(g_num_switches), "%" PRIuS, | 57 snprintf(g_num_switches, arraysize(g_num_switches), "%" PRIuS, |
| 74 argv.size() - 1); | 58 argv.size() - 1); |
| 75 | 59 |
| 76 std::string command_line_str; | 60 std::string command_line_str; |
| 77 for (size_t argv_i = 1; | 61 for (size_t argv_i = 1; |
| 78 argv_i < argv.size() && argv_i <= kMaxSwitches; | 62 argv_i < argv.size() && argv_i <= kMaxSwitches; |
| 79 ++argv_i) { | 63 ++argv_i) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 102 | 86 |
| 103 // Make note of the total number of experiments, which may be greater than | 87 // Make note of the total number of experiments, which may be greater than |
| 104 // what was able to fit in |kMaxReportedVariationChunks|. This is useful when | 88 // what was able to fit in |kMaxReportedVariationChunks|. This is useful when |
| 105 // correlating stability with the number of experiments running | 89 // correlating stability with the number of experiments running |
| 106 // simultaneously. | 90 // simultaneously. |
| 107 snprintf(g_num_variations, arraysize(g_num_variations), "%" PRIuS, | 91 snprintf(g_num_variations, arraysize(g_num_variations), "%" PRIuS, |
| 108 experiments.size()); | 92 experiments.size()); |
| 109 } | 93 } |
| 110 | 94 |
| 111 } // namespace child_process_logging | 95 } // namespace child_process_logging |
| OLD | NEW |