OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/crash_keys/crash_keys.h" |
| 6 |
| 7 #include "base/debug/crash_logging.h" |
| 8 #include "base/format_macros.h" |
| 9 #include "base/strings/string_piece.h" |
| 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" |
| 12 |
| 13 namespace crash_keys { |
| 14 |
| 15 #if defined(OS_MACOSX) |
| 16 // Crashpad owns the "guid" key. Chrome's metrics client ID is a separate ID |
| 17 // carried in a distinct "metrics_client_id" field. |
| 18 const char kMetricsClientId[] = "metrics_client_id"; |
| 19 #else |
| 20 const char kClientId[] = "guid"; |
| 21 #endif |
| 22 |
| 23 const char kChannel[] = "channel"; |
| 24 |
| 25 const char kNumVariations[] = "num-experiments"; |
| 26 const char kVariations[] = "variations"; |
| 27 |
| 28 #if defined(OS_MACOSX) |
| 29 namespace mac { |
| 30 |
| 31 const char kZombie[] = "zombie"; |
| 32 const char kZombieTrace[] = "zombie_dealloc_bt"; |
| 33 |
| 34 } // namespace mac |
| 35 #endif |
| 36 |
| 37 void SetMetricsClientIdFromGUID(const std::string& metrics_client_guid) { |
| 38 std::string stripped_guid(metrics_client_guid); |
| 39 // Remove all instance of '-' char from the GUID. So BCD-WXY becomes BCDWXY. |
| 40 base::ReplaceSubstringsAfterOffset( |
| 41 &stripped_guid, 0, "-", base::StringPiece()); |
| 42 if (stripped_guid.empty()) |
| 43 return; |
| 44 |
| 45 #if defined(OS_MACOSX) |
| 46 // The crash client ID is maintained by Crashpad and is distinct from the |
| 47 // metrics client ID, which is carried in its own key. |
| 48 base::debug::SetCrashKeyValue(kMetricsClientId, stripped_guid); |
| 49 #else |
| 50 // The crash client ID is set by the application when Breakpad is in use. |
| 51 // The same ID as the metrics client ID is used. |
| 52 base::debug::SetCrashKeyValue(kClientId, stripped_guid); |
| 53 #endif |
| 54 } |
| 55 |
| 56 void ClearMetricsClientId() { |
| 57 #if defined(OS_MACOSX) |
| 58 // Crashpad always monitors for crashes, but doesn't upload them when |
| 59 // crash reporting is disabled. The preference to upload crash reports is |
| 60 // linked to the preference for metrics reporting. When metrics reporting is |
| 61 // disabled, don't put the metrics client ID into crash dumps. This way, crash |
| 62 // reports that are saved but not uploaded will not have a metrics client ID |
| 63 // from the time that metrics reporting was disabled even if they are uploaded |
| 64 // by user action at a later date. |
| 65 // |
| 66 // Breakpad cannot be enabled or disabled without an application restart, and |
| 67 // it needs to use the metrics client ID as its stable crash client ID, so |
| 68 // leave its client ID intact even when metrics reporting is disabled while |
| 69 // the application is running. |
| 70 base::debug::ClearCrashKey(kMetricsClientId); |
| 71 #endif |
| 72 } |
| 73 |
| 74 void SetVariationsList(const std::vector<std::string>& variations) { |
| 75 base::debug::SetCrashKeyValue(kNumVariations, |
| 76 base::StringPrintf("%" PRIuS, variations.size())); |
| 77 |
| 78 std::string variations_string; |
| 79 variations_string.reserve(kLargeSize); |
| 80 |
| 81 for (size_t i = 0; i < variations.size(); ++i) { |
| 82 const std::string& variation = variations[i]; |
| 83 // Do not truncate an individual experiment. |
| 84 if (variations_string.size() + variation.size() >= kLargeSize) |
| 85 break; |
| 86 variations_string += variation; |
| 87 variations_string += ","; |
| 88 } |
| 89 |
| 90 base::debug::SetCrashKeyValue(kVariations, variations_string); |
| 91 } |
| 92 |
| 93 } // namespace crash_keys |
OLD | NEW |