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 "chrome/installer/setup/installer_crash_keys.h" | |
6 | |
7 #include "base/debug/leak_annotations.h" | |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "chrome/installer/setup/installer_crash_reporter_client.h" | |
10 #include "chrome/installer/util/google_update_settings.h" | |
11 #include "chrome/installer/util/installer_state.h" | |
12 #include "components/crash/content/app/breakpad_win.h" | |
13 #include "components/crash/content/app/crash_keys_win.h" | |
14 #include "components/crash/core/common/crash_keys.h" | |
15 | |
16 namespace installer { | |
17 | |
18 namespace { | |
19 | |
20 // Crash Keys | |
21 | |
22 const char kDistributionType[] = "dist-type"; | |
23 const char kIsMultiInstall[] = "multi-install"; | |
24 const char kIsSystemLevel[] = "system-level"; | |
25 const char kOperation[] = "operation"; | |
26 const char kStateKey[] = "state-key"; | |
27 | |
28 #if defined(COMPONENT_BUILD) | |
29 // Installed via base::debug::SetCrashKeyReportingFunctions. | |
30 void SetCrashKeyValue(const base::StringPiece& key, | |
31 const base::StringPiece& value) { | |
32 DCHECK(breakpad::CrashKeysWin::keeper()); | |
33 breakpad::CrashKeysWin::keeper()->SetCrashKeyValue(base::UTF8ToUTF16(key), | |
34 base::UTF8ToUTF16(value)); | |
35 } | |
36 | |
37 // Installed via base::debug::SetCrashKeyReportingFunctions. | |
38 void ClearCrashKey(const base::StringPiece& key) { | |
39 DCHECK(breakpad::CrashKeysWin::keeper()); | |
40 breakpad::CrashKeysWin::keeper()->ClearCrashKeyValue(base::UTF8ToUTF16(key)); | |
41 } | |
42 #endif // COMPONENT_BUILD | |
43 | |
44 const char *DistributionTypeToString(BrowserDistribution::Type type) { | |
45 switch (type) { | |
46 case BrowserDistribution::CHROME_BROWSER: | |
47 return "chrome browser"; | |
48 case BrowserDistribution::CHROME_FRAME: | |
49 return "chrome frame"; | |
50 case BrowserDistribution::CHROME_BINARIES: | |
51 return "chrome binaries"; | |
52 case BrowserDistribution::NUM_TYPES: | |
53 // Fall out of switch. | |
54 break; | |
55 } | |
56 NOTREACHED(); | |
57 return ""; | |
58 } | |
59 | |
60 const char *OperationToString(InstallerState::Operation operation) { | |
61 switch (operation) { | |
62 case InstallerState::SINGLE_INSTALL_OR_UPDATE: | |
63 return "single-install-or-update"; | |
64 case InstallerState::MULTI_INSTALL: | |
65 return "multi-install"; | |
66 case InstallerState::MULTI_UPDATE: | |
67 return "multi-update"; | |
68 case InstallerState::UNINSTALL: | |
69 return "uninstall"; | |
70 case InstallerState::UNINITIALIZED: | |
71 // Fall out of switch. | |
72 break; | |
73 } | |
74 NOTREACHED(); | |
75 return ""; | |
76 } | |
77 | |
78 const char *PackageTypeToString(InstallerState::PackageType type) { | |
79 // Returns a boolean string: is this a multi install? | |
80 switch (type) { | |
81 case InstallerState::SINGLE_PACKAGE: | |
82 return "false"; | |
83 case InstallerState::MULTI_PACKAGE: | |
84 return "true"; | |
85 case InstallerState::UNKNOWN_PACKAGE_TYPE: | |
86 // Fall out of switch. | |
87 break; | |
88 } | |
89 NOTREACHED(); | |
90 return ""; | |
91 } | |
92 | |
93 const char *SystemLevelToString(InstallerState::Level type) { | |
94 // Returns a boolean string: is this a system level install? | |
95 switch (type) { | |
96 case InstallerState::USER_LEVEL: | |
97 return "false"; | |
98 case InstallerState::SYSTEM_LEVEL: | |
99 return "true"; | |
100 case InstallerState::UNKNOWN_LEVEL: | |
101 // Fall out of switch. | |
102 break; | |
103 } | |
104 NOTREACHED(); | |
105 return ""; | |
106 } | |
107 | |
108 } // namespace | |
109 | |
110 void ConfigureCrashReporting(const InstallerState& installer_state) { | |
grt (UTC plus 2)
2015/11/26 19:24:45
this does a lot more than just operate on/for cras
Joe Mason
2015/11/26 19:47:02
What about just renaming installer_crash_keys.* to
grt (UTC plus 2)
2015/11/26 19:50:35
Ack.
| |
111 // This is inspired by work done in various parts of Chrome startup to connect | |
112 // to the crash service. Since the installer does not split its work between | |
113 // a stub .exe and a main .dll, crash reporting can be configured in one place | |
114 // right here. | |
115 | |
116 // Create the crash client and install it (a la MainDllLoader::Launch). | |
117 InstallerCrashReporterClient *crash_client = | |
118 new InstallerCrashReporterClient(!installer_state.system_install()); | |
119 ANNOTATE_LEAKING_OBJECT_PTR(crash_client); | |
120 crash_reporter::SetCrashReporterClient(crash_client); | |
121 | |
122 breakpad::InitCrashReporter("Chrome Installer"); | |
123 | |
124 // Set up crash keys and the client id (a la child_process_logging::Init()). | |
125 #if defined(COMPONENT_BUILD) | |
126 // breakpad::InitCrashReporter takes care of this for static builds but not | |
127 // component builds due to intricacies of chrome.exe and chrome.dll sharing a | |
128 // copy of base.dll in that case (for details, see the comment in | |
129 // components/crash/content/app/breakpad_win.cc). | |
130 crash_client->RegisterCrashKeys(); | |
131 base::debug::SetCrashKeyReportingFunctions(&SetCrashKeyValue, &ClearCrashKey); | |
132 #endif // COMPONENT_BUILD | |
133 | |
134 scoped_ptr<metrics::ClientInfo> client_info = | |
135 GoogleUpdateSettings::LoadMetricsClientInfo(); | |
136 if (client_info) | |
137 crash_client->SetCrashReporterClientIdFromGUID(client_info->client_id); | |
138 // TODO(grt): A lack of a client_id at this point generally means that Chrome | |
139 // has yet to have been launched and picked one. Consider creating it and | |
140 // setting it here for Chrome to use. | |
141 } | |
142 | |
143 void RegisterCrashKeys(std::vector<base::debug::CrashKey>& keys) { | |
grt (UTC plus 2)
2015/11/26 19:24:45
out params must be passed by non-const pointer rat
Joe Mason
2015/11/26 20:49:05
Done.
| |
144 const base::debug::CrashKey kFixedKeys[] = { | |
145 { crash_keys::kClientId, crash_keys::kSmallSize }, | |
146 { kDistributionType, crash_keys::kSmallSize }, | |
147 { kIsMultiInstall, crash_keys::kSmallSize }, | |
148 { kIsSystemLevel, crash_keys::kSmallSize }, | |
149 { kOperation, crash_keys::kSmallSize }, | |
150 | |
151 // This is a Windows registry key, which maxes out at 255 chars. | |
152 // (kMediumSize actually maxes out at 252 chars on Windows, but potentially | |
153 // truncating such a small amount is a fair tradeoff compared to using | |
154 // kLargeSize, which is wasteful.) | |
155 { kStateKey, crash_keys::kMediumSize }, | |
156 }; | |
157 keys.insert(keys.end(), std::begin(kFixedKeys), std::end(kFixedKeys)); | |
grt (UTC plus 2)
2015/11/26 19:24:45
go c++11!
| |
158 } | |
159 | |
160 void SetStartingCrashKeys(const InstallerState& installer_state) { | |
161 base::debug::SetCrashKeyValue(kDistributionType, DistributionTypeToString( | |
grt (UTC plus 2)
2015/11/26 19:24:45
consider "using base::debug::SetCrashKeyValue;" at
Joe Mason
2015/11/26 20:49:05
Done.
| |
162 installer_state.state_type())); | |
163 base::debug::SetCrashKeyValue(kOperation, OperationToString( | |
164 installer_state.operation())); | |
165 base::debug::SetCrashKeyValue(kIsMultiInstall, PackageTypeToString( | |
grt (UTC plus 2)
2015/11/26 19:24:45
nit: the following is easier to read:
installer_st
Joe Mason
2015/11/26 19:47:02
I agree, but I'm following the comment in Installe
grt (UTC plus 2)
2015/11/26 19:50:35
As the author of that comment, I authorize you to
Joe Mason
2015/11/26 20:49:05
Done.
| |
166 installer_state.package_type())); | |
167 base::debug::SetCrashKeyValue(kIsSystemLevel, SystemLevelToString( | |
grt (UTC plus 2)
2015/11/26 19:24:45
installer_state.system_install() ? "true" : "false
Joe Mason
2015/11/26 20:49:05
Done.
| |
168 installer_state.level())); | |
169 | |
170 const std::wstring state_key = installer_state.state_key(); | |
171 if (!state_key.empty()) { | |
grt (UTC plus 2)
2015/11/26 19:24:45
formatting nit:
if (!state_key.empty())
base
Joe Mason
2015/11/26 20:49:05
Done.
(You're talking about the extra line break,
grt (UTC plus 2)
2015/11/26 21:37:17
By and large, Chromium does not use them for singl
| |
172 base::debug::SetCrashKeyValue(kStateKey, | |
173 base::UTF16ToUTF8(state_key)); | |
174 } | |
175 } | |
176 | |
177 } // namespace installer | |
OLD | NEW |