OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/app/breakpad_win.h" | 5 #include "chrome/app/breakpad_win.h" |
6 | 6 |
7 #include <shellapi.h> | 7 #include <shellapi.h> |
8 #include <tchar.h> | 8 #include <tchar.h> |
9 #include <userenv.h> | 9 #include <userenv.h> |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
27 #include "base/win/metro.h" | 27 #include "base/win/metro.h" |
28 #include "base/win/pe_image.h" | 28 #include "base/win/pe_image.h" |
29 #include "base/win/registry.h" | 29 #include "base/win/registry.h" |
30 #include "base/win/win_util.h" | 30 #include "base/win/win_util.h" |
31 #include "breakpad/src/client/windows/handler/exception_handler.h" | 31 #include "breakpad/src/client/windows/handler/exception_handler.h" |
32 #include "chrome/app/hard_error_handler_win.h" | 32 #include "chrome/app/hard_error_handler_win.h" |
33 #include "components/breakpad/breakpad_client.h" | 33 #include "components/breakpad/breakpad_client.h" |
34 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
35 #include "content/public/common/result_codes.h" | 35 #include "content/public/common/result_codes.h" |
36 #include "policy/policy_constants.h" | |
37 #include "sandbox/win/src/nt_internals.h" | 36 #include "sandbox/win/src/nt_internals.h" |
38 #include "sandbox/win/src/sidestep/preamble_patcher.h" | 37 #include "sandbox/win/src/sidestep/preamble_patcher.h" |
39 | 38 |
40 // userenv.dll is required for GetProfileType(). | 39 // userenv.dll is required for GetProfileType(). |
41 #pragma comment(lib, "userenv.lib") | 40 #pragma comment(lib, "userenv.lib") |
42 | 41 |
43 #pragma intrinsic(_AddressOfReturnAddress) | 42 #pragma intrinsic(_AddressOfReturnAddress) |
44 #pragma intrinsic(_ReturnAddress) | 43 #pragma intrinsic(_ReturnAddress) |
45 | 44 |
46 namespace breakpad_win { | 45 namespace breakpad_win { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 size_t chunk_length = std::min(kChunkSize, path.size() - chunk_start); | 207 size_t chunk_length = std::min(kChunkSize, path.size() - chunk_start); |
209 | 208 |
210 g_custom_entries->push_back(google_breakpad::CustomInfoEntry( | 209 g_custom_entries->push_back(google_breakpad::CustomInfoEntry( |
211 base::StringPrintf(L"plugin-path-chunk-%i", chunk_index + 1).c_str(), | 210 base::StringPrintf(L"plugin-path-chunk-%i", chunk_index + 1).c_str(), |
212 path.substr(chunk_start, chunk_length).c_str())); | 211 path.substr(chunk_start, chunk_length).c_str())); |
213 | 212 |
214 chunk_start += chunk_length; | 213 chunk_start += chunk_length; |
215 } | 214 } |
216 } | 215 } |
217 | 216 |
218 // Determine whether configuration management allows loading the crash reporter. | |
219 // Since the configuration management infrastructure is not initialized at this | |
220 // point, we read the corresponding registry key directly. The return status | |
221 // indicates whether policy data was successfully read. If it is true, |result| | |
222 // contains the value set by policy. | |
223 static bool MetricsReportingControlledByPolicy(bool* result) { | |
224 string16 key_name = UTF8ToUTF16(policy::key::kMetricsReportingEnabled); | |
225 DWORD value = 0; | |
226 base::win::RegKey hklm_policy_key(HKEY_LOCAL_MACHINE, | |
227 policy::kRegistryChromePolicyKey, KEY_READ); | |
228 if (hklm_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) { | |
229 *result = value != 0; | |
230 return true; | |
231 } | |
232 | |
233 base::win::RegKey hkcu_policy_key(HKEY_CURRENT_USER, | |
234 policy::kRegistryChromePolicyKey, KEY_READ); | |
235 if (hkcu_policy_key.ReadValueDW(key_name.c_str(), &value) == ERROR_SUCCESS) { | |
236 *result = value != 0; | |
237 return true; | |
238 } | |
239 | |
240 return false; | |
241 } | |
242 | |
243 // Appends the breakpad dump path to |g_custom_entries|. | 217 // Appends the breakpad dump path to |g_custom_entries|. |
244 void SetBreakpadDumpPath() { | 218 void SetBreakpadDumpPath() { |
245 DCHECK(g_custom_entries); | 219 DCHECK(g_custom_entries); |
246 base::FilePath crash_dumps_dir_path; | 220 base::FilePath crash_dumps_dir_path; |
247 if (breakpad::GetBreakpadClient()->GetAlternativeCrashDumpLocation( | 221 if (breakpad::GetBreakpadClient()->GetAlternativeCrashDumpLocation( |
248 &crash_dumps_dir_path)) { | 222 &crash_dumps_dir_path)) { |
249 g_custom_entries->push_back(google_breakpad::CustomInfoEntry( | 223 g_custom_entries->push_back(google_breakpad::CustomInfoEntry( |
250 L"breakpad-dump-location", crash_dumps_dir_path.value().c_str())); | 224 L"breakpad-dump-location", crash_dumps_dir_path.value().c_str())); |
251 } | 225 } |
252 } | 226 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 if (type == L"plugin" || type == L"ppapi") { | 297 if (type == L"plugin" || type == L"ppapi") { |
324 std::wstring plugin_path = | 298 std::wstring plugin_path = |
325 CommandLine::ForCurrentProcess()->GetSwitchValueNative("plugin-path"); | 299 CommandLine::ForCurrentProcess()->GetSwitchValueNative("plugin-path"); |
326 if (!plugin_path.empty()) | 300 if (!plugin_path.empty()) |
327 SetPluginPath(plugin_path); | 301 SetPluginPath(plugin_path); |
328 } | 302 } |
329 | 303 |
330 // Check whether configuration management controls crash reporting. | 304 // Check whether configuration management controls crash reporting. |
331 bool crash_reporting_enabled = true; | 305 bool crash_reporting_enabled = true; |
332 bool controlled_by_policy = | 306 bool controlled_by_policy = |
333 MetricsReportingControlledByPolicy(&crash_reporting_enabled); | 307 breakpad::GetBreakpadClient()->ReportingIsEnforcedByPolicy( |
| 308 &crash_reporting_enabled); |
334 const CommandLine& command = *CommandLine::ForCurrentProcess(); | 309 const CommandLine& command = *CommandLine::ForCurrentProcess(); |
335 bool use_crash_service = | 310 bool use_crash_service = |
336 !controlled_by_policy && | 311 !controlled_by_policy && |
337 (command.HasSwitch(switches::kNoErrorDialogs) || | 312 (command.HasSwitch(switches::kNoErrorDialogs) || |
338 breakpad::GetBreakpadClient()->IsRunningUnattended()); | 313 breakpad::GetBreakpadClient()->IsRunningUnattended()); |
339 if (use_crash_service) | 314 if (use_crash_service) |
340 SetBreakpadDumpPath(); | 315 SetBreakpadDumpPath(); |
341 | 316 |
342 // Create space for dynamic ad-hoc keys. The names and values are set using | 317 // Create space for dynamic ad-hoc keys. The names and values are set using |
343 // the API defined in base/debug/crash_logging.h. | 318 // the API defined in base/debug/crash_logging.h. |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 static void InitPipeNameEnvVar(bool is_per_user_install) { | 620 static void InitPipeNameEnvVar(bool is_per_user_install) { |
646 scoped_ptr<base::Environment> env(base::Environment::Create()); | 621 scoped_ptr<base::Environment> env(base::Environment::Create()); |
647 if (env->HasVar(kPipeNameVar)) { | 622 if (env->HasVar(kPipeNameVar)) { |
648 // The Breakpad pipe name is already configured: nothing to do. | 623 // The Breakpad pipe name is already configured: nothing to do. |
649 return; | 624 return; |
650 } | 625 } |
651 | 626 |
652 // Check whether configuration management controls crash reporting. | 627 // Check whether configuration management controls crash reporting. |
653 bool crash_reporting_enabled = true; | 628 bool crash_reporting_enabled = true; |
654 bool controlled_by_policy = | 629 bool controlled_by_policy = |
655 MetricsReportingControlledByPolicy(&crash_reporting_enabled); | 630 breakpad::GetBreakpadClient()->ReportingIsEnforcedByPolicy( |
| 631 &crash_reporting_enabled); |
656 | 632 |
657 const CommandLine& command = *CommandLine::ForCurrentProcess(); | 633 const CommandLine& command = *CommandLine::ForCurrentProcess(); |
658 bool use_crash_service = | 634 bool use_crash_service = |
659 !controlled_by_policy && | 635 !controlled_by_policy && |
660 (command.HasSwitch(switches::kNoErrorDialogs) || | 636 (command.HasSwitch(switches::kNoErrorDialogs) || |
661 breakpad::GetBreakpadClient()->IsRunningUnattended()); | 637 breakpad::GetBreakpadClient()->IsRunningUnattended()); |
662 | 638 |
663 std::wstring pipe_name; | 639 std::wstring pipe_name; |
664 if (use_crash_service) { | 640 if (use_crash_service) { |
665 // Crash reporting is done by crash_service.exe. | 641 // Crash reporting is done by crash_service.exe. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 // Initialize the hook TerminateProcess to catch unexpected exits. | 779 // Initialize the hook TerminateProcess to catch unexpected exits. |
804 InitTerminateProcessHooks(); | 780 InitTerminateProcessHooks(); |
805 } | 781 } |
806 #endif | 782 #endif |
807 } | 783 } |
808 } | 784 } |
809 | 785 |
810 void InitDefaultCrashCallback(LPTOP_LEVEL_EXCEPTION_FILTER filter) { | 786 void InitDefaultCrashCallback(LPTOP_LEVEL_EXCEPTION_FILTER filter) { |
811 previous_filter = SetUnhandledExceptionFilter(filter); | 787 previous_filter = SetUnhandledExceptionFilter(filter); |
812 } | 788 } |
OLD | NEW |