Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/installer/setup/installer_crash_reporting.cc

Issue 1475643004: Add crash keys for the installer covering simple InstallerState fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_reporting.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());
grt (UTC plus 2) 2015/11/26 21:37:18 #include "base/logging.h"
Joe Mason 2015/11/26 22:28:54 Done.
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 } // namespace
79
80 void ConfigureCrashReporting(const InstallerState& installer_state) {
81 // This is inspired by work done in various parts of Chrome startup to connect
82 // to the crash service. Since the installer does not split its work between
83 // a stub .exe and a main .dll, crash reporting can be configured in one place
84 // right here.
85
86 // Create the crash client and install it (a la MainDllLoader::Launch).
87 InstallerCrashReporterClient *crash_client =
88 new InstallerCrashReporterClient(!installer_state.system_install());
89 ANNOTATE_LEAKING_OBJECT_PTR(crash_client);
90 crash_reporter::SetCrashReporterClient(crash_client);
91
92 breakpad::InitCrashReporter("Chrome Installer");
93
94 // Set up crash keys and the client id (a la child_process_logging::Init()).
95 #if defined(COMPONENT_BUILD)
96 // breakpad::InitCrashReporter takes care of this for static builds but not
97 // component builds due to intricacies of chrome.exe and chrome.dll sharing a
98 // copy of base.dll in that case (for details, see the comment in
99 // components/crash/content/app/breakpad_win.cc).
100 crash_client->RegisterCrashKeys();
101 base::debug::SetCrashKeyReportingFunctions(&SetCrashKeyValue, &ClearCrashKey);
102 #endif // COMPONENT_BUILD
103
104 scoped_ptr<metrics::ClientInfo> client_info =
105 GoogleUpdateSettings::LoadMetricsClientInfo();
106 if (client_info)
107 crash_client->SetCrashReporterClientIdFromGUID(client_info->client_id);
108 // TODO(grt): A lack of a client_id at this point generally means that Chrome
109 // has yet to have been launched and picked one. Consider creating it and
110 // setting it here for Chrome to use.
111 }
112
113 void GetCrashKeys(std::vector<base::debug::CrashKey>* keys) {
114 const base::debug::CrashKey kFixedKeys[] = {
115 { crash_keys::kClientId, crash_keys::kSmallSize },
116 { kDistributionType, crash_keys::kSmallSize },
117 { kIsMultiInstall, crash_keys::kSmallSize },
118 { kIsSystemLevel, crash_keys::kSmallSize },
119 { kOperation, crash_keys::kSmallSize },
120
121 // This is a Windows registry key, which maxes out at 255 chars.
122 // (kMediumSize actually maxes out at 252 chars on Windows, but potentially
123 // truncating such a small amount is a fair tradeoff compared to using
124 // kLargeSize, which is wasteful.)
125 { kStateKey, crash_keys::kMediumSize },
126 };
127 DCHECK(keys);
grt (UTC plus 2) 2015/11/26 21:37:17 checking arguments like this should be the first t
Joe Mason 2015/11/26 22:28:54 Done.
128 if (!keys)
grt (UTC plus 2) 2015/11/26 21:37:18 don't try to handle DCHECK failures (https://www.c
Joe Mason 2015/11/26 22:28:54 Done.
129 return;
130 keys->insert(keys->end(), std::begin(kFixedKeys), std::end(kFixedKeys));
131 }
132
133 void SetInitialCrashKeys(const InstallerState& state) {
134 using base::debug::SetCrashKeyValue;
135
136 SetCrashKeyValue(kDistributionType,
137 DistributionTypeToString(state.state_type()));
138 SetCrashKeyValue(kOperation, OperationToString(state.operation()));
139 SetCrashKeyValue(kIsMultiInstall,
140 state.is_multi_install() ? "true" : "false");
141 SetCrashKeyValue(kIsSystemLevel, state.system_install() ? "true" : "false");
142
143 const std::wstring state_key = state.state_key();
144 if (!state_key.empty()) {
145 SetCrashKeyValue(kStateKey, base::UTF16ToUTF8(state_key));
146 }
147 }
148
149 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698