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"; |
19 #else | 27 #else |
20 const char kClientId[] = "guid"; | 28 const char kClientId[] = "guid"; |
21 #endif | 29 #endif |
22 | 30 |
23 const char kChannel[] = "channel"; | 31 const char kChannel[] = "channel"; |
24 | 32 |
25 const char kNumVariations[] = "num-experiments"; | 33 const char kNumVariations[] = "num-experiments"; |
26 const char kVariations[] = "variations"; | 34 const char kVariations[] = "variations"; |
27 | 35 |
28 const char kBug464926CrashKey[] = "bug-464926-info"; | 36 const char kBug464926CrashKey[] = "bug-464926-info"; |
29 | 37 |
30 #if defined(OS_MACOSX) | 38 #if defined(OS_MACOSX) |
31 namespace mac { | 39 namespace mac { |
32 | 40 |
33 const char kZombie[] = "zombie"; | 41 const char kZombie[] = "zombie"; |
34 const char kZombieTrace[] = "zombie_dealloc_bt"; | 42 const char kZombieTrace[] = "zombie_dealloc_bt"; |
35 | 43 |
36 } // namespace mac | 44 } // namespace mac |
37 #endif | 45 #endif |
38 | 46 |
39 void SetMetricsClientIdFromGUID(const std::string& metrics_client_guid) { | 47 void SetMetricsClientIdFromGUID(const std::string& metrics_client_guid) { |
40 std::string stripped_guid(metrics_client_guid); | 48 std::string stripped_guid(metrics_client_guid); |
41 // Remove all instance of '-' char from the GUID. So BCD-WXY becomes BCDWXY. | 49 // Remove all instance of '-' char from the GUID. So BCD-WXY becomes BCDWXY. |
42 base::ReplaceSubstringsAfterOffset( | 50 base::ReplaceSubstringsAfterOffset( |
43 &stripped_guid, 0, "-", base::StringPiece()); | 51 &stripped_guid, 0, "-", base::StringPiece()); |
44 if (stripped_guid.empty()) | 52 if (stripped_guid.empty()) |
45 return; | 53 return; |
46 | 54 |
47 #if defined(OS_MACOSX) | 55 #if defined(OS_MACOSX) || defined(OS_WIN) |
48 // The crash client ID is maintained by Crashpad and is distinct from the | 56 // The crash client ID is maintained by Crashpad and is distinct from the |
49 // metrics client ID, which is carried in its own key. | 57 // metrics client ID, which is carried in its own key. |
50 base::debug::SetCrashKeyValue(kMetricsClientId, stripped_guid); | 58 base::debug::SetCrashKeyValue(kMetricsClientId, stripped_guid); |
51 #else | 59 #else |
52 // The crash client ID is set by the application when Breakpad is in use. | 60 // The crash client ID is set by the application when Breakpad is in use. |
53 // The same ID as the metrics client ID is used. | 61 // The same ID as the metrics client ID is used. |
54 base::debug::SetCrashKeyValue(kClientId, stripped_guid); | 62 base::debug::SetCrashKeyValue(kClientId, stripped_guid); |
55 #endif | 63 #endif |
56 } | 64 } |
57 | 65 |
58 void ClearMetricsClientId() { | 66 void ClearMetricsClientId() { |
59 #if defined(OS_MACOSX) | 67 #if defined(OS_MACOSX) || defined(OS_WIN) |
60 // Crashpad always monitors for crashes, but doesn't upload them when | 68 // Crashpad always monitors for crashes, but doesn't upload them when |
61 // crash reporting is disabled. The preference to upload crash reports is | 69 // crash reporting is disabled. The preference to upload crash reports is |
62 // linked to the preference for metrics reporting. When metrics reporting is | 70 // linked to the preference for metrics reporting. When metrics reporting is |
63 // disabled, don't put the metrics client ID into crash dumps. This way, crash | 71 // disabled, don't put the metrics client ID into crash dumps. This way, crash |
64 // reports that are saved but not uploaded will not have a metrics client ID | 72 // reports that are saved but not uploaded will not have a metrics client ID |
65 // from the time that metrics reporting was disabled even if they are uploaded | 73 // from the time that metrics reporting was disabled even if they are uploaded |
66 // by user action at a later date. | 74 // by user action at a later date. |
67 // | 75 // |
68 // Breakpad cannot be enabled or disabled without an application restart, and | 76 // Breakpad cannot be enabled or disabled without an application restart, and |
69 // it needs to use the metrics client ID as its stable crash client ID, so | 77 // it needs to use the metrics client ID as its stable crash client ID, so |
(...skipping 16 matching lines...) Expand all Loading... |
86 if (variations_string.size() + variation.size() >= kLargeSize) | 94 if (variations_string.size() + variation.size() >= kLargeSize) |
87 break; | 95 break; |
88 variations_string += variation; | 96 variations_string += variation; |
89 variations_string += ","; | 97 variations_string += ","; |
90 } | 98 } |
91 | 99 |
92 base::debug::SetCrashKeyValue(kVariations, variations_string); | 100 base::debug::SetCrashKeyValue(kVariations, variations_string); |
93 } | 101 } |
94 | 102 |
95 } // namespace crash_keys | 103 } // namespace crash_keys |
OLD | NEW |