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