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 |
26 static const size_t kNumSize = 32; | 28 static const size_t kNumSize = 32; |
27 char g_num_switches[kNumSize] = ""; | 29 char g_num_switches[kNumSize] = ""; |
28 char g_num_variations[kNumSize] = ""; | 30 char g_num_variations[kNumSize] = ""; |
29 | 31 |
30 // Assume command line switches are less than 64 chars. | 32 // Assume command line switches are less than 64 chars. |
31 static const size_t kMaxSwitchesSize = kSwitchLen * kMaxSwitches + 1; | 33 static const size_t kMaxSwitchesSize = kSwitchLen * kMaxSwitches + 1; |
32 char g_switches[kMaxSwitchesSize] = ""; | 34 char g_switches[kMaxSwitchesSize] = ""; |
33 | 35 |
34 static const size_t kMaxVariationChunksSize = | 36 static const size_t kMaxVariationChunksSize = |
35 kMaxVariationChunkSize * kMaxReportedVariationChunks + 1; | 37 kMaxVariationChunkSize * kMaxReportedVariationChunks + 1; |
36 char g_variation_chunks[kMaxVariationChunksSize] = ""; | 38 char g_variation_chunks[kMaxVariationChunksSize] = ""; |
37 | 39 |
38 void SetClientId(const std::string& client_id) { | 40 void SetClientId(const std::string& client_id) { |
39 std::string str(client_id); | 41 std::string str(client_id); |
40 ReplaceSubstringsAfterOffset(&str, 0, "-", std::string()); | 42 ReplaceSubstringsAfterOffset(&str, 0, "-", std::string()); |
41 | 43 |
42 if (str.empty()) | 44 if (str.empty()) |
43 return; | 45 return; |
44 | 46 |
45 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); | 47 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); |
46 std::wstring wstr = ASCIIToWide(str); | 48 std::wstring wstr = ASCIIToWide(str); |
47 GoogleUpdateSettings::SetMetricsId(wstr); | 49 GoogleUpdateSettings::SetMetricsId(wstr); |
48 } | 50 } |
49 | 51 |
50 std::string GetClientId() { | 52 std::string GetClientId() { |
51 return std::string(g_client_id); | 53 return std::string(g_client_id); |
52 } | 54 } |
53 | 55 |
| 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 |
54 void SetCommandLine(const CommandLine* command_line) { | 70 void SetCommandLine(const CommandLine* command_line) { |
55 const CommandLine::StringVector& argv = command_line->argv(); | 71 const CommandLine::StringVector& argv = command_line->argv(); |
56 | 72 |
57 snprintf(g_num_switches, arraysize(g_num_switches), "%" PRIuS, | 73 snprintf(g_num_switches, arraysize(g_num_switches), "%" PRIuS, |
58 argv.size() - 1); | 74 argv.size() - 1); |
59 | 75 |
60 std::string command_line_str; | 76 std::string command_line_str; |
61 for (size_t argv_i = 1; | 77 for (size_t argv_i = 1; |
62 argv_i < argv.size() && argv_i <= kMaxSwitches; | 78 argv_i < argv.size() && argv_i <= kMaxSwitches; |
63 ++argv_i) { | 79 ++argv_i) { |
(...skipping 22 matching lines...) Expand all Loading... |
86 | 102 |
87 // Make note of the total number of experiments, which may be greater than | 103 // Make note of the total number of experiments, which may be greater than |
88 // what was able to fit in |kMaxReportedVariationChunks|. This is useful when | 104 // what was able to fit in |kMaxReportedVariationChunks|. This is useful when |
89 // correlating stability with the number of experiments running | 105 // correlating stability with the number of experiments running |
90 // simultaneously. | 106 // simultaneously. |
91 snprintf(g_num_variations, arraysize(g_num_variations), "%" PRIuS, | 107 snprintf(g_num_variations, arraysize(g_num_variations), "%" PRIuS, |
92 experiments.size()); | 108 experiments.size()); |
93 } | 109 } |
94 | 110 |
95 } // namespace child_process_logging | 111 } // namespace child_process_logging |
OLD | NEW |