Use different name for wait events for different apps
authorCheng Zhao <zcbenz@gmail.com>
Tue, 4 Aug 2015 11:30:35 +0000 (19:30 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 4 Aug 2015 11:30:35 +0000 (19:30 +0800)
atom/common/crash_reporter/crash_reporter_win.cc
atom/common/crash_reporter/win/crash_service.cc
atom/common/crash_reporter/win/crash_service.h
atom/common/crash_reporter/win/crash_service_main.cc

index 5c4f9fb..be096da 100644 (file)
@@ -21,6 +21,7 @@ const MINIDUMP_TYPE kSmallDumpType = static_cast<MINIDUMP_TYPE>(
     MiniDumpWithProcessThreadData |  // Get PEB and TEB.
     MiniDumpWithUnloadedModules);  // Get unloaded modules when available.
 
+const wchar_t kWaitEventFormat[] = L"$1CrashServiceWaitEvent";
 const wchar_t kPipeNameFormat[] = L"\\\\.\\pipe\\$1 Crash Service";
 
 }  // namespace
@@ -47,13 +48,14 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name,
 
   base::string16 pipe_name = ReplaceStringPlaceholders(
       kPipeNameFormat, base::UTF8ToUTF16(product_name), NULL);
+  base::string16 wait_name = ReplaceStringPlaceholders(
+      kWaitEventFormat, base::UTF8ToUTF16(product_name), NULL);
 
   // Wait until the crash service is started.
-  HANDLE waiting_event =
-      ::CreateEventW(NULL, TRUE, FALSE, L"g_atom_shell_crash_service");
-  if (waiting_event != NULL) {
-    WaitForSingleObject(waiting_event, 1000);
-    CloseHandle(waiting_event);
+  HANDLE wait_event = ::CreateEventW(NULL, TRUE, FALSE, wait_name.c_str());
+  if (wait_event != NULL) {
+    WaitForSingleObject(wait_event, 1000);
+    CloseHandle(wait_event);
   }
 
   // ExceptionHandler() attaches our handler and ~ExceptionHandler() detaches
index 10e0fdf..611c392 100644 (file)
@@ -14,6 +14,7 @@
 #include "base/files/file_util.h"
 #include "base/logging.h"
 #include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
 #include "base/time/time.h"
 #include "base/win/windows_version.h"
 #include "vendor/breakpad/src/client/windows/crash_generation/client_info.h"
@@ -24,6 +25,7 @@ namespace breakpad {
 
 namespace {
 
+const wchar_t kWaitEventFormat[] = L"$1CrashServiceWaitEvent";
 const wchar_t kTestPipeName[] = L"\\\\.\\pipe\\ChromeCrashServices";
 
 const wchar_t kGoogleReportURL[] = L"https://clients2.google.com/cr/report";
@@ -193,7 +195,8 @@ CrashService::~CrashService() {
   delete sender_;
 }
 
-bool CrashService::Initialize(const base::FilePath& operating_dir,
+bool CrashService::Initialize(const base::string16& application_name,
+                              const base::FilePath& operating_dir,
                               const base::FilePath& dumps_path) {
   using google_breakpad::CrashReportSender;
   using google_breakpad::CrashGenerationServer;
@@ -298,11 +301,10 @@ bool CrashService::Initialize(const base::FilePath& operating_dir,
 
   // Create or open an event to signal the browser process that the crash
   // service is initialized.
-  HANDLE running_event =
-      ::CreateEventW(NULL, TRUE, TRUE, L"g_atom_shell_crash_service");
-  // If the browser already had the event open, the CreateEvent call did not
-  // signal it. We need to do it manually.
-  ::SetEvent(running_event);
+  base::string16 wait_name = ReplaceStringPlaceholders(
+      kWaitEventFormat, application_name, NULL);
+  HANDLE wait_event = ::CreateEventW(NULL, TRUE, FALSE, wait_name.c_str());
+  ::SetEvent(wait_event);
 
   return true;
 }
index 730e4da..7195ec2 100644 (file)
@@ -37,7 +37,8 @@ class CrashService {
   // other members in that case. |operating_dir| is where the CrashService
   // should store breakpad's checkpoint file. |dumps_path| is the directory
   // where the crash dumps should be stored.
-  bool Initialize(const base::FilePath& operating_dir,
+  bool Initialize(const base::string16& application_name,
+                  const base::FilePath& operating_dir,
                   const base::FilePath& dumps_path);
 
   // Command line switches:
index 0bd72de..7a5eeb1 100644 (file)
@@ -77,7 +77,8 @@ int Main(const wchar_t* cmd) {
   cmd_line.AppendSwitchNative("pipe-name", pipe_name);
 
   breakpad::CrashService crash_service;
-  if (!crash_service.Initialize(operating_dir, operating_dir))
+  if (!crash_service.Initialize(application_name, operating_dir,
+                                operating_dir))
     return 2;
 
   VLOG(1) << "Ready to process crash requests";