Chromium Code Reviews| 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/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 Loading... | |
| 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, |
|
Robert Sesek
2013/10/17 17:21:21
This doesn't match the signature in the other file
| |
| 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 CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
| 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 base::FilePath dumps_path_to_use = dumps_path; |
| 195 | 185 |
| 196 base::FilePath dumps_path; | |
| 197 if (cmd_line.HasSwitch(kDumpsDir)) { | 186 if (cmd_line.HasSwitch(kDumpsDir)) { |
| 198 dumps_path = base::FilePath(cmd_line.GetSwitchValueNative(kDumpsDir)); | 187 dumps_path_to_use = |
| 199 } else { | 188 base::FilePath(cmd_line.GetSwitchValueNative(kDumpsDir)); |
| 200 if (!PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path)) { | |
| 201 LOG(ERROR) << "could not get DIR_CRASH_DUMPS"; | |
| 202 return false; | |
| 203 } | |
| 204 } | 189 } |
| 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 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 236 | 221 |
| 237 security_attributes_actual = &security_attributes; | 222 security_attributes_actual = &security_attributes; |
| 238 } | 223 } |
| 239 | 224 |
| 240 // Create the OOP crash generator object. | 225 // Create the OOP crash generator object. |
| 241 dumper_ = new CrashGenerationServer(pipe_name, security_attributes_actual, | 226 dumper_ = new CrashGenerationServer(pipe_name, security_attributes_actual, |
| 242 &CrashService::OnClientConnected, this, | 227 &CrashService::OnClientConnected, this, |
| 243 &CrashService::OnClientDumpRequest, this, | 228 &CrashService::OnClientDumpRequest, this, |
| 244 &CrashService::OnClientExited, this, | 229 &CrashService::OnClientExited, this, |
| 245 NULL, NULL, | 230 NULL, NULL, |
| 246 true, &dumps_path.value()); | 231 true, &dumps_path_to_use.value()); |
| 247 | 232 |
| 248 if (!dumper_) { | 233 if (!dumper_) { |
| 249 LOG(ERROR) << "could not create dumper"; | 234 LOG(ERROR) << "could not create dumper"; |
| 250 if (security_attributes.lpSecurityDescriptor) | 235 if (security_attributes.lpSecurityDescriptor) |
| 251 LocalFree(security_attributes.lpSecurityDescriptor); | 236 LocalFree(security_attributes.lpSecurityDescriptor); |
| 252 return false; | 237 return false; |
| 253 } | 238 } |
| 254 | 239 |
| 255 if (!CreateTopWindow(::GetModuleHandleW(NULL), | 240 if (!CreateTopWindow(::GetModuleHandleW(NULL), |
| 256 !cmd_line.HasSwitch(kNoWindow))) { | 241 !cmd_line.HasSwitch(kNoWindow))) { |
| 257 LOG(ERROR) << "could not create window"; | 242 LOG(ERROR) << "could not create window"; |
| 258 if (security_attributes.lpSecurityDescriptor) | 243 if (security_attributes.lpSecurityDescriptor) |
| 259 LocalFree(security_attributes.lpSecurityDescriptor); | 244 LocalFree(security_attributes.lpSecurityDescriptor); |
| 260 return false; | 245 return false; |
| 261 } | 246 } |
| 262 | 247 |
| 263 reporter_tag_ = L"crash svc"; | 248 reporter_tag_ = L"crash svc"; |
| 264 if (cmd_line.HasSwitch(kReporterTag)) | 249 if (cmd_line.HasSwitch(kReporterTag)) |
| 265 reporter_tag_ = cmd_line.GetSwitchValueNative(kReporterTag); | 250 reporter_tag_ = cmd_line.GetSwitchValueNative(kReporterTag); |
| 266 | 251 |
| 267 // Log basic information. | 252 // Log basic information. |
| 268 VLOG(1) << "pipe name is " << pipe_name | 253 VLOG(1) << "pipe name is " << pipe_name |
| 269 << "\ndumps at " << dumps_path.value() | 254 << "\ndumps at " << dumps_path_to_use.value(); |
| 270 << "\nreports at " << report_path_.value(); | |
| 271 | 255 |
| 272 if (sender_) { | 256 if (sender_) { |
| 273 VLOG(1) << "checkpoint is " << checkpoint_path.value() | 257 VLOG(1) << "checkpoint is " << checkpoint_path.value() |
| 274 << "\nserver is " << kCrashReportURL | 258 << "\nserver is " << kCrashReportURL |
| 275 << "\nmaximum " << sender_->max_reports_per_day() << " reports/day" | 259 << "\nmaximum " << sender_->max_reports_per_day() << " reports/day" |
| 276 << "\nreporter is " << reporter_tag_; | 260 << "\nreporter is " << reporter_tag_; |
| 277 } | 261 } |
| 278 // Start servicing clients. | 262 // Start servicing clients. |
| 279 if (!dumper_->Start()) { | 263 if (!dumper_->Start()) { |
| 280 LOG(ERROR) << "could not start dumper"; | 264 LOG(ERROR) << "could not start dumper"; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 SDDL_REVISION, | 478 SDDL_REVISION, |
| 495 &sec_desc, NULL)) { | 479 &sec_desc, NULL)) { |
| 496 if (::GetSecurityDescriptorSacl(sec_desc, &sacl_present, &sacl, | 480 if (::GetSecurityDescriptorSacl(sec_desc, &sacl_present, &sacl, |
| 497 &sacl_defaulted)) { | 481 &sacl_defaulted)) { |
| 498 return sec_desc; | 482 return sec_desc; |
| 499 } | 483 } |
| 500 } | 484 } |
| 501 | 485 |
| 502 return NULL; | 486 return NULL; |
| 503 } | 487 } |
| 488 | |
| 489 } // namespace breakpad | |
| OLD | NEW |