OLD | NEW |
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 | 4 |
5 // TODO(ananta/scottmg) | 5 // TODO(ananta/scottmg) |
6 // Add test coverage for Crashpad. | 6 // Add test coverage for Crashpad. |
7 #include "chrome/app/chrome_crash_reporter_client_win.h" | 7 #include "chrome/app/chrome_crash_reporter_client_win.h" |
8 | 8 |
| 9 #include <assert.h> |
9 #include <windows.h> | 10 #include <windows.h> |
10 | 11 |
11 #include <memory> | 12 #include <memory> |
12 #include <string> | 13 #include <string> |
13 | 14 |
14 #include "base/command_line.h" | |
15 #include "base/files/file_path.h" | |
16 #include "base/logging.h" | |
17 #include "base/path_service.h" | |
18 #include "base/strings/string_split.h" | |
19 #include "base/strings/utf_string_conversions.h" | |
20 #include "base/version.h" | |
21 #include "build/build_config.h" | 15 #include "build/build_config.h" |
22 #include "chrome/common/chrome_result_codes.h" | 16 #include "chrome/common/chrome_result_codes.h" |
23 #include "chrome/common/crash_keys.h" | 17 #include "chrome/common/crash_keys.h" |
24 #include "chrome/common/env_vars.h" | |
25 #include "chrome/install_static/install_util.h" | 18 #include "chrome/install_static/install_util.h" |
26 #include "content/public/common/content_switches.h" | |
27 | |
28 namespace { | |
29 | |
30 // This is the minimum version of google update that is required for deferred | |
31 // crash uploads to work. | |
32 const char kMinUpdateVersion[] = "1.3.21.115"; | |
33 | |
34 } // namespace | |
35 | 19 |
36 ChromeCrashReporterClient::ChromeCrashReporterClient() {} | 20 ChromeCrashReporterClient::ChromeCrashReporterClient() {} |
37 | 21 |
38 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} | 22 ChromeCrashReporterClient::~ChromeCrashReporterClient() {} |
39 | 23 |
40 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( | 24 bool ChromeCrashReporterClient::GetAlternativeCrashDumpLocation( |
41 base::FilePath* crash_dir) { | 25 base::string16* crash_dir) { |
42 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 26 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
43 // location to write breakpad crash dumps can be set. | 27 // location to write breakpad crash dumps can be set. |
44 std::string alternate_crash_dump_location = | 28 *crash_dir = |
45 install_static::GetEnvironmentString("BREAKPAD_DUMP_LOCATION"); | 29 install_static::GetEnvironmentString16(L"BREAKPAD_DUMP_LOCATION"); |
46 if (!alternate_crash_dump_location.empty()) { | 30 return !crash_dir->empty(); |
47 *crash_dir = base::FilePath::FromUTF8Unsafe(alternate_crash_dump_location); | |
48 return true; | |
49 } | |
50 return false; | |
51 } | 31 } |
52 | 32 |
53 void ChromeCrashReporterClient::GetProductNameAndVersion( | 33 void ChromeCrashReporterClient::GetProductNameAndVersion( |
54 const base::FilePath& exe_path, | 34 const base::string16& exe_path, |
55 base::string16* product_name, | 35 base::string16* product_name, |
56 base::string16* version, | 36 base::string16* version, |
57 base::string16* special_build, | 37 base::string16* special_build, |
58 base::string16* channel_name) { | 38 base::string16* channel_name) { |
59 DCHECK(product_name); | 39 assert(product_name); |
60 DCHECK(version); | 40 assert(version); |
61 DCHECK(special_build); | 41 assert(special_build); |
62 DCHECK(channel_name); | 42 assert(channel_name); |
63 | 43 |
64 install_static::GetExecutableVersionDetails( | 44 install_static::GetExecutableVersionDetails( |
65 exe_path.value(), product_name, version, special_build, channel_name); | 45 exe_path, product_name, version, special_build, channel_name); |
66 } | 46 } |
67 | 47 |
68 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, | 48 bool ChromeCrashReporterClient::ShouldShowRestartDialog(base::string16* title, |
69 base::string16* message, | 49 base::string16* message, |
70 bool* is_rtl_locale) { | 50 bool* is_rtl_locale) { |
71 if (!install_static::HasEnvironmentVariable(env_vars::kShowRestart) || | 51 if (!install_static::HasEnvironmentVariable16( |
72 !install_static::HasEnvironmentVariable(env_vars::kRestartInfo) || | 52 install_static::kShowRestart) || |
73 install_static::HasEnvironmentVariable(env_vars::kMetroConnected)) { | 53 !install_static::HasEnvironmentVariable16( |
| 54 install_static::kRestartInfo)) { |
74 return false; | 55 return false; |
75 } | 56 } |
76 | 57 |
77 std::string restart_info = | 58 base::string16 restart_info = |
78 install_static::GetEnvironmentString(env_vars::kRestartInfo); | 59 install_static::GetEnvironmentString16(install_static::kRestartInfo); |
79 | 60 |
80 // The CHROME_RESTART var contains the dialog strings separated by '|'. | 61 // The CHROME_RESTART var contains the dialog strings separated by '|'. |
81 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() | 62 // See ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment() |
82 // for details. | 63 // for details. |
83 std::vector<std::string> dlg_strings = base::SplitString( | 64 std::vector<base::string16> dlg_strings = install_static::TokenizeString16( |
84 restart_info, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 65 restart_info, L'|', true); // true = Trim whitespace. |
85 | 66 |
86 if (dlg_strings.size() < 3) | 67 if (dlg_strings.size() < 3) |
87 return false; | 68 return false; |
88 | 69 |
89 *title = base::UTF8ToUTF16(dlg_strings[0]); | 70 *title = dlg_strings[0]; |
90 *message = base::UTF8ToUTF16(dlg_strings[1]); | 71 *message = dlg_strings[1]; |
91 *is_rtl_locale = dlg_strings[2] == env_vars::kRtlLocale; | 72 *is_rtl_locale = dlg_strings[2] == install_static::kRtlLocale; |
92 return true; | 73 return true; |
93 } | 74 } |
94 | 75 |
95 bool ChromeCrashReporterClient::AboutToRestart() { | 76 bool ChromeCrashReporterClient::AboutToRestart() { |
96 if (!install_static::HasEnvironmentVariable(env_vars::kRestartInfo)) | 77 if (!install_static::HasEnvironmentVariable16(install_static::kRestartInfo)) |
97 return false; | 78 return false; |
98 | 79 |
99 install_static::SetEnvironmentString(env_vars::kShowRestart, "1"); | 80 install_static::SetEnvironmentString16(install_static::kShowRestart, L"1"); |
100 return true; | 81 return true; |
101 } | 82 } |
102 | 83 |
103 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( | 84 bool ChromeCrashReporterClient::GetDeferredUploadsSupported( |
104 bool is_per_user_install) { | 85 bool is_per_user_install) { |
105 Version update_version(install_static::GetGoogleUpdateVersion()); | 86 return false; |
106 return update_version.IsValid() && | |
107 update_version >= base::Version(kMinUpdateVersion); | |
108 } | 87 } |
109 | 88 |
110 bool ChromeCrashReporterClient::GetIsPerUserInstall( | 89 bool ChromeCrashReporterClient::GetIsPerUserInstall( |
111 const base::FilePath& exe_path) { | 90 const base::string16& exe_path) { |
112 return !install_static::IsSystemInstall(exe_path.value().c_str()); | 91 return !install_static::IsSystemInstall(exe_path.c_str()); |
113 } | 92 } |
114 | 93 |
115 bool ChromeCrashReporterClient::GetShouldDumpLargerDumps( | 94 bool ChromeCrashReporterClient::GetShouldDumpLargerDumps( |
116 bool is_per_user_install) { | 95 bool is_per_user_install) { |
117 base::string16 channel_name; | 96 base::string16 channel_name; |
118 install_static::GetChromeChannelName(is_per_user_install, | 97 install_static::GetChromeChannelName(is_per_user_install, |
119 false, // !add_modifier | 98 false, // !add_modifier |
120 &channel_name); | 99 &channel_name); |
121 // Capture more detail in crash dumps for Beta, Dev, Canary channels and | 100 // Capture more detail in crash dumps for Beta, Dev, Canary channels and |
122 // if channel is unknown (e.g. Chromium or developer builds). | 101 // if channel is unknown (e.g. Chromium or developer builds). |
(...skipping 13 matching lines...) Expand all Loading... |
136 // reporter. | 115 // reporter. |
137 // Since the configuration management infrastructure is not initialized at | 116 // Since the configuration management infrastructure is not initialized at |
138 // this point, we read the corresponding registry key directly. The return | 117 // this point, we read the corresponding registry key directly. The return |
139 // status indicates whether policy data was successfully read. If it is true, | 118 // status indicates whether policy data was successfully read. If it is true, |
140 // |breakpad_enabled| contains the value set by policy. | 119 // |breakpad_enabled| contains the value set by policy. |
141 return install_static::ReportingIsEnforcedByPolicy(crashpad_enabled); | 120 return install_static::ReportingIsEnforcedByPolicy(crashpad_enabled); |
142 } | 121 } |
143 | 122 |
144 | 123 |
145 bool ChromeCrashReporterClient::GetCrashDumpLocation( | 124 bool ChromeCrashReporterClient::GetCrashDumpLocation( |
146 base::FilePath* crash_dir) { | 125 base::string16* crash_dir) { |
147 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate | 126 // By setting the BREAKPAD_DUMP_LOCATION environment variable, an alternate |
148 // location to write breakpad crash dumps can be set. | 127 // location to write breakpad crash dumps can be set. |
149 // If this environment variable exists, then for the time being, | 128 // If this environment variable exists, then for the time being, |
150 // short-circuit how it's handled on Windows. Honoring this | 129 // short-circuit how it's handled on Windows. Honoring this |
151 // variable is required in order to symbolize stack traces in | 130 // variable is required in order to symbolize stack traces in |
152 // Telemetry based tests: http://crbug.com/561763. | 131 // Telemetry based tests: http://crbug.com/561763. |
153 if (GetAlternativeCrashDumpLocation(crash_dir)) | 132 if (GetAlternativeCrashDumpLocation(crash_dir)) |
154 return true; | 133 return true; |
155 | 134 |
156 // TODO(scottmg): Consider supporting --user-data-dir. See | 135 // TODO(scottmg): Consider supporting --user-data-dir. See |
157 // https://crbug.com/565446. | 136 // https://crbug.com/565446. |
158 base::string16 crash_dump_location; | 137 return install_static::GetDefaultCrashDumpLocation(crash_dir); |
159 if (!install_static::GetDefaultCrashDumpLocation(&crash_dump_location)) | |
160 return false; | |
161 *crash_dir = base::FilePath(crash_dump_location); | |
162 return true; | |
163 } | 138 } |
164 | 139 |
165 size_t ChromeCrashReporterClient::RegisterCrashKeys() { | 140 size_t ChromeCrashReporterClient::RegisterCrashKeys() { |
166 return crash_keys::RegisterChromeCrashKeys(); | 141 return crash_keys::RegisterChromeCrashKeys(); |
167 } | 142 } |
168 | 143 |
169 bool ChromeCrashReporterClient::IsRunningUnattended() { | 144 bool ChromeCrashReporterClient::IsRunningUnattended() { |
170 return install_static::HasEnvironmentVariable(env_vars::kHeadless); | 145 return install_static::HasEnvironmentVariable16(install_static::kHeadless); |
171 } | 146 } |
172 | 147 |
173 bool ChromeCrashReporterClient::GetCollectStatsConsent() { | 148 bool ChromeCrashReporterClient::GetCollectStatsConsent() { |
174 return install_static::GetCollectStatsConsent(); | 149 return install_static::GetCollectStatsConsent(); |
175 } | 150 } |
176 | 151 |
177 bool ChromeCrashReporterClient::EnableBreakpadForProcess( | 152 bool ChromeCrashReporterClient::EnableBreakpadForProcess( |
178 const std::string& process_type) { | 153 const std::string& process_type) { |
179 return process_type == switches::kRendererProcess || | 154 return process_type == install_static::kRendererProcess || |
180 process_type == switches::kPpapiPluginProcess || | 155 process_type == install_static::kPpapiPluginProcess || |
181 process_type == switches::kZygoteProcess || | 156 process_type == install_static::kGpuProcess; |
182 process_type == switches::kGpuProcess; | |
183 } | 157 } |
OLD | NEW |