| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 122 |
| 117 #if defined(KASKO) | 123 #if defined(KASKO) |
| 118 const char kKaskoGuid[] = "kasko-guid"; | 124 const char kKaskoGuid[] = "kasko-guid"; |
| 119 const char kKaskoEquivalentGuid[] = "kasko-equivalent-guid"; | 125 const char kKaskoEquivalentGuid[] = "kasko-equivalent-guid"; |
| 120 #endif | 126 #endif |
| 121 | 127 |
| 122 size_t RegisterChromeCrashKeys() { | 128 size_t RegisterChromeCrashKeys() { |
| 123 // The following keys may be chunked by the underlying crash logging system, | 129 // The following keys may be chunked by the underlying crash logging system, |
| 124 // but ultimately constitute a single key-value pair. | 130 // but ultimately constitute a single key-value pair. |
| 125 base::debug::CrashKey fixed_keys[] = { | 131 base::debug::CrashKey fixed_keys[] = { |
| 132 #if defined(OS_MACOSX) |
| 133 { kMetricsClientId, kSmallSize }, |
| 134 #else |
| 126 { kClientId, kSmallSize }, | 135 { kClientId, kSmallSize }, |
| 136 #endif |
| 127 { kChannel, kSmallSize }, | 137 { kChannel, kSmallSize }, |
| 128 { kActiveURL, kLargeSize }, | 138 { kActiveURL, kLargeSize }, |
| 129 { kNumSwitches, kSmallSize }, | 139 { kNumSwitches, kSmallSize }, |
| 130 { kNumVariations, kSmallSize }, | 140 { kNumVariations, kSmallSize }, |
| 131 { kVariations, kLargeSize }, | 141 { kVariations, kLargeSize }, |
| 132 { kNumExtensionsCount, kSmallSize }, | 142 { kNumExtensionsCount, kSmallSize }, |
| 133 { kShutdownType, kSmallSize }, | 143 { kShutdownType, kSmallSize }, |
| 134 #if !defined(OS_ANDROID) | 144 #if !defined(OS_ANDROID) |
| 135 { kGPUVendorID, kSmallSize }, | 145 { kGPUVendorID, kSmallSize }, |
| 136 { kGPUDeviceID, kSmallSize }, | 146 { kGPUDeviceID, kSmallSize }, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 DCHECK_GT(n, 0); | 237 DCHECK_GT(n, 0); |
| 228 base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize }; | 238 base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize }; |
| 229 keys.push_back(crash_key); | 239 keys.push_back(crash_key); |
| 230 } | 240 } |
| 231 } | 241 } |
| 232 | 242 |
| 233 return base::debug::InitCrashKeys(&keys.at(0), keys.size(), | 243 return base::debug::InitCrashKeys(&keys.at(0), keys.size(), |
| 234 kSingleChunkLength); | 244 kSingleChunkLength); |
| 235 } | 245 } |
| 236 | 246 |
| 237 void SetCrashClientIdFromGUID(const std::string& client_guid) { | 247 void SetMetricsClientIdFromGUID(const std::string& metrics_client_guid) { |
| 238 std::string stripped_guid(client_guid); | 248 std::string stripped_guid(metrics_client_guid); |
| 239 // Remove all instance of '-' char from the GUID. So BCD-WXY becomes BCDWXY. | 249 // Remove all instance of '-' char from the GUID. So BCD-WXY becomes BCDWXY. |
| 240 ReplaceSubstringsAfterOffset(&stripped_guid, 0, "-", ""); | 250 ReplaceSubstringsAfterOffset(&stripped_guid, 0, "-", ""); |
| 241 if (stripped_guid.empty()) | 251 if (stripped_guid.empty()) |
| 242 return; | 252 return; |
| 243 | 253 |
| 254 #if defined(OS_MACOSX) |
| 255 // The crash client ID is maintained by Crashpad and is distinct from the |
| 256 // metrics client ID, which is carried in its own key. |
| 257 base::debug::SetCrashKeyValue(kMetricsClientId, stripped_guid); |
| 258 #else |
| 259 // The crash client ID is set by the application when Breakpad is in use. |
| 260 // The same ID as the metrics client ID is used. |
| 244 base::debug::SetCrashKeyValue(kClientId, stripped_guid); | 261 base::debug::SetCrashKeyValue(kClientId, stripped_guid); |
| 262 #endif |
| 263 } |
| 264 |
| 265 void ClearMetricsClientId() { |
| 266 #if defined(OS_MACOSX) |
| 267 // Crashpad always monitors for crashes, but doesn't upload them when |
| 268 // crash reporting is disabled. The preference to upload crash reports is |
| 269 // linked to the preference for metrics reporting. When metrics reporting is |
| 270 // disabled, don't put the metrics client ID into crash dumps. This way, crash |
| 271 // reports that are saved but not uploaded will not have a metrics client ID |
| 272 // from the time that metrics reporting was disabled even if they are uploaded |
| 273 // by user action at a later date. |
| 274 // |
| 275 // Breakpad cannot be enabled or disabled without an application restart, and |
| 276 // it needs to use the metrics client ID as its stable crash client ID, so |
| 277 // leave its client ID intact even when metrics reporting is disabled while |
| 278 // the application is running. |
| 279 base::debug::ClearCrashKey(kMetricsClientId); |
| 280 #endif |
| 245 } | 281 } |
| 246 | 282 |
| 247 static bool IsBoringSwitch(const std::string& flag) { | 283 static bool IsBoringSwitch(const std::string& flag) { |
| 248 #if defined(OS_WIN) | 284 #if defined(OS_WIN) |
| 249 return StartsWithASCII(flag, "--channel=", true) || | 285 return StartsWithASCII(flag, "--channel=", true) || |
| 250 | 286 |
| 251 // No point to including this since we already have a ptype field. | 287 // No point to including this since we already have a ptype field. |
| 252 StartsWithASCII(flag, "--type=", true) || | 288 StartsWithASCII(flag, "--type=", true) || |
| 253 | 289 |
| 254 // Not particularly interesting | 290 // Not particularly interesting |
| 255 StartsWithASCII(flag, "--flash-broker=", true) || | 291 StartsWithASCII(flag, "--flash-broker=", true) || |
| 256 | 292 |
| 257 // Just about everything has this, don't bother. | 293 // Just about everything has this, don't bother. |
| 258 StartsWithASCII(flag, "/prefetch:", true) || | 294 StartsWithASCII(flag, "/prefetch:", true) || |
| 259 | 295 |
| 260 // We handle the plugin path separately since it is usually too big | 296 // We handle the plugin path separately since it is usually too big |
| 261 // to fit in the switches (limited to 63 characters). | 297 // to fit in the switches (limited to 63 characters). |
| 262 StartsWithASCII(flag, "--plugin-path=", true) || | 298 StartsWithASCII(flag, "--plugin-path=", true) || |
| 263 | 299 |
| 264 // This is too big so we end up truncating it anyway. | 300 // This is too big so we end up truncating it anyway. |
| 265 StartsWithASCII(flag, "--force-fieldtrials=", true) || | 301 StartsWithASCII(flag, "--force-fieldtrials=", true) || |
| 266 | 302 |
| 267 // These surround the flags that were added by about:flags, it lets | 303 // These surround the flags that were added by about:flags, it lets |
| 268 // you distinguish which flags were added manually via the command | 304 // you distinguish which flags were added manually via the command |
| 269 // line versus those added through about:flags. For the most part | 305 // line versus those added through about:flags. For the most part |
| 270 // we don't care how an option was enabled, so we strip these. | 306 // we don't care how an option was enabled, so we strip these. |
| 271 // (If you need to know can always look at the PEB). | 307 // (If you need to know can always look at the PEB). |
| 272 flag == "--flag-switches-begin" || | 308 flag == "--flag-switches-begin" || |
| 273 flag == "--flag-switches-end"; | 309 flag == "--flag-switches-end"; |
| 310 #elif defined(OS_MACOSX) |
| 311 // These are carried in their own fields. |
| 312 return StartsWithASCII(flag, "--channel=", true) || |
| 313 StartsWithASCII(flag, "--type=", true) || |
| 314 StartsWithASCII(flag, "--metrics-client-id=", true); |
| 274 #elif defined(OS_CHROMEOS) | 315 #elif defined(OS_CHROMEOS) |
| 275 static const char* const kIgnoreSwitches[] = { | 316 static const char* const kIgnoreSwitches[] = { |
| 276 ::switches::kEnableLogging, | 317 ::switches::kEnableLogging, |
| 277 ::switches::kFlagSwitchesBegin, | 318 ::switches::kFlagSwitchesBegin, |
| 278 ::switches::kFlagSwitchesEnd, | 319 ::switches::kFlagSwitchesEnd, |
| 279 ::switches::kLoggingLevel, | 320 ::switches::kLoggingLevel, |
| 280 ::switches::kPpapiFlashArgs, | 321 ::switches::kPpapiFlashArgs, |
| 281 ::switches::kPpapiFlashPath, | 322 ::switches::kPpapiFlashPath, |
| 282 ::switches::kRegisterPepperPlugins, | 323 ::switches::kRegisterPepperPlugins, |
| 283 ::switches::kUIPrioritizeInGpuProcess, | 324 ::switches::kUIPrioritizeInGpuProcess, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 } | 444 } |
| 404 | 445 |
| 405 ScopedPrinterInfo::~ScopedPrinterInfo() { | 446 ScopedPrinterInfo::~ScopedPrinterInfo() { |
| 406 for (size_t i = 0; i < kPrinterInfoCount; ++i) { | 447 for (size_t i = 0; i < kPrinterInfoCount; ++i) { |
| 407 std::string key = base::StringPrintf(kPrinterInfo, i + 1); | 448 std::string key = base::StringPrintf(kPrinterInfo, i + 1); |
| 408 base::debug::ClearCrashKey(key); | 449 base::debug::ClearCrashKey(key); |
| 409 } | 450 } |
| 410 } | 451 } |
| 411 | 452 |
| 412 } // namespace crash_keys | 453 } // namespace crash_keys |
| OLD | NEW |