Index: chrome/app/chrome_exe_main_win.cc |
diff --git a/chrome/app/chrome_exe_main_win.cc b/chrome/app/chrome_exe_main_win.cc |
index a5f8ee124e617a8a158531cfd6a0b1ee14db545f..c8e1a6e073f024cefab64b9f1e79ef8ff5847f75 100644 |
--- a/chrome/app/chrome_exe_main_win.cc |
+++ b/chrome/app/chrome_exe_main_win.cc |
@@ -4,6 +4,7 @@ |
#include <windows.h> |
#include <malloc.h> |
+#include <shellapi.h> |
#include <shellscalingapi.h> |
#include <tchar.h> |
@@ -13,6 +14,7 @@ |
#include "base/command_line.h" |
#include "base/files/file_path.h" |
#include "base/logging.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
#include "base/win/windows_version.h" |
#include "chrome/app/main_dll_loader_win.h" |
@@ -23,6 +25,8 @@ |
#include "chrome_elf/chrome_elf_main.h" |
#include "components/startup_metric_utils/browser/startup_metric_utils.h" |
#include "content/public/common/result_codes.h" |
+#include "third_party/crashpad/crashpad/handler/handler_main.h" |
+#include "third_party/crashpad/crashpad/util/win/scoped_local_alloc.h" |
#include "ui/gfx/win/dpi.h" |
namespace { |
@@ -121,6 +125,35 @@ void SwitchToLFHeap() { |
} |
} |
+bool RunAsCrashpadHandlerIfSpecified(int* rc) { |
cpu_(ooo_6.6-7.5)
2015/11/06 23:16:48
don't like the "IfSpecified"
scottmg
2015/11/07 00:39:43
Done.
|
+ int num_args; |
+ wchar_t** args = CommandLineToArgvW(GetCommandLine(), &num_args); |
+ crashpad::ScopedLocalAlloc scoped_args(args); // Take ownership. |
+ PCHECK(args) << "CommandLineToArgvW"; |
+ |
+ for (int i = 1; i < num_args; ++i) { |
+ if (wcscmp(args[i], L"--crashpad_handler") == 0) { |
+ // We're dropping args[i], so reserve one less than num_args for the |
cpu_(ooo_6.6-7.5)
2015/11/06 23:16:48
is this not possible with base/command_line ?
scottmg
2015/11/07 00:39:42
I have trust issues with how much that code does.
|
+ // arrays, but add an extra trailing null for the getopt implementation. |
+ scoped_ptr<char* []> argv_as_utf8(new char*[num_args]); |
+ std::vector<std::string> storage; |
+ storage.reserve(num_args - 1); |
+ for (int j = 0; j < num_args; ++j) { |
+ if (j == i) |
+ continue; |
+ storage.push_back(base::UTF16ToUTF8(args[j])); |
+ } |
+ DCHECK_EQ(storage.size(), static_cast<size_t>(num_args - 1)); |
+ for (size_t j = 0; j < storage.size(); ++j) |
+ argv_as_utf8[j] = &storage[j][0]; |
+ argv_as_utf8[num_args - 1] = nullptr; |
+ *rc = crashpad::HandlerMain(num_args - 1, argv_as_utf8.get()); |
+ return true; |
+ } |
+ } |
+ return false; |
+} |
+ |
} // namespace |
#if !defined(ADDRESS_SANITIZER) |
@@ -131,6 +164,11 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
int main() { |
HINSTANCE instance = GetModuleHandle(NULL); |
#endif |
+ int rc; |
+ if (RunAsCrashpadHandlerIfSpecified(&rc)) { |
+ return rc; |
+ } |
+ |
SwitchToLFHeap(); |
startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); |
@@ -155,7 +193,7 @@ int main() { |
// Load and launch the chrome dll. *Everything* happens inside. |
VLOG(1) << "About to load main DLL."; |
MainDllLoader* loader = MakeMainDllLoader(); |
- int rc = loader->Launch(instance); |
+ rc = loader->Launch(instance); |
loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
delete loader; |
return rc; |