| 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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #endif | 48 #endif |
| 49 | 49 |
| 50 // Guarantees for crash key sizes. | 50 // Guarantees for crash key sizes. |
| 51 static_assert(kSmallSize <= kSingleChunkLength, | 51 static_assert(kSmallSize <= kSingleChunkLength, |
| 52 "crash key chunk size too small"); | 52 "crash key chunk size too small"); |
| 53 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
| 54 static_assert(kMediumSize <= kSingleChunkLength, | 54 static_assert(kMediumSize <= kSingleChunkLength, |
| 55 "mac has medium size crash key chunks"); | 55 "mac has medium size crash key chunks"); |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 #if defined(OS_MACOSX) |
| 59 // Crashpad owns the "guid" key. Chrome's metrics client ID is a separate ID |
| 60 // carried in a distinct "metrics_client_id" field. |
| 61 const char kMetricsClientId[] = "metrics_client_id"; |
| 62 #else |
| 58 const char kClientId[] = "guid"; | 63 const char kClientId[] = "guid"; |
| 64 #endif |
| 59 | 65 |
| 60 const char kChannel[] = "channel"; | 66 const char kChannel[] = "channel"; |
| 61 | 67 |
| 62 const char kActiveURL[] = "url-chunk"; | 68 const char kActiveURL[] = "url-chunk"; |
| 63 | 69 |
| 64 const char kFontKeyName[] = "font_key_name"; | 70 const char kFontKeyName[] = "font_key_name"; |
| 65 | 71 |
| 66 const char kSwitch[] = "switch-%" PRIuS; | 72 const char kSwitch[] = "switch-%" PRIuS; |
| 67 const char kNumSwitches[] = "num-switches"; | 73 const char kNumSwitches[] = "num-switches"; |
| 68 | 74 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 const char kZombie[] = "zombie"; | 117 const char kZombie[] = "zombie"; |
| 112 const char kZombieTrace[] = "zombie_dealloc_bt"; | 118 const char kZombieTrace[] = "zombie_dealloc_bt"; |
| 113 | 119 |
| 114 } // namespace mac | 120 } // namespace mac |
| 115 #endif | 121 #endif |
| 116 | 122 |
| 117 size_t RegisterChromeCrashKeys() { | 123 size_t RegisterChromeCrashKeys() { |
| 118 // The following keys may be chunked by the underlying crash logging system, | 124 // The following keys may be chunked by the underlying crash logging system, |
| 119 // but ultimately constitute a single key-value pair. | 125 // but ultimately constitute a single key-value pair. |
| 120 base::debug::CrashKey fixed_keys[] = { | 126 base::debug::CrashKey fixed_keys[] = { |
| 127 #if defined(OS_MACOSX) |
| 128 { kMetricsClientId, kSmallSize }, |
| 129 #else |
| 121 { kClientId, kSmallSize }, | 130 { kClientId, kSmallSize }, |
| 131 #endif |
| 122 { kChannel, kSmallSize }, | 132 { kChannel, kSmallSize }, |
| 123 { kActiveURL, kLargeSize }, | 133 { kActiveURL, kLargeSize }, |
| 124 { kNumSwitches, kSmallSize }, | 134 { kNumSwitches, kSmallSize }, |
| 125 { kNumVariations, kSmallSize }, | 135 { kNumVariations, kSmallSize }, |
| 126 { kVariations, kLargeSize }, | 136 { kVariations, kLargeSize }, |
| 127 { kNumExtensionsCount, kSmallSize }, | 137 { kNumExtensionsCount, kSmallSize }, |
| 128 { kShutdownType, kSmallSize }, | 138 { kShutdownType, kSmallSize }, |
| 129 #if !defined(OS_ANDROID) | 139 #if !defined(OS_ANDROID) |
| 130 { kGPUVendorID, kSmallSize }, | 140 { kGPUVendorID, kSmallSize }, |
| 131 { kGPUDeviceID, kSmallSize }, | 141 { kGPUDeviceID, kSmallSize }, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 DCHECK_GT(n, 0); | 228 DCHECK_GT(n, 0); |
| 219 base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize }; | 229 base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize }; |
| 220 keys.push_back(crash_key); | 230 keys.push_back(crash_key); |
| 221 } | 231 } |
| 222 } | 232 } |
| 223 | 233 |
| 224 return base::debug::InitCrashKeys(&keys.at(0), keys.size(), | 234 return base::debug::InitCrashKeys(&keys.at(0), keys.size(), |
| 225 kSingleChunkLength); | 235 kSingleChunkLength); |
| 226 } | 236 } |
| 227 | 237 |
| 228 void SetCrashClientIdFromGUID(const std::string& client_guid) { | 238 void SetMetricsClientIdFromGUID(const std::string& metrics_client_guid) { |
| 229 std::string stripped_guid(client_guid); | 239 std::string stripped_guid(metrics_client_guid); |
| 230 // Remove all instance of '-' char from the GUID. So BCD-WXY becomes BCDWXY. | 240 // Remove all instance of '-' char from the GUID. So BCD-WXY becomes BCDWXY. |
| 231 ReplaceSubstringsAfterOffset(&stripped_guid, 0, "-", ""); | 241 ReplaceSubstringsAfterOffset(&stripped_guid, 0, "-", ""); |
| 232 if (stripped_guid.empty()) | 242 if (stripped_guid.empty()) |
| 233 return; | 243 return; |
| 234 | 244 |
| 245 #if defined(OS_MACOSX) |
| 246 // The crash client ID is maintained by Crashpad and is distinct from the |
| 247 // metrics client ID, which is carried in its own key. |
| 248 base::debug::SetCrashKeyValue(kMetricsClientId, stripped_guid); |
| 249 #else |
| 250 // The crash client ID is set by the application when Breakpad is in use. |
| 251 // The same ID as the metrics client ID is used. |
| 235 base::debug::SetCrashKeyValue(kClientId, stripped_guid); | 252 base::debug::SetCrashKeyValue(kClientId, stripped_guid); |
| 253 #endif |
| 254 } |
| 255 |
| 256 void ClearMetricsClientId() { |
| 257 #if defined(OS_MACOSX) |
| 258 // Crashpad always monitors for crashes, but doesn't upload them when |
| 259 // crash reporting is disabled. The preference to upload crash reports is |
| 260 // linked to the preference for metrics reporting. When metrics reporting is |
| 261 // disabled, don't put the metrics client ID into crash dumps. This way, crash |
| 262 // reports that are saved but not uploaded will not have a metrics client ID |
| 263 // from the time that metrics reporting was disabled even if they are uploaded |
| 264 // by user action at a later date. |
| 265 // |
| 266 // Breakpad cannot be enabled or disabled without an application restart, and |
| 267 // it needs to use the metrics client ID as its stable crash client ID, so |
| 268 // leave its client ID intact even when metrics reporting is disabled while |
| 269 // the application is running. |
| 270 base::debug::ClearCrashKey(kMetricsClientId); |
| 271 #endif |
| 236 } | 272 } |
| 237 | 273 |
| 238 static bool IsBoringSwitch(const std::string& flag) { | 274 static bool IsBoringSwitch(const std::string& flag) { |
| 239 #if defined(OS_WIN) | 275 #if defined(OS_WIN) |
| 240 return StartsWithASCII(flag, "--channel=", true) || | 276 return StartsWithASCII(flag, "--channel=", true) || |
| 241 | 277 |
| 242 // No point to including this since we already have a ptype field. | 278 // No point to including this since we already have a ptype field. |
| 243 StartsWithASCII(flag, "--type=", true) || | 279 StartsWithASCII(flag, "--type=", true) || |
| 244 | 280 |
| 245 // Not particularly interesting | 281 // Not particularly interesting |
| 246 StartsWithASCII(flag, "--flash-broker=", true) || | 282 StartsWithASCII(flag, "--flash-broker=", true) || |
| 247 | 283 |
| 248 // Just about everything has this, don't bother. | 284 // Just about everything has this, don't bother. |
| 249 StartsWithASCII(flag, "/prefetch:", true) || | 285 StartsWithASCII(flag, "/prefetch:", true) || |
| 250 | 286 |
| 251 // We handle the plugin path separately since it is usually too big | 287 // We handle the plugin path separately since it is usually too big |
| 252 // to fit in the switches (limited to 63 characters). | 288 // to fit in the switches (limited to 63 characters). |
| 253 StartsWithASCII(flag, "--plugin-path=", true) || | 289 StartsWithASCII(flag, "--plugin-path=", true) || |
| 254 | 290 |
| 255 // This is too big so we end up truncating it anyway. | 291 // This is too big so we end up truncating it anyway. |
| 256 StartsWithASCII(flag, "--force-fieldtrials=", true) || | 292 StartsWithASCII(flag, "--force-fieldtrials=", true) || |
| 257 | 293 |
| 258 // These surround the flags that were added by about:flags, it lets | 294 // These surround the flags that were added by about:flags, it lets |
| 259 // you distinguish which flags were added manually via the command | 295 // you distinguish which flags were added manually via the command |
| 260 // line versus those added through about:flags. For the most part | 296 // line versus those added through about:flags. For the most part |
| 261 // we don't care how an option was enabled, so we strip these. | 297 // we don't care how an option was enabled, so we strip these. |
| 262 // (If you need to know can always look at the PEB). | 298 // (If you need to know can always look at the PEB). |
| 263 flag == "--flag-switches-begin" || | 299 flag == "--flag-switches-begin" || |
| 264 flag == "--flag-switches-end"; | 300 flag == "--flag-switches-end"; |
| 301 #elif defined(OS_MACOSX) |
| 302 // These are carried in their own fields. |
| 303 return StartsWithASCII(flag, "--channel=", true) || |
| 304 StartsWithASCII(flag, "--type=", true) || |
| 305 StartsWithASCII(flag, "--metrics-client-id=", true); |
| 265 #elif defined(OS_CHROMEOS) | 306 #elif defined(OS_CHROMEOS) |
| 266 static const char* const kIgnoreSwitches[] = { | 307 static const char* const kIgnoreSwitches[] = { |
| 267 ::switches::kEnableLogging, | 308 ::switches::kEnableLogging, |
| 268 ::switches::kFlagSwitchesBegin, | 309 ::switches::kFlagSwitchesBegin, |
| 269 ::switches::kFlagSwitchesEnd, | 310 ::switches::kFlagSwitchesEnd, |
| 270 ::switches::kLoggingLevel, | 311 ::switches::kLoggingLevel, |
| 271 ::switches::kPpapiFlashArgs, | 312 ::switches::kPpapiFlashArgs, |
| 272 ::switches::kPpapiFlashPath, | 313 ::switches::kPpapiFlashPath, |
| 273 ::switches::kRegisterPepperPlugins, | 314 ::switches::kRegisterPepperPlugins, |
| 274 ::switches::kUIPrioritizeInGpuProcess, | 315 ::switches::kUIPrioritizeInGpuProcess, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 } | 435 } |
| 395 | 436 |
| 396 ScopedPrinterInfo::~ScopedPrinterInfo() { | 437 ScopedPrinterInfo::~ScopedPrinterInfo() { |
| 397 for (size_t i = 0; i < kPrinterInfoCount; ++i) { | 438 for (size_t i = 0; i < kPrinterInfoCount; ++i) { |
| 398 std::string key = base::StringPrintf(kPrinterInfo, i + 1); | 439 std::string key = base::StringPrintf(kPrinterInfo, i + 1); |
| 399 base::debug::ClearCrashKey(key); | 440 base::debug::ClearCrashKey(key); |
| 400 } | 441 } |
| 401 } | 442 } |
| 402 | 443 |
| 403 } // namespace crash_keys | 444 } // namespace crash_keys |
| OLD | NEW |