OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/crash_keys.h" | 5 #include "chrome/common/crash_keys.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/logging.h" | 9 #include "base/logging.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/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
16 #include "ipc/ipc_switches.h" | 16 #include "ipc/ipc_switches.h" |
17 | 17 |
18 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
19 #include "breakpad/src/common/simple_string_dictionary.h" | 19 #include "breakpad/src/common/simple_string_dictionary.h" |
20 #elif defined(OS_WIN) | 20 #elif defined(OS_WIN) |
21 #include "breakpad/src/client/windows/common/ipc_protocol.h" | 21 #include "breakpad/src/client/windows/common/ipc_protocol.h" |
22 #elif defined(OS_CHROMEOS) | 22 #elif defined(OS_CHROMEOS) |
23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
24 #include "gpu/command_buffer/service/gpu_switches.h" | 24 #include "gpu/command_buffer/service/gpu_switches.h" |
25 #include "ui/gl/gl_switches.h" | 25 #include "ui/gl/gl_switches.h" |
26 #endif | 26 #endif |
27 | 27 |
28 namespace crash_keys { | 28 namespace crash_keys { |
29 | 29 |
30 // A small crash key, guaranteed to never be split into multiple pieces. | |
31 const size_t kSmallSize = 63; | |
32 | |
33 // A medium crash key, which will be chunked on certain platforms but not | |
34 // others. Guaranteed to never be more than four chunks. | |
35 const size_t kMediumSize = kSmallSize * 4; | |
36 | |
37 // A large crash key, which will be chunked on all platforms. This should be | |
38 // used sparingly. | |
39 const size_t kLargeSize = kSmallSize * 16; | |
40 | |
41 // The maximum lengths specified by breakpad include the trailing NULL, so | 30 // The maximum lengths specified by breakpad include the trailing NULL, so |
42 // the actual length of the string is one less. | 31 // the actual length of the string is one less. |
43 #if defined(OS_MACOSX) | 32 #if defined(OS_MACOSX) |
44 static const size_t kSingleChunkLength = | 33 static const size_t kSingleChunkLength = |
45 google_breakpad::SimpleStringDictionary::value_size - 1; | 34 google_breakpad::SimpleStringDictionary::value_size - 1; |
46 #elif defined(OS_WIN) | 35 #elif defined(OS_WIN) |
47 static const size_t kSingleChunkLength = | 36 static const size_t kSingleChunkLength = |
48 google_breakpad::CustomInfoEntry::kValueMaxLength - 1; | 37 google_breakpad::CustomInfoEntry::kValueMaxLength - 1; |
49 #else | 38 #else |
50 static const size_t kSingleChunkLength = 63; | 39 static const size_t kSingleChunkLength = 63; |
51 #endif | 40 #endif |
52 | 41 |
53 // Guarantees for crash key sizes. | 42 // Guarantees for crash key sizes. |
54 static_assert(kSmallSize <= kSingleChunkLength, | 43 static_assert(kSmallSize <= kSingleChunkLength, |
55 "crash key chunk size too small"); | 44 "crash key chunk size too small"); |
56 #if defined(OS_MACOSX) | 45 #if defined(OS_MACOSX) |
57 static_assert(kMediumSize <= kSingleChunkLength, | 46 static_assert(kMediumSize <= kSingleChunkLength, |
58 "mac has medium size crash key chunks"); | 47 "mac has medium size crash key chunks"); |
59 #endif | 48 #endif |
60 | 49 |
61 #if defined(OS_MACOSX) | |
62 // Crashpad owns the "guid" key. Chrome's metrics client ID is a separate ID | |
63 // carried in a distinct "metrics_client_id" field. | |
64 const char kMetricsClientId[] = "metrics_client_id"; | |
65 #else | |
66 const char kClientId[] = "guid"; | |
67 #endif | |
68 | |
69 const char kChannel[] = "channel"; | |
70 | |
71 const char kActiveURL[] = "url-chunk"; | 50 const char kActiveURL[] = "url-chunk"; |
72 | 51 |
73 const char kFontKeyName[] = "font_key_name"; | 52 const char kFontKeyName[] = "font_key_name"; |
74 | 53 |
75 const char kSwitch[] = "switch-%" PRIuS; | 54 const char kSwitch[] = "switch-%" PRIuS; |
76 const char kNumSwitches[] = "num-switches"; | 55 const char kNumSwitches[] = "num-switches"; |
77 | 56 |
78 const char kNumVariations[] = "num-experiments"; | |
79 const char kVariations[] = "variations"; | |
80 | |
81 const char kExtensionID[] = "extension-%" PRIuS; | 57 const char kExtensionID[] = "extension-%" PRIuS; |
82 const char kNumExtensionsCount[] = "num-extensions"; | 58 const char kNumExtensionsCount[] = "num-extensions"; |
83 | 59 |
84 const char kShutdownType[] = "shutdown-type"; | 60 const char kShutdownType[] = "shutdown-type"; |
85 | 61 |
86 #if !defined(OS_ANDROID) | 62 #if !defined(OS_ANDROID) |
87 const char kGPUVendorID[] = "gpu-venid"; | 63 const char kGPUVendorID[] = "gpu-venid"; |
88 const char kGPUDeviceID[] = "gpu-devid"; | 64 const char kGPUDeviceID[] = "gpu-devid"; |
89 #endif | 65 #endif |
90 const char kGPUDriverVersion[] = "gpu-driver"; | 66 const char kGPUDriverVersion[] = "gpu-driver"; |
(...skipping 19 matching lines...) Expand all Loading... |
110 const char kFirstNSExceptionTrace[] = "firstexception_bt"; | 86 const char kFirstNSExceptionTrace[] = "firstexception_bt"; |
111 | 87 |
112 const char kLastNSException[] = "lastexception"; | 88 const char kLastNSException[] = "lastexception"; |
113 const char kLastNSExceptionTrace[] = "lastexception_bt"; | 89 const char kLastNSExceptionTrace[] = "lastexception_bt"; |
114 | 90 |
115 const char kNSException[] = "nsexception"; | 91 const char kNSException[] = "nsexception"; |
116 const char kNSExceptionTrace[] = "nsexception_bt"; | 92 const char kNSExceptionTrace[] = "nsexception_bt"; |
117 | 93 |
118 const char kSendAction[] = "sendaction"; | 94 const char kSendAction[] = "sendaction"; |
119 | 95 |
120 const char kZombie[] = "zombie"; | |
121 const char kZombieTrace[] = "zombie_dealloc_bt"; | |
122 | |
123 } // namespace mac | 96 } // namespace mac |
124 #endif | 97 #endif |
125 | 98 |
126 #if defined(KASKO) | 99 #if defined(KASKO) |
127 const char kKaskoGuid[] = "kasko-guid"; | 100 const char kKaskoGuid[] = "kasko-guid"; |
128 const char kKaskoEquivalentGuid[] = "kasko-equivalent-guid"; | 101 const char kKaskoEquivalentGuid[] = "kasko-equivalent-guid"; |
129 #endif | 102 #endif |
130 | 103 |
131 // Used to help investigate bug 464926. NOTE: This value is defined multiple | 104 // Used to help investigate bug 464926. NOTE: This value is defined multiple |
132 // places in the codebase due to layering issues. DO NOT change the value here | 105 // places in the codebase due to layering issues. DO NOT change the value here |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 DCHECK_GT(n, 0); | 223 DCHECK_GT(n, 0); |
251 base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize }; | 224 base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize }; |
252 keys.push_back(crash_key); | 225 keys.push_back(crash_key); |
253 } | 226 } |
254 } | 227 } |
255 | 228 |
256 return base::debug::InitCrashKeys(&keys.at(0), keys.size(), | 229 return base::debug::InitCrashKeys(&keys.at(0), keys.size(), |
257 kSingleChunkLength); | 230 kSingleChunkLength); |
258 } | 231 } |
259 | 232 |
260 void SetMetricsClientIdFromGUID(const std::string& metrics_client_guid) { | |
261 std::string stripped_guid(metrics_client_guid); | |
262 // Remove all instance of '-' char from the GUID. So BCD-WXY becomes BCDWXY. | |
263 base::ReplaceSubstringsAfterOffset( | |
264 &stripped_guid, 0, "-", base::StringPiece()); | |
265 if (stripped_guid.empty()) | |
266 return; | |
267 | |
268 #if defined(OS_MACOSX) | |
269 // The crash client ID is maintained by Crashpad and is distinct from the | |
270 // metrics client ID, which is carried in its own key. | |
271 base::debug::SetCrashKeyValue(kMetricsClientId, stripped_guid); | |
272 #else | |
273 // The crash client ID is set by the application when Breakpad is in use. | |
274 // The same ID as the metrics client ID is used. | |
275 base::debug::SetCrashKeyValue(kClientId, stripped_guid); | |
276 #endif | |
277 } | |
278 | |
279 void ClearMetricsClientId() { | |
280 #if defined(OS_MACOSX) | |
281 // Crashpad always monitors for crashes, but doesn't upload them when | |
282 // crash reporting is disabled. The preference to upload crash reports is | |
283 // linked to the preference for metrics reporting. When metrics reporting is | |
284 // disabled, don't put the metrics client ID into crash dumps. This way, crash | |
285 // reports that are saved but not uploaded will not have a metrics client ID | |
286 // from the time that metrics reporting was disabled even if they are uploaded | |
287 // by user action at a later date. | |
288 // | |
289 // Breakpad cannot be enabled or disabled without an application restart, and | |
290 // it needs to use the metrics client ID as its stable crash client ID, so | |
291 // leave its client ID intact even when metrics reporting is disabled while | |
292 // the application is running. | |
293 base::debug::ClearCrashKey(kMetricsClientId); | |
294 #endif | |
295 } | |
296 | |
297 static bool IsBoringSwitch(const std::string& flag) { | 233 static bool IsBoringSwitch(const std::string& flag) { |
298 static const char* const kIgnoreSwitches[] = { | 234 static const char* const kIgnoreSwitches[] = { |
299 switches::kEnableLogging, | 235 switches::kEnableLogging, |
300 switches::kFlagSwitchesBegin, | 236 switches::kFlagSwitchesBegin, |
301 switches::kFlagSwitchesEnd, | 237 switches::kFlagSwitchesEnd, |
302 switches::kLoggingLevel, | 238 switches::kLoggingLevel, |
303 #if defined(OS_WIN) | 239 #if defined(OS_WIN) |
304 // This file is linked into both chrome.dll and chrome.exe. However //ipc | 240 // This file is linked into both chrome.dll and chrome.exe. However //ipc |
305 // is only in the .dll, so this needs to be a literal rather than the | 241 // is only in the .dll, so this needs to be a literal rather than the |
306 // constant. | 242 // constant. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 std::string key = base::StringPrintf(kSwitch, key_i++); | 326 std::string key = base::StringPrintf(kSwitch, key_i++); |
391 base::debug::SetCrashKeyValue(key, switch_str); | 327 base::debug::SetCrashKeyValue(key, switch_str); |
392 } | 328 } |
393 | 329 |
394 // Clear any remaining switches. | 330 // Clear any remaining switches. |
395 for (; key_i <= kSwitchesMaxCount; ++key_i) { | 331 for (; key_i <= kSwitchesMaxCount; ++key_i) { |
396 base::debug::ClearCrashKey(base::StringPrintf(kSwitch, key_i)); | 332 base::debug::ClearCrashKey(base::StringPrintf(kSwitch, key_i)); |
397 } | 333 } |
398 } | 334 } |
399 | 335 |
400 void SetVariationsList(const std::vector<std::string>& variations) { | |
401 base::debug::SetCrashKeyValue(kNumVariations, | |
402 base::StringPrintf("%" PRIuS, variations.size())); | |
403 | |
404 std::string variations_string; | |
405 variations_string.reserve(kLargeSize); | |
406 | |
407 for (size_t i = 0; i < variations.size(); ++i) { | |
408 const std::string& variation = variations[i]; | |
409 // Do not truncate an individual experiment. | |
410 if (variations_string.size() + variation.size() >= kLargeSize) | |
411 break; | |
412 variations_string += variation; | |
413 variations_string += ","; | |
414 } | |
415 | |
416 base::debug::SetCrashKeyValue(kVariations, variations_string); | |
417 } | |
418 | |
419 void SetActiveExtensions(const std::set<std::string>& extensions) { | 336 void SetActiveExtensions(const std::set<std::string>& extensions) { |
420 base::debug::SetCrashKeyValue(kNumExtensionsCount, | 337 base::debug::SetCrashKeyValue(kNumExtensionsCount, |
421 base::StringPrintf("%" PRIuS, extensions.size())); | 338 base::StringPrintf("%" PRIuS, extensions.size())); |
422 | 339 |
423 std::set<std::string>::const_iterator it = extensions.begin(); | 340 std::set<std::string>::const_iterator it = extensions.begin(); |
424 for (size_t i = 0; i < kExtensionIDMaxCount; ++i) { | 341 for (size_t i = 0; i < kExtensionIDMaxCount; ++i) { |
425 std::string key = base::StringPrintf(kExtensionID, i + 1); | 342 std::string key = base::StringPrintf(kExtensionID, i + 1); |
426 if (it == extensions.end()) { | 343 if (it == extensions.end()) { |
427 base::debug::ClearCrashKey(key); | 344 base::debug::ClearCrashKey(key); |
428 } else { | 345 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
445 } | 362 } |
446 | 363 |
447 ScopedPrinterInfo::~ScopedPrinterInfo() { | 364 ScopedPrinterInfo::~ScopedPrinterInfo() { |
448 for (size_t i = 0; i < kPrinterInfoCount; ++i) { | 365 for (size_t i = 0; i < kPrinterInfoCount; ++i) { |
449 std::string key = base::StringPrintf(kPrinterInfo, i + 1); | 366 std::string key = base::StringPrintf(kPrinterInfo, i + 1); |
450 base::debug::ClearCrashKey(key); | 367 base::debug::ClearCrashKey(key); |
451 } | 368 } |
452 } | 369 } |
453 | 370 |
454 } // namespace crash_keys | 371 } // namespace crash_keys |
OLD | NEW |