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_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/common/metrics/variations/variations_util.h" | 16 #include "chrome/common/metrics/variations/variations_util.h" |
17 #include "chrome/installer/util/google_update_settings.h" | 17 #include "chrome/installer/util/google_update_settings.h" |
18 | 18 |
19 namespace child_process_logging { | 19 namespace child_process_logging { |
20 | 20 |
21 using base::debug::SetCrashKeyValueFuncT; | 21 using base::debug::SetCrashKeyValueFuncT; |
22 using base::debug::ClearCrashKeyValueFuncT; | 22 using base::debug::ClearCrashKeyValueFuncT; |
23 using base::debug::SetCrashKeyValue; | 23 using base::debug::SetCrashKeyValue; |
24 using base::debug::ClearCrashKey; | 24 using base::debug::ClearCrashKey; |
25 | 25 |
26 const char* kGuidParamName = "guid"; | 26 const char* kGuidParamName = "guid"; |
27 const char* kNumberOfViews = "num-views"; | 27 const char* kNumberOfViews = "num-views"; |
28 const char* kNumExtensionsName = "num-extensions"; | |
29 const char* kExtensionNameFormat = "extension-%zu"; | |
30 const char* kPrinterInfoNameFormat = "prn-info-%zu"; | 28 const char* kPrinterInfoNameFormat = "prn-info-%zu"; |
31 | 29 |
32 // Account for the terminating null character. | 30 // Account for the terminating null character. |
33 static const size_t kClientIdSize = 32 + 1; | 31 static const size_t kClientIdSize = 32 + 1; |
34 static char g_client_id[kClientIdSize]; | 32 static char g_client_id[kClientIdSize]; |
35 | 33 |
36 void SetClientIdImpl(const std::string& client_id, | 34 void SetClientIdImpl(const std::string& client_id, |
37 SetCrashKeyValueFuncT set_key_func) { | 35 SetCrashKeyValueFuncT set_key_func) { |
38 set_key_func(kGuidParamName, client_id); | 36 set_key_func(kGuidParamName, client_id); |
39 } | 37 } |
40 | 38 |
41 void SetClientId(const std::string& client_id) { | 39 void SetClientId(const std::string& client_id) { |
42 std::string str(client_id); | 40 std::string str(client_id); |
43 ReplaceSubstringsAfterOffset(&str, 0, "-", ""); | 41 ReplaceSubstringsAfterOffset(&str, 0, "-", ""); |
44 | 42 |
45 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); | 43 base::strlcpy(g_client_id, str.c_str(), kClientIdSize); |
46 SetClientIdImpl(str, SetCrashKeyValue); | 44 SetClientIdImpl(str, SetCrashKeyValue); |
47 | 45 |
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 SetActiveExtensions(const std::set<std::string>& extension_ids) { | |
57 // Log the count separately to track heavy users. | |
58 const int count = static_cast<int>(extension_ids.size()); | |
59 SetCrashKeyValue(kNumExtensionsName, base::IntToString(count)); | |
60 | |
61 // Record up to |kMaxReportedActiveExtensions| extensions, clearing | |
62 // keys if there aren't that many. | |
63 std::set<std::string>::const_iterator iter = extension_ids.begin(); | |
64 for (size_t i = 0; i < kMaxReportedActiveExtensions; ++i) { | |
65 std::string key = base::StringPrintf(kExtensionNameFormat, i); | |
66 if (iter != extension_ids.end()) { | |
67 SetCrashKeyValue(key, *iter); | |
68 ++iter; | |
69 } else { | |
70 ClearCrashKey(key); | |
71 } | |
72 } | |
73 } | |
74 | |
75 void SetPrinterInfo(const char* printer_info) { | 54 void SetPrinterInfo(const char* printer_info) { |
76 std::vector<std::string> info; | 55 std::vector<std::string> info; |
77 base::SplitString(printer_info, ';', &info); | 56 base::SplitString(printer_info, ';', &info); |
78 info.resize(kMaxReportedPrinterRecords); | 57 info.resize(kMaxReportedPrinterRecords); |
79 for (size_t i = 0; i < info.size(); ++i) { | 58 for (size_t i = 0; i < info.size(); ++i) { |
80 std::string key = base::StringPrintf(kPrinterInfoNameFormat, i); | 59 std::string key = base::StringPrintf(kPrinterInfoNameFormat, i); |
81 if (!info[i].empty()) { | 60 if (!info[i].empty()) { |
82 SetCrashKeyValue(key, info[i]); | 61 SetCrashKeyValue(key, info[i]); |
83 } else { | 62 } else { |
84 ClearCrashKey(key); | 63 ClearCrashKey(key); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 base::StringPrintf("%zu", experiments.size())); | 130 base::StringPrintf("%zu", experiments.size())); |
152 } | 131 } |
153 | 132 |
154 void SetChannel(const std::string& channel) { | 133 void SetChannel(const std::string& channel) { |
155 // This should match the corresponding string in breakpad_win.cc. | 134 // This should match the corresponding string in breakpad_win.cc. |
156 const std::string kChannelKey = "channel"; | 135 const std::string kChannelKey = "channel"; |
157 SetCrashKeyValue(kChannelKey, channel); | 136 SetCrashKeyValue(kChannelKey, channel); |
158 } | 137 } |
159 | 138 |
160 } // namespace child_process_logging | 139 } // namespace child_process_logging |
OLD | NEW |