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

Side by Side Diff: chrome_frame/chrome_frame_reporting.cc

Issue 12521002: Start and stop crash reporting outside of the loader lock. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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"
12 #include "base/lazy_instance.h"
9 #include "base/win/win_util.h" 13 #include "base/win/win_util.h"
10 #include "chrome/installer/util/google_update_settings.h" 14 #include "chrome/installer/util/google_update_settings.h"
11 #include "chrome/installer/util/install_util.h" 15 #include "chrome/installer/util/install_util.h"
12 #include "chrome_frame/chrome_frame_reporting.h" 16 #include "chrome_frame/crash_reporting/crash_report.h"
13 #include "chrome_frame/exception_barrier.h" 17 #include "chrome_frame/exception_barrier.h"
14 #include "chrome_frame/utils.h" 18 #include "chrome_frame/utils.h"
15 19
20 extern "C" IMAGE_DOS_HEADER __ImageBase;
21
22 namespace {
23
24 base::LazyInstance<CrashReportingManager>::Leaky g_crash_reporting_manager =
25 LAZY_INSTANCE_INITIALIZER;
26
16 // Well known SID for the system principal. 27 // Well known SID for the system principal.
17 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; 28 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18";
18 const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices"; 29 const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices";
19 30
20 // Returns the custom info structure based on the dll in parameter 31 // Returns the custom info structure based on the dll in parameter
21 google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* dll_path) { 32 google_breakpad::CustomClientInfo* GetCustomInfo(const wchar_t* dll_path) {
22 std::wstring product; 33 std::wstring product;
23 std::wstring version; 34 std::wstring version;
24 scoped_ptr<FileVersionInfo> version_info( 35 scoped_ptr<FileVersionInfo> version_info(
25 FileVersionInfo::CreateFileVersionInfo(base::FilePath(dll_path))); 36 FileVersionInfo::CreateFileVersionInfo(base::FilePath(dll_path)));
(...skipping 12 matching lines...) Expand all
38 static google_breakpad::CustomInfoEntry prod_entry(L"prod", product.c_str()); 49 static google_breakpad::CustomInfoEntry prod_entry(L"prod", product.c_str());
39 static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); 50 static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32");
40 static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame"); 51 static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame");
41 static google_breakpad::CustomInfoEntry entries[] = { 52 static google_breakpad::CustomInfoEntry entries[] = {
42 ver_entry, prod_entry, plat_entry, type_entry }; 53 ver_entry, prod_entry, plat_entry, type_entry };
43 static google_breakpad::CustomClientInfo custom_info = { 54 static google_breakpad::CustomClientInfo custom_info = {
44 entries, arraysize(entries) }; 55 entries, arraysize(entries) };
45 return &custom_info; 56 return &custom_info;
46 } 57 }
47 58
48 extern "C" IMAGE_DOS_HEADER __ImageBase;
49
50 bool InitializeCrashReporting() { 59 bool InitializeCrashReporting() {
51 // In headless mode we want crashes to be reported back. 60 // In headless mode we want crashes to be reported back.
52 bool always_take_dump = IsHeadlessMode(); 61 bool always_take_dump = IsHeadlessMode();
53 // We want to use the Google Update crash reporting. We need to check if the 62 // We want to use the Google Update crash reporting. We need to check if the
54 // user allows it first. 63 // user allows it first.
55 if (!always_take_dump && !GoogleUpdateSettings::GetCollectStatsConsent()) 64 if (!always_take_dump && !GoogleUpdateSettings::GetCollectStatsConsent())
56 return true; 65 return true;
57 66
58 // If we got here, we want to report crashes, so make sure all 67 // If we got here, we want to report crashes, so make sure all
59 // ExceptionBarrierBase instances do so. 68 // ExceptionBarrierBase instances do so.
60 ExceptionBarrierConfig::set_enabled(true); 69 ExceptionBarrierConfig::set_enabled(true);
61 70
62 // Get the alternate dump directory. We use the temp path. 71 // Get the alternate dump directory. We use the temp path.
63 base::FilePath temp_directory; 72 base::FilePath temp_directory;
64 if (!file_util::GetTempDir(&temp_directory) || temp_directory.empty()) { 73 if (!file_util::GetTempDir(&temp_directory) || temp_directory.empty())
65 return false; 74 return false;
66 }
67 75
68 wchar_t dll_path[MAX_PATH * 2] = {0}; 76 wchar_t dll_path[MAX_PATH * 2] = {0};
69 GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), dll_path, 77 GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), dll_path,
70 arraysize(dll_path)); 78 arraysize(dll_path));
71 79
72 if (always_take_dump) { 80 if (always_take_dump) {
73 return InitializeVectoredCrashReportingWithPipeName(true, kChromePipeName, 81 return InitializeVectoredCrashReportingWithPipeName(
74 temp_directory.value(), GetCustomInfo(dll_path)); 82 true, kChromePipeName, temp_directory.value(), GetCustomInfo(dll_path));
75 } 83 }
76 84
77 // Build the pipe name. It can be either: 85 // Build the pipe name. It can be either:
78 // System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18" 86 // System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18"
79 // Per-user install: "NamedPipe\GoogleCrashServices\<user SID>" 87 // Per-user install: "NamedPipe\GoogleCrashServices\<user SID>"
80 std::wstring user_sid; 88 std::wstring user_sid;
81 if (InstallUtil::IsPerUserInstall(dll_path)) { 89 if (InstallUtil::IsPerUserInstall(dll_path)) {
82 if (!base::win::GetUserSidString(&user_sid)) { 90 if (!base::win::GetUserSidString(&user_sid))
83 return false; 91 return false;
84 }
85 } else { 92 } else {
86 user_sid = kSystemPrincipalSid; 93 user_sid = kSystemPrincipalSid;
87 } 94 }
88 95
89 return InitializeVectoredCrashReporting(false, user_sid.c_str(), 96 return InitializeVectoredCrashReporting(
90 temp_directory.value(), GetCustomInfo(dll_path)); 97 false, user_sid.c_str(), temp_directory.value(), GetCustomInfo(dll_path));
91 } 98 }
92 99
93 bool ShutdownCrashReporting() { 100 bool ShutdownCrashReporting() {
94 ExceptionBarrierConfig::set_enabled(false); 101 ExceptionBarrierConfig::set_enabled(false);
95 return ShutdownVectoredCrashReporting(); 102 return ShutdownVectoredCrashReporting();
96 } 103 }
104
105 } // namespace
106
107 // static
108 void CrashReportingManager::Decommit() {
109 CrashReportingManager& instance = Get();
110 base::AutoLock auto_lock(instance.lock_);
111 instance.committed_ = false;
112 instance.ShutdownIfNotCommittedAndUnreferenced();
113 }
114
115 CrashReportingManager::CrashReportingManager()
116 : ref_count_(0),
117 initialized_(false),
118 committed_(false) {}
119
120 CrashReportingManager::~CrashReportingManager() {
121 // The one and only instance of this class is leaked.
122 NOTREACHED();
123 }
124
125 // static
126 CrashReportingManager& CrashReportingManager::Get() {
127 return g_crash_reporting_manager.Get();
128 }
129
130 void CrashReportingManager::AddRef() {
131 base::AutoLock auto_lock(lock_);
132 DCHECK_LT(ref_count_, kuint32max);
133 ++ref_count_;
134
135 if (!initialized_) {
136 initialized_ = true;
137 InitializeCrashReporting();
138 }
139 }
140
141 void CrashReportingManager::Release() {
142 base::AutoLock auto_lock(lock_);
143
144 DCHECK_GT(ref_count_, 0U);
145 if (--ref_count_ == 0)
146 ShutdownIfNotCommittedAndUnreferenced();
147 }
148
149 void CrashReportingManager::Commit() {
150 base::AutoLock auto_lock(lock_);
151 DCHECK_NE(ref_count_, 0U);
152 committed_ = true;
153 }
154
155 // Shuts down crash reporting if no scoper has committed to keeping reporting
156 // alive and no scopers are currently active.
157 void CrashReportingManager::ShutdownIfNotCommittedAndUnreferenced() {
158 lock_.AssertAcquired();
159 if (initialized_ && !committed_ && ref_count_ == 0) {
160 initialized_ = false;
161 ShutdownCrashReporting();
162 }
163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698