| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Implementation of wrapper around common crash reporting. | 5 // Implementation of wrapper around common crash reporting. |
| 6 | 6 |
| 7 #include "chrome_frame/chrome_frame_reporting.h" |
| 8 |
| 9 #include "base/basictypes.h" |
| 7 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 8 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
| 9 #include "base/win/win_util.h" | 12 #include "base/win/win_util.h" |
| 10 #include "chrome/installer/util/google_update_settings.h" | 13 #include "chrome/installer/util/google_update_settings.h" |
| 11 #include "chrome/installer/util/install_util.h" | 14 #include "chrome/installer/util/install_util.h" |
| 12 #include "chrome_frame/chrome_frame_reporting.h" | 15 #include "chrome_frame/crash_reporting/crash_report.h" |
| 13 #include "chrome_frame/exception_barrier.h" | 16 #include "chrome_frame/exception_barrier.h" |
| 14 #include "chrome_frame/utils.h" | 17 #include "chrome_frame/utils.h" |
| 15 | 18 |
| 19 extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 20 |
| 21 namespace { |
| 22 |
| 16 // Well known SID for the system principal. | 23 // Well known SID for the system principal. |
| 17 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; | 24 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; |
| 18 const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices"; | 25 const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices"; |
| 19 | 26 |
| 20 // Returns the custom info structure based on the dll in parameter | 27 // Returns the custom info structure based on the dll in parameter |
| 21 google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* dll_path) { | 28 google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* dll_path) { |
| 22 std::wstring product; | 29 std::wstring product; |
| 23 std::wstring version; | 30 std::wstring version; |
| 24 scoped_ptr<FileVersionInfo> version_info( | 31 scoped_ptr<FileVersionInfo> version_info( |
| 25 FileVersionInfo::CreateFileVersionInfo(base::FilePath(dll_path))); | 32 FileVersionInfo::CreateFileVersionInfo(base::FilePath(dll_path))); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 38 static google_breakpad::CustomInfoEntry prod_entry(L"prod", product.c_str()); | 45 static google_breakpad::CustomInfoEntry prod_entry(L"prod", product.c_str()); |
| 39 static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); | 46 static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); |
| 40 static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame"); | 47 static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame"); |
| 41 static google_breakpad::CustomInfoEntry entries[] = { | 48 static google_breakpad::CustomInfoEntry entries[] = { |
| 42 ver_entry, prod_entry, plat_entry, type_entry }; | 49 ver_entry, prod_entry, plat_entry, type_entry }; |
| 43 static google_breakpad::CustomClientInfo custom_info = { | 50 static google_breakpad::CustomClientInfo custom_info = { |
| 44 entries, arraysize(entries) }; | 51 entries, arraysize(entries) }; |
| 45 return &custom_info; | 52 return &custom_info; |
| 46 } | 53 } |
| 47 | 54 |
| 48 extern "C" IMAGE_DOS_HEADER __ImageBase; | |
| 49 | |
| 50 bool InitializeCrashReporting() { | 55 bool InitializeCrashReporting() { |
| 51 // In headless mode we want crashes to be reported back. | 56 // In headless mode we want crashes to be reported back. |
| 52 bool always_take_dump = IsHeadlessMode(); | 57 bool always_take_dump = IsHeadlessMode(); |
| 53 // We want to use the Google Update crash reporting. We need to check if the | 58 // We want to use the Google Update crash reporting. We need to check if the |
| 54 // user allows it first. | 59 // user allows it first. |
| 55 if (!always_take_dump && !GoogleUpdateSettings::GetCollectStatsConsent()) | 60 if (!always_take_dump && !GoogleUpdateSettings::GetCollectStatsConsent()) |
| 56 return true; | 61 return true; |
| 57 | 62 |
| 58 // If we got here, we want to report crashes, so make sure all | 63 // If we got here, we want to report crashes, so make sure all |
| 59 // ExceptionBarrierBase instances do so. | 64 // ExceptionBarrierBase instances do so. |
| 60 ExceptionBarrierConfig::set_enabled(true); | 65 ExceptionBarrierConfig::set_enabled(true); |
| 61 | 66 |
| 62 // Get the alternate dump directory. We use the temp path. | 67 // Get the alternate dump directory. We use the temp path. |
| 63 base::FilePath temp_directory; | 68 base::FilePath temp_directory; |
| 64 if (!file_util::GetTempDir(&temp_directory) || temp_directory.empty()) { | 69 if (!file_util::GetTempDir(&temp_directory) || temp_directory.empty()) |
| 65 return false; | 70 return false; |
| 66 } | |
| 67 | 71 |
| 68 wchar_t dll_path[MAX_PATH * 2] = {0}; | 72 wchar_t dll_path[MAX_PATH * 2] = {0}; |
| 69 GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), dll_path, | 73 GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), dll_path, |
| 70 arraysize(dll_path)); | 74 arraysize(dll_path)); |
| 71 | 75 |
| 72 if (always_take_dump) { | 76 if (always_take_dump) { |
| 73 return InitializeVectoredCrashReportingWithPipeName(true, kChromePipeName, | 77 return InitializeVectoredCrashReportingWithPipeName( |
| 74 temp_directory.value(), GetCustomInfo(dll_path)); | 78 true, kChromePipeName, temp_directory.value(), GetCustomInfo(dll_path)); |
| 75 } | 79 } |
| 76 | 80 |
| 77 // Build the pipe name. It can be either: | 81 // Build the pipe name. It can be either: |
| 78 // System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18" | 82 // System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18" |
| 79 // Per-user install: "NamedPipe\GoogleCrashServices\<user SID>" | 83 // Per-user install: "NamedPipe\GoogleCrashServices\<user SID>" |
| 80 std::wstring user_sid; | 84 std::wstring user_sid; |
| 81 if (InstallUtil::IsPerUserInstall(dll_path)) { | 85 if (InstallUtil::IsPerUserInstall(dll_path)) { |
| 82 if (!base::win::GetUserSidString(&user_sid)) { | 86 if (!base::win::GetUserSidString(&user_sid)) |
| 83 return false; | 87 return false; |
| 84 } | |
| 85 } else { | 88 } else { |
| 86 user_sid = kSystemPrincipalSid; | 89 user_sid = kSystemPrincipalSid; |
| 87 } | 90 } |
| 88 | 91 |
| 89 return InitializeVectoredCrashReporting(false, user_sid.c_str(), | 92 return InitializeVectoredCrashReporting( |
| 90 temp_directory.value(), GetCustomInfo(dll_path)); | 93 false, user_sid.c_str(), temp_directory.value(), GetCustomInfo(dll_path)); |
| 91 } | 94 } |
| 92 | 95 |
| 93 bool ShutdownCrashReporting() { | 96 bool ShutdownCrashReporting() { |
| 94 ExceptionBarrierConfig::set_enabled(false); | 97 ExceptionBarrierConfig::set_enabled(false); |
| 95 return ShutdownVectoredCrashReporting(); | 98 return ShutdownVectoredCrashReporting(); |
| 96 } | 99 } |
| 100 |
| 101 } // namespace |
| 102 |
| 103 namespace chrome_frame { |
| 104 |
| 105 void CrashReportingTraits::Initialize() { |
| 106 InitializeCrashReporting(); |
| 107 } |
| 108 |
| 109 void CrashReportingTraits::Shutdown() { |
| 110 ShutdownCrashReporting(); |
| 111 } |
| 112 |
| 113 } // namespace chrome_frame |
| OLD | NEW |