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 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.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/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/common/metrics/variations/variations_util.h" | 15 #include "chrome/common/metrics/variations/variations_util.h" |
16 #include "chrome/installer/util/google_update_settings.h" | 16 #include "chrome/installer/util/google_update_settings.h" |
17 | 17 |
18 namespace child_process_logging { | 18 namespace child_process_logging { |
19 | 19 |
20 using base::debug::SetCrashKeyValueFuncT; | 20 using base::debug::SetCrashKeyValueFuncT; |
21 using base::debug::ClearCrashKeyValueFuncT; | 21 using base::debug::ClearCrashKeyValueFuncT; |
22 using base::debug::SetCrashKeyValue; | 22 using base::debug::SetCrashKeyValue; |
23 using base::debug::ClearCrashKey; | 23 using base::debug::ClearCrashKey; |
24 | 24 |
25 const char* kGuidParamName = "guid"; | 25 const char* kGuidParamName = "guid"; |
| 26 const char* kPrinterInfoNameFormat = "prn-info-%zu"; |
26 | 27 |
27 // Account for the terminating null character. | 28 // Account for the terminating null character. |
28 static const size_t kClientIdSize = 32 + 1; | 29 static const size_t kClientIdSize = 32 + 1; |
29 static char g_client_id[kClientIdSize]; | 30 static char g_client_id[kClientIdSize]; |
30 | 31 |
31 void SetClientIdImpl(const std::string& client_id, | 32 void SetClientIdImpl(const std::string& client_id, |
32 SetCrashKeyValueFuncT set_key_func) { | 33 SetCrashKeyValueFuncT set_key_func) { |
33 set_key_func(kGuidParamName, client_id); | 34 set_key_func(kGuidParamName, client_id); |
34 } | 35 } |
35 | 36 |
36 void SetClientId(const std::string& client_id) { | 37 void SetClientId(const std::string& client_id) { |
37 std::string str(client_id); | 38 std::string str(client_id); |
38 ReplaceSubstringsAfterOffset(&str, 0, "-", ""); | 39 ReplaceSubstringsAfterOffset(&str, 0, "-", ""); |
39 | 40 |
40 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); | 41 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); |
41 SetClientIdImpl(str, SetCrashKeyValue); | 42 SetClientIdImpl(str, SetCrashKeyValue); |
42 | 43 |
43 std::wstring wstr = ASCIIToWide(str); | 44 std::wstring wstr = ASCIIToWide(str); |
44 GoogleUpdateSettings::SetMetricsId(wstr); | 45 GoogleUpdateSettings::SetMetricsId(wstr); |
45 } | 46 } |
46 | 47 |
47 std::string GetClientId() { | 48 std::string GetClientId() { |
48 return std::string(g_client_id); | 49 return std::string(g_client_id); |
49 } | 50 } |
50 | 51 |
| 52 void SetPrinterInfo(const char* printer_info) { |
| 53 std::vector<std::string> info; |
| 54 base::SplitString(printer_info, ';', &info); |
| 55 info.resize(kMaxReportedPrinterRecords); |
| 56 for (size_t i = 0; i < info.size(); ++i) { |
| 57 std::string key = base::StringPrintf(kPrinterInfoNameFormat, i); |
| 58 if (!info[i].empty()) { |
| 59 SetCrashKeyValue(key, info[i]); |
| 60 } else { |
| 61 ClearCrashKey(key); |
| 62 } |
| 63 } |
| 64 } |
| 65 |
51 void SetCommandLine(const CommandLine* command_line) { | 66 void SetCommandLine(const CommandLine* command_line) { |
52 DCHECK(command_line); | 67 DCHECK(command_line); |
53 if (!command_line) | 68 if (!command_line) |
54 return; | 69 return; |
55 | 70 |
56 // These should match the corresponding strings in breakpad_win.cc. | 71 // These should match the corresponding strings in breakpad_win.cc. |
57 const char* kNumSwitchesKey = "num-switches"; | 72 const char* kNumSwitchesKey = "num-switches"; |
58 const char* kSwitchKeyFormat = "switch-%zu"; // 1-based. | 73 const char* kSwitchKeyFormat = "switch-%zu"; // 1-based. |
59 | 74 |
60 // Note the total number of switches, not including the exec path. | 75 // Note the total number of switches, not including the exec path. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 112 |
98 // Make note of the total number of experiments, which may be greater than | 113 // Make note of the total number of experiments, which may be greater than |
99 // what was able to fit in |kMaxReportedVariationChunks|. This is useful when | 114 // what was able to fit in |kMaxReportedVariationChunks|. This is useful when |
100 // correlating stability with the number of experiments running | 115 // correlating stability with the number of experiments running |
101 // simultaneously. | 116 // simultaneously. |
102 SetCrashKeyValue(kNumExperimentsKey, | 117 SetCrashKeyValue(kNumExperimentsKey, |
103 base::StringPrintf("%zu", experiments.size())); | 118 base::StringPrintf("%zu", experiments.size())); |
104 } | 119 } |
105 | 120 |
106 } // namespace child_process_logging | 121 } // namespace child_process_logging |
OLD | NEW |