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

Side by Side Diff: components/breakpad/tools/crash_service.cc

Issue 26688006: Move CrashService class to breakpad component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years, 2 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) 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/tools/crash_service/crash_service.h" 5 #include "components/breakpad/tools/crash_service.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <sddl.h> 9 #include <sddl.h>
10 #include <fstream> 10 #include <fstream>
11 #include <map> 11 #include <map>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/path_service.h"
17 #include "base/win/windows_version.h" 16 #include "base/win/windows_version.h"
18 #include "breakpad/src/client/windows/crash_generation/client_info.h" 17 #include "breakpad/src/client/windows/crash_generation/client_info.h"
19 #include "breakpad/src/client/windows/crash_generation/crash_generation_server.h " 18 #include "breakpad/src/client/windows/crash_generation/crash_generation_server.h "
20 #include "breakpad/src/client/windows/sender/crash_report_sender.h" 19 #include "breakpad/src/client/windows/sender/crash_report_sender.h"
21 #include "chrome/common/chrome_constants.h" 20
22 #include "chrome/common/chrome_paths.h" 21 namespace breakpad {
23 22
24 namespace { 23 namespace {
25 24
26 const wchar_t kTestPipeName[] = L"\\\\.\\pipe\\ChromeCrashServices"; 25 const wchar_t kTestPipeName[] = L"\\\\.\\pipe\\ChromeCrashServices";
27 26
28 const wchar_t kCrashReportURL[] = L"https://clients2.google.com/cr/report"; 27 const wchar_t kCrashReportURL[] = L"https://clients2.google.com/cr/report";
29 const wchar_t kCheckPointFile[] = L"crash_checkpoint.txt"; 28 const wchar_t kCheckPointFile[] = L"crash_checkpoint.txt";
30 29
31 typedef std::map<std::wstring, std::wstring> CrashMap; 30 typedef std::map<std::wstring, std::wstring> CrashMap;
32 31
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 144
146 } // namespace 145 } // namespace
147 146
148 // Command line switches: 147 // Command line switches:
149 const char CrashService::kMaxReports[] = "max-reports"; 148 const char CrashService::kMaxReports[] = "max-reports";
150 const char CrashService::kNoWindow[] = "no-window"; 149 const char CrashService::kNoWindow[] = "no-window";
151 const char CrashService::kReporterTag[] = "reporter"; 150 const char CrashService::kReporterTag[] = "reporter";
152 const char CrashService::kDumpsDir[] = "dumps-dir"; 151 const char CrashService::kDumpsDir[] = "dumps-dir";
153 const char CrashService::kPipeName[] = "pipe-name"; 152 const char CrashService::kPipeName[] = "pipe-name";
154 153
155 CrashService::CrashService(const std::wstring& report_dir) 154 CrashService::CrashService()
156 : report_path_(report_dir), 155 : sender_(NULL),
157 sender_(NULL),
158 dumper_(NULL), 156 dumper_(NULL),
159 requests_handled_(0), 157 requests_handled_(0),
160 requests_sent_(0), 158 requests_sent_(0),
161 clients_connected_(0), 159 clients_connected_(0),
162 clients_terminated_(0) { 160 clients_terminated_(0) {
163 chrome::RegisterPathProvider();
164 } 161 }
165 162
166 CrashService::~CrashService() { 163 CrashService::~CrashService() {
167 base::AutoLock lock(sending_); 164 base::AutoLock lock(sending_);
168 delete dumper_; 165 delete dumper_;
169 delete sender_; 166 delete sender_;
170 } 167 }
171 168
172 169 bool CrashService::Initialize(const base::FilePath& operating_dir,
173 bool CrashService::Initialize(const std::wstring& command_line) { 170 const base::FilePath& report_path,
171 const base::FilePath& dumps_path) {
174 using google_breakpad::CrashReportSender; 172 using google_breakpad::CrashReportSender;
175 using google_breakpad::CrashGenerationServer; 173 using google_breakpad::CrashGenerationServer;
176 174
177 std::wstring pipe_name = kTestPipeName; 175 std::wstring pipe_name = kTestPipeName;
178 int max_reports = -1; 176 int max_reports = -1;
179 177
180 // The checkpoint file allows CrashReportSender to enforce the the maximum 178 // The checkpoint file allows CrashReportSender to enforce the the maximum
181 // reports per day quota. Does not seem to serve any other purpose. 179 // reports per day quota. Does not seem to serve any other purpose.
182 base::FilePath checkpoint_path = report_path_.Append(kCheckPointFile); 180 base::FilePath checkpoint_path = operating_dir.Append(kCheckPointFile);
183 181
184 // The dumps path is typically : '<user profile>\Local settings\ 182 report_path_ = report_path;
185 // Application data\Goggle\Chrome\Crash Reports' and the report path is
186 // Application data\Google\Chrome\Reported Crashes.txt
187 base::FilePath user_data_dir;
188 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
189 LOG(ERROR) << "could not get DIR_USER_DATA";
190 return false;
191 }
192 report_path_ = user_data_dir.Append(chrome::kCrashReportLog);
193 183
194 CommandLine cmd_line = CommandLine::FromString(command_line); 184 CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
195 185
196 base::FilePath dumps_path; 186 base::FilePath dumps_path_to_use = dumps_path;
197 if (cmd_line.HasSwitch(kDumpsDir)) { 187
198 dumps_path = base::FilePath(cmd_line.GetSwitchValueNative(kDumpsDir)); 188 if (cmd_line.HasSwitch(kDumpsDir))
199 } else { 189 dumps_path_to_use = base::FilePath(cmd_line.GetSwitchValueNative(kDumpsDir)) ;
Robert Sesek 2013/10/17 13:16:05 nit: 80cols (sucky, I know)
jochen (gone - plz use gerrit) 2013/10/17 16:47:39 Done.
200 if (!PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path)) {
201 LOG(ERROR) << "could not get DIR_CRASH_DUMPS";
202 return false;
203 }
204 }
205 190
206 // We can override the send reports quota with a command line switch. 191 // We can override the send reports quota with a command line switch.
207 if (cmd_line.HasSwitch(kMaxReports)) 192 if (cmd_line.HasSwitch(kMaxReports))
208 max_reports = _wtoi(cmd_line.GetSwitchValueNative(kMaxReports).c_str()); 193 max_reports = _wtoi(cmd_line.GetSwitchValueNative(kMaxReports).c_str());
209 194
210 // Allow the global pipe name to be overridden for better testability. 195 // Allow the global pipe name to be overridden for better testability.
211 if (cmd_line.HasSwitch(kPipeName)) 196 if (cmd_line.HasSwitch(kPipeName))
212 pipe_name = cmd_line.GetSwitchValueNative(kPipeName); 197 pipe_name = cmd_line.GetSwitchValueNative(kPipeName);
213 198
214 #ifdef _WIN64 199 #ifdef _WIN64
(...skipping 25 matching lines...) Expand all
240 225
241 security_attributes_actual = &security_attributes; 226 security_attributes_actual = &security_attributes;
242 } 227 }
243 228
244 // Create the OOP crash generator object. 229 // Create the OOP crash generator object.
245 dumper_ = new CrashGenerationServer(pipe_name, security_attributes_actual, 230 dumper_ = new CrashGenerationServer(pipe_name, security_attributes_actual,
246 &CrashService::OnClientConnected, this, 231 &CrashService::OnClientConnected, this,
247 &CrashService::OnClientDumpRequest, this, 232 &CrashService::OnClientDumpRequest, this,
248 &CrashService::OnClientExited, this, 233 &CrashService::OnClientExited, this,
249 NULL, NULL, 234 NULL, NULL,
250 true, &dumps_path.value()); 235 true, &dumps_path_to_use.value());
251 236
252 if (!dumper_) { 237 if (!dumper_) {
253 LOG(ERROR) << "could not create dumper"; 238 LOG(ERROR) << "could not create dumper";
254 if (security_attributes.lpSecurityDescriptor) 239 if (security_attributes.lpSecurityDescriptor)
255 LocalFree(security_attributes.lpSecurityDescriptor); 240 LocalFree(security_attributes.lpSecurityDescriptor);
256 return false; 241 return false;
257 } 242 }
258 243
259 if (!CreateTopWindow(::GetModuleHandleW(NULL), 244 if (!CreateTopWindow(::GetModuleHandleW(NULL),
260 !cmd_line.HasSwitch(kNoWindow))) { 245 !cmd_line.HasSwitch(kNoWindow))) {
261 LOG(ERROR) << "could not create window"; 246 LOG(ERROR) << "could not create window";
262 if (security_attributes.lpSecurityDescriptor) 247 if (security_attributes.lpSecurityDescriptor)
263 LocalFree(security_attributes.lpSecurityDescriptor); 248 LocalFree(security_attributes.lpSecurityDescriptor);
264 return false; 249 return false;
265 } 250 }
266 251
267 reporter_tag_ = L"crash svc"; 252 reporter_tag_ = L"crash svc";
268 if (cmd_line.HasSwitch(kReporterTag)) 253 if (cmd_line.HasSwitch(kReporterTag))
269 reporter_tag_ = cmd_line.GetSwitchValueNative(kReporterTag); 254 reporter_tag_ = cmd_line.GetSwitchValueNative(kReporterTag);
270 255
271 // Log basic information. 256 // Log basic information.
272 VLOG(1) << "pipe name is " << pipe_name 257 VLOG(1) << "pipe name is " << pipe_name
273 << "\ndumps at " << dumps_path.value() 258 << "\ndumps at " << dumps_path_to_use.value()
274 << "\nreports at " << report_path_.value(); 259 << "\nreports at " << report_path_.value();
275 260
276 if (sender_) { 261 if (sender_) {
277 VLOG(1) << "checkpoint is " << checkpoint_path.value() 262 VLOG(1) << "checkpoint is " << checkpoint_path.value()
278 << "\nserver is " << kCrashReportURL 263 << "\nserver is " << kCrashReportURL
279 << "\nmaximum " << sender_->max_reports_per_day() << " reports/day" 264 << "\nmaximum " << sender_->max_reports_per_day() << " reports/day"
280 << "\nreporter is " << reporter_tag_; 265 << "\nreporter is " << reporter_tag_;
281 } 266 }
282 // Start servicing clients. 267 // Start servicing clients.
283 if (!dumper_->Start()) { 268 if (!dumper_->Start()) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 SDDL_REVISION, 483 SDDL_REVISION,
499 &sec_desc, NULL)) { 484 &sec_desc, NULL)) {
500 if (::GetSecurityDescriptorSacl(sec_desc, &sacl_present, &sacl, 485 if (::GetSecurityDescriptorSacl(sec_desc, &sacl_present, &sacl,
501 &sacl_defaulted)) { 486 &sacl_defaulted)) {
502 return sec_desc; 487 return sec_desc;
503 } 488 }
504 } 489 }
505 490
506 return NULL; 491 return NULL;
507 } 492 }
493
494 } // namespace breakpad
OLDNEW
« components/breakpad/tools/crash_service.h ('K') | « components/breakpad/tools/crash_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698