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

Side by Side Diff: chrome/app/chrome_crash_reporter_client_win.cc

Issue 1963373003: Revert of Remove dependencies on chrome\installer from the ChromeCrashReporterClient class on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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
« no previous file with comments | « chrome/app/DEPS ('k') | chrome/chrome_dll.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // TODO(ananta/scottmg) 4
5 // Add test coverage for Crashpad.
6 #include "chrome/app/chrome_crash_reporter_client_win.h" 5 #include "chrome/app/chrome_crash_reporter_client_win.h"
7 6
8 #include <windows.h> 7 #include <windows.h>
9 8
10 #include <memory> 9 #include <memory>
11 #include <string>
12 10
13 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/environment.h"
13 #include "base/file_version_info.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/version.h" 19 #include "base/win/registry.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/chrome_paths_internal.h"
21 #include "chrome/common/chrome_result_codes.h" 23 #include "chrome/common/chrome_result_codes.h"
22 #include "chrome/common/crash_keys.h" 24 #include "chrome/common/crash_keys.h"
23 #include "chrome/common/env_vars.h" 25 #include "chrome/common/env_vars.h"
24 #include "chrome/install_static/install_util.h" 26 #include "chrome/common/metrics_constants_util_win.h"
27 #include "chrome/installer/util/google_chrome_sxs_distribution.h"
28 #include "chrome/installer/util/google_update_settings.h"
29 #include "chrome/installer/util/install_util.h"
30 #include "chrome/installer/util/util_constants.h"
25 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
32 #include "policy/policy_constants.h"
33
26 34
27 namespace { 35 namespace {
28 36
29 // This is the minimum version of google update that is required for deferred 37 // This is the minimum version of google update that is required for deferred
30 // crash uploads to work. 38 // crash uploads to work.
31 const char kMinUpdateVersion[] = "1.3.21.115"; 39 const char kMinUpdateVersion[] = "1.3.21.115";
32 40
33 } // namespace 41 } // namespace
34 42
35 ChromeCrashReporterClient::ChromeCrashReporterClient() {} 43 ChromeCrashReporterClient::ChromeCrashReporterClient() {}
36 44
37 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} 45 ChromeCrashReporterClient::~ChromeCrashReporterClient() {}
38 46
39 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( 47 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation(
40 base::FilePath* crash_dir) { 48 base::FilePath* crash_dir) {
41 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate 49 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
42 // location to write breakpad crash dumps can be set. 50 // location to write breakpad crash dumps can be set.
43 std::string alternate_crash_dump_location = 51 std::unique_ptr<base::Environment> env(base::Environment::Create());
44 install_static::GetEnvironmentString("BREAKPAD_DUMP_LOCATION"); 52 std::string alternate_crash_dump_location;
45 if (!alternate_crash_dump_location.empty()) { 53 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) {
46 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); 54 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location);
47 return true; 55 return true;
48 } 56 }
57
49 return false; 58 return false;
50 } 59 }
51 60
52 void ChromeCrashReporterClient::GetProductNameAndVersion( 61 void ChromeCrashReporterClient::GetProductNameAndVersion(
53 const base::FilePath& exe_path, 62 const base::FilePath& exe_path,
54 base::string16* product_name, 63 base::string16* product_name,
55 base::string16* version, 64 base::string16* version,
56 base::string16* special_build, 65 base::string16* special_build,
57 base::string16* channel_name) { 66 base::string16* channel_name) {
58 DCHECK(product_name); 67 DCHECK(product_name);
59 DCHECK(version); 68 DCHECK(version);
60 DCHECK(special_build); 69 DCHECK(special_build);
61 DCHECK(channel_name); 70 DCHECK(channel_name);
62 71
63 install_static::GetExecutableVersionDetails( 72 std::unique_ptr<FileVersionInfo> version_info(
64 exe_path.value(), product_name, version, special_build, channel_name); 73 FileVersionInfo::CreateFileVersionInfo(exe_path));
74
75 if (version_info.get()) {
76 // Get the information from the file.
77 *version = version_info->product_version();
78 if (!version_info->is_official_build())
79 version->append(base::ASCIIToUTF16("-devel"));
80
81 *product_name = version_info->product_short_name();
82 *special_build = version_info->special_build();
83 } else {
84 // No version info found. Make up the values.
85 *product_name = base::ASCIIToUTF16("Chrome");
86 *version = base::ASCIIToUTF16("0.0.0.0-devel");
87 }
88
89 GoogleUpdateSettings::GetChromeChannelAndModifiers(
90 !GetIsPerUserInstall(exe_path), channel_name);
65 } 91 }
66 92
67 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, 93 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title,
68 base::string16* message, 94 base::string16* message,
69 bool* is_rtl_locale) { 95 bool* is_rtl_locale) {
70 if (!install_static::HasEnvironmentVariable(env_vars::kShowRestart) || 96 std::unique_ptr<base::Environment> env(base::Environment::Create());
71 !install_static::HasEnvironmentVariable(env_vars::kRestartInfo) || 97 if (!env->HasVar(env_vars::kShowRestart) ||
72 install_static::HasEnvironmentVariable(env_vars::kMetroConnected)) { 98 !env->HasVar(env_vars::kRestartInfo) ||
99 env->HasVar(env_vars::kMetroConnected)) {
73 return false; 100 return false;
74 } 101 }
75 102
76 std::string restart_info = 103 std::string restart_info;
77 install_static::GetEnvironmentString(env_vars::kRestartInfo); 104 env->GetVar(env_vars::kRestartInfo, &restart_info);
78 105
79 // The CHROME_RESTART var contains the dialog strings separated by '|'. 106 // The CHROME_RESTART var contains the dialog strings separated by '|'.
80 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() 107 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment()
81 // for details. 108 // for details.
82 std::vector<std::string> dlg_strings = base::SplitString( 109 std::vector<std::string> dlg_strings = base::SplitString(
83 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 110 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
84 111
85 if (dlg_strings.size() < 3) 112 if (dlg_strings.size() < 3)
86 return false; 113 return false;
87 114
88 *title = base::UTF8ToUTF16(dlg_strings[0]); 115 *title = base::UTF8ToUTF16(dlg_strings[0]);
89 *message = base::UTF8ToUTF16(dlg_strings[1]); 116 *message = base::UTF8ToUTF16(dlg_strings[1]);
90 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale; 117 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale;
91 return true; 118 return true;
92 } 119 }
93 120
94 bool ChromeCrashReporterClient::AboutToRestart() { 121 bool ChromeCrashReporterClient::AboutToRestart() {
95 if (!install_static::HasEnvironmentVariable(env_vars::kRestartInfo)) 122 std::unique_ptr<base::Environment> env(base::Environment::Create());
123 if (!env->HasVar(env_vars::kRestartInfo))
96 return false; 124 return false;
97 125
98 install_static::SetEnvironmentString(env_vars::kShowRestart, "1"); 126 env->SetVar(env_vars::kShowRestart, "1");
99 return true; 127 return true;
100 } 128 }
101 129
102 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( 130 bool ChromeCrashReporterClient::GetDeferredUploadsSupported(
103 bool is_per_user_install) { 131 bool is_per_user_install) {
104 std::string version_string = install_static::GetGoogleUpdateVersion(); 132 Version update_version = GoogleUpdateSettings::GetGoogleUpdateVersion(
105 Version update_version(version_string); 133 !is_per_user_install);
106 if (!update_version.IsValid() || 134 if (!update_version.IsValid() ||
107 update_version < base::Version(kMinUpdateVersion)) { 135 update_version < base::Version(kMinUpdateVersion))
108 return false; 136 return false;
109 } 137
110 return true; 138 return true;
111 } 139 }
112 140
113 bool ChromeCrashReporterClient::GetIsPerUserInstall( 141 bool ChromeCrashReporterClient::GetIsPerUserInstall(
114 const base::FilePath& exe_path) { 142 const base::FilePath& exe_path) {
115 return !install_static::IsSystemInstall(exe_path.value().c_str()); 143 return InstallUtil::IsPerUserInstall(exe_path);
116 } 144 }
117 145
118 bool ChromeCrashReporterClient::GetShouldDumpLargerDumps( 146 bool ChromeCrashReporterClient::GetShouldDumpLargerDumps(
119 bool is_per_user_install) { 147 bool is_per_user_install) {
120 base::string16 channel_name; 148 base::string16 channel_name =
121 install_static::GetChromeChannelName(is_per_user_install, 149 GoogleUpdateSettings::GetChromeChannel(!is_per_user_install);
122 false, // !add_modifier 150
123 &channel_name);
124 // Capture more detail in crash dumps for Beta, Dev, Canary channels and 151 // Capture more detail in crash dumps for Beta, Dev, Canary channels and
125 // if channel is unknown (e.g. Chromium or developer builds). 152 // if channel is unknown (e.g. Chromium or developer builds).
126 return (channel_name == install_static::kChromeChannelBeta || 153 return (channel_name == installer::kChromeChannelBeta ||
127 channel_name == install_static::kChromeChannelDev || 154 channel_name == installer::kChromeChannelDev ||
128 channel_name == install_static::kChromeChannelCanary || 155 channel_name == GoogleChromeSxSDistribution::ChannelName() ||
129 channel_name == install_static::kChromeChannelUnknown); 156 channel_name == installer::kChromeChannelUnknown);
130 } 157 }
131 158
132 int ChromeCrashReporterClient::GetResultCodeRespawnFailed() { 159 int ChromeCrashReporterClient::GetResultCodeRespawnFailed() {
133 return chrome::RESULT_CODE_RESPAWN_FAILED; 160 return chrome::RESULT_CODE_RESPAWN_FAILED;
134 } 161 }
135 162
136 bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy( 163 bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy(
137 bool* breakpad_enabled) { 164 bool* breakpad_enabled) {
138 // Determine whether configuration management allows loading the crash 165 // Determine whether configuration management allows loading the crash reporter.
139 // reporter. 166 // Since the configuration management infrastructure is not initialized at this
140 // Since the configuration management infrastructure is not initialized at 167 // point, we read the corresponding registry key directly. The return status
141 // this point, we read the corresponding registry key directly. The return 168 // indicates whether policy data was successfully read. If it is true,
142 // status indicates whether policy data was successfully read. If it is true, 169 // |breakpad_enabled| contains the value set by policy.
143 // |breakpad_enabled| contains the value set by policy. 170 base::string16 key_name =
144 return install_static::ReportingIsEnforcedByPolicy(breakpad_enabled); 171 base::UTF8ToUTF16(policy::key::kMetricsReportingEnabled);
172 DWORD value = 0;
173 base::win::RegKey hklm_policy_key(HKEY_LOCAL_MACHINE,
174 policy::kRegistryChromePolicyKey, KEY_READ);
175 if (hklm_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) {
176 *breakpad_enabled = value != 0;
177 return true;
178 }
179
180 base::win::RegKey hkcu_policy_key(HKEY_CURRENT_USER,
181 policy::kRegistryChromePolicyKey, KEY_READ);
182 if (hkcu_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) {
183 *breakpad_enabled = value != 0;
184 return true;
185 }
186
187 return false;
145 } 188 }
146 189
147 190
148 bool ChromeCrashReporterClient::GetCrashDumpLocation( 191 bool ChromeCrashReporterClient::GetCrashDumpLocation(
149 base::FilePath* crash_dir) { 192 base::FilePath* crash_dir) {
150 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate 193 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate
151 // location to write breakpad crash dumps can be set. 194 // location to write breakpad crash dumps can be set.
152 // If this environment variable exists, then for the time being, 195 std::unique_ptr<base::Environment> env(base::Environment::Create());
153 // short-circuit how it's handled on Windows. Honoring this 196 std::string alternate_crash_dump_location;
154 // variable is required in order to symbolize stack traces in 197 if (env->GetVar("BREAKPAD_DUMP_LOCATION", &alternate_crash_dump_location)) {
155 // Telemetry based tests: http://crbug.com/561763. 198 base::FilePath crash_dumps_dir_path =
156 if (GetAlternativeCrashDumpLocation(crash_dir)) 199 base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location);
200
201 // If this environment variable exists, then for the time being,
202 // short-circuit how it's handled on Windows. Honoring this
203 // variable is required in order to symbolize stack traces in
204 // Telemetry based tests: http://crbug.com/561763.
205 *crash_dir = crash_dumps_dir_path;
157 return true; 206 return true;
207 }
158 208
159 // TODO(scottmg): Consider supporting --user-data-dir. See 209 // TODO(scottmg): Consider supporting --user-data-dir. See
160 // https://crbug.com/565446. 210 // https://crbug.com/565446.
161 base::string16 crash_dump_location; 211 return chrome::GetDefaultCrashDumpLocation(crash_dir);
162 if (!install_static::GetDefaultCrashDumpLocation(&crash_dump_location))
163 return false;
164 *crash_dir = base::FilePath(crash_dump_location);
165 return true;
166 } 212 }
167 213
168 size_t ChromeCrashReporterClient::RegisterCrashKeys() { 214 size_t ChromeCrashReporterClient::RegisterCrashKeys() {
169 return crash_keys::RegisterChromeCrashKeys(); 215 return crash_keys::RegisterChromeCrashKeys();
170 } 216 }
171 217
172 bool ChromeCrashReporterClient::IsRunningUnattended() { 218 bool ChromeCrashReporterClient::IsRunningUnattended() {
173 return install_static::HasEnvironmentVariable(env_vars::kHeadless); 219 std::unique_ptr<base::Environment> env(base::Environment::Create());
220 return env->HasVar(env_vars::kHeadless);
174 } 221 }
175 222
176 bool ChromeCrashReporterClient::GetCollectStatsConsent() { 223 bool ChromeCrashReporterClient::GetCollectStatsConsent() {
177 return install_static::GetCollectStatsConsent(); 224 #if defined(GOOGLE_CHROME_BUILD)
225 bool is_official_chrome_build = true;
226 #else
227 bool is_official_chrome_build = false;
228 #endif
229
230 return is_official_chrome_build &&
231 GoogleUpdateSettings::GetCollectStatsConsent();
178 } 232 }
179 233
180 bool ChromeCrashReporterClient::EnableBreakpadForProcess( 234 bool ChromeCrashReporterClient::EnableBreakpadForProcess(
181 const std::string& process_type) { 235 const std::string& process_type) {
182 return process_type == switches::kRendererProcess || 236 return process_type == switches::kRendererProcess ||
183 process_type == switches::kPpapiPluginProcess || 237 process_type == switches::kPpapiPluginProcess ||
184 process_type == switches::kZygoteProcess || 238 process_type == switches::kZygoteProcess ||
185 process_type == switches::kGpuProcess; 239 process_type == switches::kGpuProcess;
186 } 240 }
OLDNEW
« no previous file with comments | « chrome/app/DEPS ('k') | chrome/chrome_dll.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698