| 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 "chrome/installer/setup/installer_crash_reporting.h" | 5 #include "chrome/installer/util/installer_crash_reporting.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/debug/crash_logging.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" | 12 #include "base/strings/string16.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/version.h" | 14 #include "base/version.h" |
| 17 #include "chrome/installer/setup/installer_crash_reporter_client.h" | 15 #include "base/win/registry.h" |
| 18 #include "chrome/installer/util/google_update_settings.h" | 16 #include "chrome/installer/util/google_update_constants.h" |
| 19 #include "chrome/installer/util/installer_state.h" | 17 #include "chrome/installer/util/installer_state.h" |
| 20 #include "components/crash/content/app/breakpad_win.h" | 18 #include "chrome/installer/util/install_util.h" |
| 21 #include "components/crash/content/app/crash_keys_win.h" | |
| 22 #include "components/crash/core/common/crash_keys.h" | 19 #include "components/crash/core/common/crash_keys.h" |
| 23 | 20 |
| 24 namespace installer { | 21 namespace installer { |
| 25 | 22 |
| 26 namespace { | 23 namespace { |
| 27 | 24 |
| 28 // Crash Keys | 25 // Crash Keys |
| 29 | 26 |
| 27 const char kAP[] = "ap"; |
| 28 const char kArchiveType[] = "archive-type"; |
| 30 const char kCurrentVersion[] = "current-version"; | 29 const char kCurrentVersion[] = "current-version"; |
| 31 const char kDistributionType[] = "dist-type"; | 30 const char kDistributionType[] = "dist-type"; |
| 32 const char kIsMultiInstall[] = "multi-install"; | 31 const char kIsMultiInstall[] = "multi-install"; |
| 33 const char kIsSystemLevel[] = "system-level"; | 32 const char kIsSystemLevel[] = "system-level"; |
| 34 const char kOperation[] = "operation"; | 33 const char kOperation[] = "operation"; |
| 34 const char kStage[] = "stage"; |
| 35 const char kStateKey[] = "state-key"; | 35 const char kStateKey[] = "state-key"; |
| 36 | 36 |
| 37 #if defined(COMPONENT_BUILD) | 37 const char *ArchiveTypeToString(ArchiveType archive_type) { |
| 38 // Installed via base::debug::SetCrashKeyReportingFunctions. | 38 switch (archive_type) { |
| 39 void SetCrashKeyValue(const base::StringPiece& key, | 39 case ArchiveType::UNKNOWN_ARCHIVE_TYPE: return "unknown"; |
| 40 const base::StringPiece& value) { | 40 case ArchiveType::FULL_ARCHIVE_TYPE: return "full"; |
| 41 DCHECK(breakpad::CrashKeysWin::keeper()); | 41 case ArchiveType::INCREMENTAL_ARCHIVE_TYPE: return "incremental"; |
| 42 breakpad::CrashKeysWin::keeper()->SetCrashKeyValue(base::UTF8ToUTF16(key), | 42 } |
| 43 base::UTF8ToUTF16(value)); | 43 NOTREACHED(); |
| 44 return ""; |
| 44 } | 45 } |
| 45 | 46 |
| 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) { | 47 const char *DistributionTypeToString(BrowserDistribution::Type type) { |
| 54 switch (type) { | 48 switch (type) { |
| 55 case BrowserDistribution::CHROME_BROWSER: | 49 case BrowserDistribution::CHROME_BROWSER: |
| 56 return "chrome browser"; | 50 return "chrome browser"; |
| 57 case BrowserDistribution::CHROME_FRAME: | 51 case BrowserDistribution::CHROME_FRAME: |
| 58 return "chrome frame"; | 52 return "chrome frame"; |
| 59 case BrowserDistribution::CHROME_BINARIES: | 53 case BrowserDistribution::CHROME_BINARIES: |
| 60 return "chrome binaries"; | 54 return "chrome binaries"; |
| 61 case BrowserDistribution::NUM_TYPES: | 55 case BrowserDistribution::NUM_TYPES: |
| 62 // Fall out of switch. | 56 // Fall out of switch. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 case InstallerState::UNINITIALIZED: | 73 case InstallerState::UNINITIALIZED: |
| 80 // Fall out of switch. | 74 // Fall out of switch. |
| 81 break; | 75 break; |
| 82 } | 76 } |
| 83 NOTREACHED(); | 77 NOTREACHED(); |
| 84 return ""; | 78 return ""; |
| 85 } | 79 } |
| 86 | 80 |
| 87 } // namespace | 81 } // namespace |
| 88 | 82 |
| 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() { | 83 size_t RegisterCrashKeys() { |
| 123 const base::debug::CrashKey kFixedKeys[] = { | 84 const base::debug::CrashKey kFixedKeys[] = { |
| 124 { crash_keys::kClientId, crash_keys::kSmallSize }, | 85 { crash_keys::kClientId, crash_keys::kSmallSize }, |
| 86 { kAP, crash_keys::kSmallSize }, |
| 87 { kArchiveType, crash_keys::kSmallSize }, |
| 125 { kCurrentVersion, crash_keys::kSmallSize }, | 88 { kCurrentVersion, crash_keys::kSmallSize }, |
| 126 { kDistributionType, crash_keys::kSmallSize }, | 89 { kDistributionType, crash_keys::kSmallSize }, |
| 127 { kIsMultiInstall, crash_keys::kSmallSize }, | 90 { kIsMultiInstall, crash_keys::kSmallSize }, |
| 128 { kIsSystemLevel, crash_keys::kSmallSize }, | 91 { kIsSystemLevel, crash_keys::kSmallSize }, |
| 129 { kOperation, crash_keys::kSmallSize }, | 92 { kOperation, crash_keys::kSmallSize }, |
| 93 { kStage, crash_keys::kSmallSize }, |
| 130 | 94 |
| 131 // This is a Windows registry key, which maxes out at 255 chars. | 95 // This is a Windows registry key, which maxes out at 255 chars. |
| 132 // (kMediumSize actually maxes out at 252 chars on Windows, but potentially | 96 // (kMediumSize actually maxes out at 252 chars on Windows, but potentially |
| 133 // truncating such a small amount is a fair tradeoff compared to using | 97 // truncating such a small amount is a fair tradeoff compared to using |
| 134 // kLargeSize, which is wasteful.) | 98 // kLargeSize, which is wasteful.) |
| 135 { kStateKey, crash_keys::kMediumSize }, | 99 { kStateKey, crash_keys::kMediumSize }, |
| 136 }; | 100 }; |
| 137 std::vector<base::debug::CrashKey> keys(std::begin(kFixedKeys), | 101 std::vector<base::debug::CrashKey> keys(std::begin(kFixedKeys), |
| 138 std::end(kFixedKeys)); | 102 std::end(kFixedKeys)); |
| 139 crash_keys::GetCrashKeysForCommandLineSwitches(&keys); | 103 crash_keys::GetCrashKeysForCommandLineSwitches(&keys); |
| 140 return base::debug::InitCrashKeys(keys.data(), keys.size(), | 104 return base::debug::InitCrashKeys(keys.data(), keys.size(), |
| 141 crash_keys::kChunkMaxLength); | 105 crash_keys::kChunkMaxLength); |
| 142 } | 106 } |
| 143 | 107 |
| 144 void SetInitialCrashKeys(const InstallerState& state) { | 108 void SetInitialCrashKeys(const InstallerState& state) { |
| 145 using base::debug::SetCrashKeyValue; | 109 using base::debug::SetCrashKeyValue; |
| 146 | 110 |
| 147 SetCrashKeyValue(kDistributionType, | 111 SetCrashKeyValue(kDistributionType, |
| 148 DistributionTypeToString(state.state_type())); | 112 DistributionTypeToString(state.state_type())); |
| 149 SetCrashKeyValue(kOperation, OperationToString(state.operation())); | 113 SetCrashKeyValue(kOperation, OperationToString(state.operation())); |
| 150 SetCrashKeyValue(kIsMultiInstall, | 114 SetCrashKeyValue(kIsMultiInstall, |
| 151 state.is_multi_install() ? "true" : "false"); | 115 state.is_multi_install() ? "true" : "false"); |
| 152 SetCrashKeyValue(kIsSystemLevel, state.system_install() ? "true" : "false"); | 116 SetCrashKeyValue(kIsSystemLevel, state.system_install() ? "true" : "false"); |
| 153 | 117 |
| 154 const base::string16 state_key = state.state_key(); | 118 const base::string16 state_key = state.state_key(); |
| 155 if (!state_key.empty()) | 119 if (!state_key.empty()) { |
| 156 SetCrashKeyValue(kStateKey, base::UTF16ToUTF8(state_key)); | 120 SetCrashKeyValue(kStateKey, base::UTF16ToUTF8(state_key)); |
| 121 |
| 122 base::win::RegKey key; |
| 123 if (key.Open(state.root_key(), state_key.c_str(), |
| 124 KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { |
| 125 base::string16 ap_value; |
| 126 if (key.ReadValue(google_update::kRegApField, &ap_value) == ERROR_SUCCESS) |
| 127 SetCrashKeyValue(kAP, base::UTF16ToUTF8(ap_value)); |
| 128 } |
| 129 } |
| 157 } | 130 } |
| 158 | 131 |
| 159 void SetCrashKeysFromCommandLine(const base::CommandLine& command_line) { | 132 void SetCrashKeysFromCommandLine(const base::CommandLine& command_line) { |
| 160 crash_keys::SetSwitchesFromCommandLine(command_line, nullptr); | 133 crash_keys::SetSwitchesFromCommandLine(command_line, nullptr); |
| 161 } | 134 } |
| 162 | 135 |
| 163 void SetCurrentVersionCrashKey(const base::Version* current_version) { | 136 void SetCurrentVersionCrashKey(const base::Version* current_version) { |
| 164 if (current_version) { | 137 if (current_version) { |
| 165 base::debug::SetCrashKeyValue(kCurrentVersion, | 138 base::debug::SetCrashKeyValue(kCurrentVersion, |
| 166 current_version->GetString()); | 139 current_version->GetString()); |
| 167 } else { | 140 } else { |
| 168 base::debug::ClearCrashKey(kCurrentVersion); | 141 base::debug::ClearCrashKey(kCurrentVersion); |
| 169 } | 142 } |
| 170 } | 143 } |
| 171 | 144 |
| 145 void SetStageCrashKey(InstallerStage stage) { |
| 146 base::debug::SetCrashKeyValue(kStage, |
| 147 base::UTF16ToUTF8(InstallUtil::StageToString(stage))); |
| 148 } |
| 149 |
| 150 void SetArchiveTypeCrashKey(ArchiveType archive_type) { |
| 151 base::debug::SetCrashKeyValue(kArchiveType, |
| 152 ArchiveTypeToString(archive_type)); |
| 153 } |
| 154 |
| 172 } // namespace installer | 155 } // namespace installer |
| OLD | NEW |