win: Setup crash service according to command line parameters.
authorCheng Zhao <zcbenz@gmail.com>
Sun, 24 Nov 2013 12:33:26 +0000 (20:33 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 24 Nov 2013 12:33:26 +0000 (20:33 +0800)
common/crash_reporter/win/crash_service.cc
common/crash_reporter/win/crash_service.h
common/crash_reporter/win/crash_service_main.cc

index ab4c81a..202c479 100644 (file)
@@ -24,7 +24,7 @@ namespace {
 
 const wchar_t kTestPipeName[] = L"\\\\.\\pipe\\ChromeCrashServices";
 
-const wchar_t kCrashReportURL[] = L"https://clients2.google.com/cr/report";
+const wchar_t kGoogleReportURL[] = L"https://clients2.google.com/cr/report";
 const wchar_t kCheckPointFile[] = L"crash_checkpoint.txt";
 
 typedef std::map<std::wstring, std::wstring> CrashMap;
@@ -150,6 +150,7 @@ const char CrashService::kNoWindow[]          = "no-window";
 const char CrashService::kReporterTag[]       = "reporter";
 const char CrashService::kDumpsDir[]          = "dumps-dir";
 const char CrashService::kPipeName[]          = "pipe-name";
+const char CrashService::kReporterURL[]       = "reporter-url";
 
 CrashService::CrashService()
     : sender_(NULL),
@@ -195,10 +196,6 @@ bool CrashService::Initialize(const base::FilePath& operating_dir,
   if (cmd_line.HasSwitch(kPipeName))
     pipe_name = cmd_line.GetSwitchValueNative(kPipeName);
 
-#ifdef _WIN64
-  pipe_name += L"-x64";
-#endif
-
   if (max_reports > 0) {
     // Create the http sender object.
     sender_ = new CrashReportSender(checkpoint_path.value());
@@ -248,13 +245,17 @@ bool CrashService::Initialize(const base::FilePath& operating_dir,
   if (cmd_line.HasSwitch(kReporterTag))
     reporter_tag_ = cmd_line.GetSwitchValueNative(kReporterTag);
 
+  reporter_url_ = kGoogleReportURL;
+  if (cmd_line.HasSwitch(kReporterURL))
+    reporter_url_ = cmd_line.GetSwitchValueNative(kReporterURL);
+
   // Log basic information.
   VLOG(1) << "pipe name is " << pipe_name
           << "\ndumps at " << dumps_path_to_use.value();
 
   if (sender_) {
     VLOG(1) << "checkpoint is " << checkpoint_path.value()
-            << "\nserver is " << kCrashReportURL
+            << "\nserver is " << reporter_url_
             << "\nmaximum " << sender_->max_reports_per_day() << " reports/day"
             << "\nreporter is " << reporter_tag_;
   }
@@ -406,8 +407,10 @@ DWORD CrashService::AsyncSendDump(void* context) {
       base::AutoLock lock(info->self->sending_);
       VLOG(1) << "trying to send report for pid = " << info->pid;
       google_breakpad::ReportResult send_result
-          = info->self->sender_->SendCrashReport(kCrashReportURL, info->map,
-                                                 info->dump_path, &report_id);
+          = info->self->sender_->SendCrashReport(info->self->reporter_url_,
+                                                 info->map,
+                                                 info->dump_path,
+                                                 &report_id);
       switch (send_result) {
         case google_breakpad::RESULT_FAILED:
           report_id = L"<network issue>";
index de1d856..1958571 100644 (file)
@@ -64,6 +64,9 @@ class CrashService {
   // Override the name of the Windows named pipe on which we will
   // listen for crash dump request messages.
   static const char kPipeName[];
+  // --reporter-url=<string>
+  // Override the URL to which crash reports will be sent to.
+  static const char kReporterURL[];
 
   // Returns number of crash dumps handled.
   int requests_handled() const {
@@ -110,6 +113,9 @@ class CrashService {
   // the extra tag sent to the server with each dump.
   std::wstring reporter_tag_;
 
+  // receiver URL of crash reports.
+  std::wstring reporter_url_;
+
   // clients serviced statistics:
   int requests_handled_;
   int requests_sent_;
index a87ac34..46f9690 100644 (file)
 #include "base/files/file_path.h"
 #include "base/path_service.h"
 #include "base/logging.h"
+#include "base/string_util.h"
 #include "common/crash_reporter/win/crash_service.h"
 
 namespace crash_service {
 
 namespace {
 
+const char kApplicationName[] = "application-name";
+const wchar_t kPipeNameFormat[] = L"\\\\.\\pipe\\$1CrashService";
 const wchar_t kStandardLogFile[] = L"operation_log.txt";
 
-bool GetCrashServiceDirectory(base::FilePath* dir) {
+bool GetCrashServiceDirectory(const std::wstring& application_name,
+                              base::FilePath* dir) {
   base::FilePath temp_dir;
   if (!file_util::GetTempDir(&temp_dir))
     return false;
-  temp_dir = temp_dir.Append(L"atom_crashes");
+  temp_dir = temp_dir.Append(application_name + L" Crashes");
   if (!file_util::PathExists(temp_dir)) {
     if (!file_util::CreateDirectory(temp_dir))
       return false;
@@ -33,14 +37,24 @@ bool GetCrashServiceDirectory(base::FilePath* dir) {
 
 }  // namespace.
 
-int Main(const wchar_t* cmd_line) {
+int Main(const wchar_t* cmd) {
   // Initialize all Chromium things.
   base::AtExitManager exit_manager;
   CommandLine::Init(0, NULL);
+  CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
+
+  // Use the application's name as pipe name and output directory.
+  if (!cmd_line.HasSwitch(kApplicationName)) {
+    LOG(ERROR) << "Application's name must be specified with --"
+               << kApplicationName;
+    return 1;
+  }
+  std::wstring application_name = cmd_line.GetSwitchValueNative(
+      kApplicationName);
 
   // We use/create a directory under the user's temp folder, for logging.
   base::FilePath operating_dir;
-  GetCrashServiceDirectory(&operating_dir);
+  GetCrashServiceDirectory(application_name, &operating_dir);
   base::FilePath log_file = operating_dir.Append(kStandardLogFile);
 
   // Logging out to a file.
@@ -52,11 +66,20 @@ int Main(const wchar_t* cmd_line) {
       logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
   logging::SetLogItems(true, false, true, false);
 
-  VLOG(1) << "Session start. cmdline is [" << cmd_line << "]";
+  VLOG(1) << "Session start. cmdline is [" << cmd << "]";
+
+  // Setting the crash reporter.
+  string16 pipe_name = ReplaceStringPlaceholders(kPipeNameFormat,
+                                                 application_name,
+                                                 NULL);
+  cmd_line.AppendSwitch("no-window");
+  cmd_line.AppendSwitchASCII("max-reports", "128");
+  cmd_line.AppendSwitchASCII("reporter", "atom-shell-crash-service");
+  cmd_line.AppendSwitchNative("pipe-name", pipe_name);
 
   breakpad::CrashService crash_service;
   if (!crash_service.Initialize(operating_dir, operating_dir))
-    return 1;
+    return 2;
 
   VLOG(1) << "Ready to process crash requests";