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