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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // We use static strings to hold the most recent active url and the client | 22 // We use static strings to hold the most recent active url and the client |
23 // identifier. If we crash, the crash handler code will send the contents of | 23 // identifier. If we crash, the crash handler code will send the contents of |
24 // these strings to the browser. | 24 // these strings to the browser. |
25 char g_client_id[kClientIdSize]; | 25 char g_client_id[kClientIdSize]; |
26 | 26 |
27 char g_channel[kChannelSize] = ""; | 27 char g_channel[kChannelSize] = ""; |
28 | 28 |
29 char g_printer_info[kPrinterInfoStrLen * kMaxReportedPrinterRecords + 1] = ""; | 29 char g_printer_info[kPrinterInfoStrLen * kMaxReportedPrinterRecords + 1] = ""; |
30 | 30 |
31 static const size_t kNumSize = 32; | 31 static const size_t kNumSize = 32; |
32 char g_num_extensions[kNumSize] = ""; | |
33 char g_num_switches[kNumSize] = ""; | 32 char g_num_switches[kNumSize] = ""; |
34 char g_num_variations[kNumSize] = ""; | 33 char g_num_variations[kNumSize] = ""; |
35 char g_num_views[kNumSize] = ""; | 34 char g_num_views[kNumSize] = ""; |
36 | 35 |
37 static const size_t kMaxExtensionSize = | |
38 kExtensionLen * kMaxReportedActiveExtensions + 1; | |
39 char g_extension_ids[kMaxExtensionSize] = ""; | |
40 | |
41 // Assume command line switches are less than 64 chars. | 36 // Assume command line switches are less than 64 chars. |
42 static const size_t kMaxSwitchesSize = kSwitchLen * kMaxSwitches + 1; | 37 static const size_t kMaxSwitchesSize = kSwitchLen * kMaxSwitches + 1; |
43 char g_switches[kMaxSwitchesSize] = ""; | 38 char g_switches[kMaxSwitchesSize] = ""; |
44 | 39 |
45 static const size_t kMaxVariationChunksSize = | 40 static const size_t kMaxVariationChunksSize = |
46 kMaxVariationChunkSize * kMaxReportedVariationChunks + 1; | 41 kMaxVariationChunkSize * kMaxReportedVariationChunks + 1; |
47 char g_variation_chunks[kMaxVariationChunksSize] = ""; | 42 char g_variation_chunks[kMaxVariationChunksSize] = ""; |
48 | 43 |
49 void SetClientId(const std::string& client_id) { | 44 void SetClientId(const std::string& client_id) { |
50 std::string str(client_id); | 45 std::string str(client_id); |
51 ReplaceSubstringsAfterOffset(&str, 0, "-", std::string()); | 46 ReplaceSubstringsAfterOffset(&str, 0, "-", std::string()); |
52 | 47 |
53 if (str.empty()) | 48 if (str.empty()) |
54 return; | 49 return; |
55 | 50 |
56 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); | 51 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); |
57 std::wstring wstr = ASCIIToWide(str); | 52 std::wstring wstr = ASCIIToWide(str); |
58 GoogleUpdateSettings::SetMetricsId(wstr); | 53 GoogleUpdateSettings::SetMetricsId(wstr); |
59 } | 54 } |
60 | 55 |
61 std::string GetClientId() { | 56 std::string GetClientId() { |
62 return std::string(g_client_id); | 57 return std::string(g_client_id); |
63 } | 58 } |
64 | 59 |
65 void SetActiveExtensions(const std::set<std::string>& extension_ids) { | |
66 snprintf(g_num_extensions, arraysize(g_num_extensions), "%" PRIuS, | |
67 extension_ids.size()); | |
68 | |
69 std::string extension_str; | |
70 std::set<std::string>::const_iterator iter = extension_ids.begin(); | |
71 for (size_t i = 0; | |
72 i < kMaxReportedActiveExtensions && iter != extension_ids.end(); | |
73 ++i, ++iter) { | |
74 extension_str += *iter; | |
75 } | |
76 base::strlcpy(g_extension_ids, extension_str.c_str(), | |
77 arraysize(g_extension_ids)); | |
78 } | |
79 | |
80 void SetPrinterInfo(const char* printer_info) { | 60 void SetPrinterInfo(const char* printer_info) { |
81 std::string printer_info_str; | 61 std::string printer_info_str; |
82 std::vector<std::string> info; | 62 std::vector<std::string> info; |
83 base::SplitString(printer_info, L';', &info); | 63 base::SplitString(printer_info, L';', &info); |
84 DCHECK_LE(info.size(), kMaxReportedPrinterRecords); | 64 DCHECK_LE(info.size(), kMaxReportedPrinterRecords); |
85 for (size_t i = 0; i < info.size(); ++i) { | 65 for (size_t i = 0; i < info.size(); ++i) { |
86 printer_info_str += info[i]; | 66 printer_info_str += info[i]; |
87 // Truncate long switches, align short ones with spaces to be trimmed later. | 67 // Truncate long switches, align short ones with spaces to be trimmed later. |
88 printer_info_str.resize((i + 1) * kPrinterInfoStrLen, ' '); | 68 printer_info_str.resize((i + 1) * kPrinterInfoStrLen, ' '); |
89 } | 69 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // simultaneously. | 114 // simultaneously. |
135 snprintf(g_num_variations, arraysize(g_num_variations), "%" PRIuS, | 115 snprintf(g_num_variations, arraysize(g_num_variations), "%" PRIuS, |
136 experiments.size()); | 116 experiments.size()); |
137 } | 117 } |
138 | 118 |
139 void SetChannel(const std::string& channel) { | 119 void SetChannel(const std::string& channel) { |
140 base::strlcpy(g_channel, channel.c_str(), arraysize(g_channel)); | 120 base::strlcpy(g_channel, channel.c_str(), arraysize(g_channel)); |
141 } | 121 } |
142 | 122 |
143 } // namespace child_process_logging | 123 } // namespace child_process_logging |
OLD | NEW |