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