OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/crash/core/common/crash_keys.h" | 5 #include "components/crash/core/common/crash_keys.h" |
6 | 6 |
7 #include "base/debug/crash_logging.h" | 7 #include "base/debug/crash_logging.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 | 12 |
13 namespace crash_keys { | 13 namespace crash_keys { |
14 | 14 |
15 #if defined(OS_MACOSX) | 15 #if defined(OS_MACOSX) |
16 // Crashpad owns the "guid" key. Chrome's metrics client ID is a separate ID | 16 // Crashpad owns the "guid" key. Chrome's metrics client ID is a separate ID |
17 // carried in a distinct "metrics_client_id" field. | 17 // carried in a distinct "metrics_client_id" field. |
18 const char kMetricsClientId[] = "metrics_client_id"; | 18 const char kMetricsClientId[] = "metrics_client_id"; |
19 #elif defined(OS_WIN) | |
20 // TODO(scottmg): While transitioning to Crashpad, there are some executables | |
21 // that use Crashpad (which use kMetricsClientId), and some that use Breakpad | |
22 // (kClientId), and they both use this file. For now we define both, but once | |
23 // Breakpad is no longer used on Windows, we will no longer need kClientId, and | |
24 // this can be combined with the OS_MACOSX block above. | |
25 const char kMetricsClientId[] = "metrics_client_id"; | |
26 const char kClientId[] = "guid"; | |
27 #else | 19 #else |
28 const char kClientId[] = "guid"; | 20 const char kClientId[] = "guid"; |
29 #endif | 21 #endif |
30 | 22 |
31 const char kChannel[] = "channel"; | 23 const char kChannel[] = "channel"; |
32 | 24 |
33 const char kNumVariations[] = "num-experiments"; | 25 const char kNumVariations[] = "num-experiments"; |
34 const char kVariations[] = "variations"; | 26 const char kVariations[] = "variations"; |
35 | 27 |
36 const char kBug464926CrashKey[] = "bug-464926-info"; | 28 const char kBug464926CrashKey[] = "bug-464926-info"; |
37 | 29 |
38 #if defined(OS_MACOSX) | 30 #if defined(OS_MACOSX) |
39 namespace mac { | 31 namespace mac { |
40 | 32 |
41 const char kZombie[] = "zombie"; | 33 const char kZombie[] = "zombie"; |
42 const char kZombieTrace[] = "zombie_dealloc_bt"; | 34 const char kZombieTrace[] = "zombie_dealloc_bt"; |
43 | 35 |
44 } // namespace mac | 36 } // namespace mac |
45 #endif | 37 #endif |
46 | 38 |
47 void SetMetricsClientIdFromGUID(const std::string& metrics_client_guid) { | 39 void SetMetricsClientIdFromGUID(const std::string& metrics_client_guid) { |
48 std::string stripped_guid(metrics_client_guid); | 40 std::string stripped_guid(metrics_client_guid); |
49 // Remove all instance of '-' char from the GUID. So BCD-WXY becomes BCDWXY. | 41 // Remove all instance of '-' char from the GUID. So BCD-WXY becomes BCDWXY. |
50 base::ReplaceSubstringsAfterOffset( | 42 base::ReplaceSubstringsAfterOffset( |
51 &stripped_guid, 0, "-", base::StringPiece()); | 43 &stripped_guid, 0, "-", base::StringPiece()); |
52 if (stripped_guid.empty()) | 44 if (stripped_guid.empty()) |
53 return; | 45 return; |
54 | 46 |
55 #if defined(OS_MACOSX) || defined(OS_WIN) | 47 #if defined(OS_MACOSX) |
56 // The crash client ID is maintained by Crashpad and is distinct from the | 48 // The crash client ID is maintained by Crashpad and is distinct from the |
57 // metrics client ID, which is carried in its own key. | 49 // metrics client ID, which is carried in its own key. |
58 base::debug::SetCrashKeyValue(kMetricsClientId, stripped_guid); | 50 base::debug::SetCrashKeyValue(kMetricsClientId, stripped_guid); |
59 #else | 51 #else |
60 // The crash client ID is set by the application when Breakpad is in use. | 52 // The crash client ID is set by the application when Breakpad is in use. |
61 // The same ID as the metrics client ID is used. | 53 // The same ID as the metrics client ID is used. |
62 base::debug::SetCrashKeyValue(kClientId, stripped_guid); | 54 base::debug::SetCrashKeyValue(kClientId, stripped_guid); |
63 #endif | 55 #endif |
64 } | 56 } |
65 | 57 |
66 void ClearMetricsClientId() { | 58 void ClearMetricsClientId() { |
67 #if defined(OS_MACOSX) || defined(OS_WIN) | 59 #if defined(OS_MACOSX) |
68 // Crashpad always monitors for crashes, but doesn't upload them when | 60 // Crashpad always monitors for crashes, but doesn't upload them when |
69 // crash reporting is disabled. The preference to upload crash reports is | 61 // crash reporting is disabled. The preference to upload crash reports is |
70 // linked to the preference for metrics reporting. When metrics reporting is | 62 // linked to the preference for metrics reporting. When metrics reporting is |
71 // disabled, don't put the metrics client ID into crash dumps. This way, crash | 63 // disabled, don't put the metrics client ID into crash dumps. This way, crash |
72 // reports that are saved but not uploaded will not have a metrics client ID | 64 // reports that are saved but not uploaded will not have a metrics client ID |
73 // from the time that metrics reporting was disabled even if they are uploaded | 65 // from the time that metrics reporting was disabled even if they are uploaded |
74 // by user action at a later date. | 66 // by user action at a later date. |
75 // | 67 // |
76 // Breakpad cannot be enabled or disabled without an application restart, and | 68 // Breakpad cannot be enabled or disabled without an application restart, and |
77 // it needs to use the metrics client ID as its stable crash client ID, so | 69 // it needs to use the metrics client ID as its stable crash client ID, so |
(...skipping 16 matching lines...) Expand all Loading... |
94 if (variations_string.size() + variation.size() >= kLargeSize) | 86 if (variations_string.size() + variation.size() >= kLargeSize) |
95 break; | 87 break; |
96 variations_string += variation; | 88 variations_string += variation; |
97 variations_string += ","; | 89 variations_string += ","; |
98 } | 90 } |
99 | 91 |
100 base::debug::SetCrashKeyValue(kVariations, variations_string); | 92 base::debug::SetCrashKeyValue(kVariations, variations_string); |
101 } | 93 } |
102 | 94 |
103 } // namespace crash_keys | 95 } // namespace crash_keys |
OLD | NEW |