Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/crash/content/app/run_as_crashpad_handler_win.h" | 5 #include "components/crash/content/app/run_as_crashpad_handler_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/memory/ptr_util.h" | |
| 13 #include "base/process/memory.h" | 14 #include "base/process/memory.h" |
| 14 #include "base/strings/string16.h" | |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "components/browser_watcher/stability_report_user_stream_data_source.h" | |
| 17 #include "third_party/crashpad/crashpad/client/crashpad_info.h" | 18 #include "third_party/crashpad/crashpad/client/crashpad_info.h" |
| 18 #include "third_party/crashpad/crashpad/client/simple_string_dictionary.h" | 19 #include "third_party/crashpad/crashpad/client/simple_string_dictionary.h" |
| 19 #include "third_party/crashpad/crashpad/handler/handler_main.h" | 20 #include "third_party/crashpad/crashpad/handler/handler_main.h" |
| 21 #include "third_party/crashpad/crashpad/handler/user_stream_data_source.h" | |
| 20 | 22 |
| 21 namespace crash_reporter { | 23 namespace crash_reporter { |
| 22 | 24 |
| 23 int RunAsCrashpadHandler(const base::CommandLine& command_line, | 25 int RunAsCrashpadHandler(const base::CommandLine& command_line, |
| 24 const char* process_type_switch) { | 26 const base::string16& user_data_dir, |
| 27 const char* process_type_switch, | |
| 28 const char* user_data_dir_switch) { | |
| 25 // Make sure this process terminates on OOM in the same mode as other Chrome | 29 // Make sure this process terminates on OOM in the same mode as other Chrome |
| 26 // processes. | 30 // processes. |
| 27 base::EnableTerminationOnOutOfMemory(); | 31 base::EnableTerminationOnOutOfMemory(); |
| 28 | 32 |
| 29 // If the handler is started with --monitor-self, it'll need a ptype | 33 // If the handler is started with --monitor-self, it'll need a ptype |
| 30 // annotation set. It'll normally set one itself by being invoked with | 34 // annotation set. It'll normally set one itself by being invoked with |
| 31 // --monitor-self-annotation=ptype=crashpad-handler, but that leaves a window | 35 // --monitor-self-annotation=ptype=crashpad-handler, but that leaves a window |
| 32 // during self-monitoring initialization when the ptype is not set at all, so | 36 // during self-monitoring initialization when the ptype is not set at all, so |
| 33 // provide one here. | 37 // provide one here. |
| 34 const std::string process_type = | 38 const std::string process_type = |
| 35 command_line.GetSwitchValueASCII(process_type_switch); | 39 command_line.GetSwitchValueASCII(process_type_switch); |
| 36 if (!process_type.empty()) { | 40 if (!process_type.empty()) { |
| 37 crashpad::SimpleStringDictionary* annotations = | 41 crashpad::SimpleStringDictionary* annotations = |
| 38 new crashpad::SimpleStringDictionary(); | 42 new crashpad::SimpleStringDictionary(); |
| 39 annotations->SetKeyValue("ptype", process_type.c_str()); | 43 annotations->SetKeyValue("ptype", process_type.c_str()); |
| 40 crashpad::CrashpadInfo* crashpad_info = | 44 crashpad::CrashpadInfo* crashpad_info = |
| 41 crashpad::CrashpadInfo::GetCrashpadInfo(); | 45 crashpad::CrashpadInfo::GetCrashpadInfo(); |
| 42 DCHECK(!crashpad_info->simple_annotations()); | 46 DCHECK(!crashpad_info->simple_annotations()); |
| 43 crashpad_info->set_simple_annotations(annotations); | 47 crashpad_info->set_simple_annotations(annotations); |
| 44 } | 48 } |
| 45 | 49 |
| 46 std::vector<base::string16> argv = command_line.argv(); | 50 std::vector<base::string16> argv = command_line.argv(); |
| 47 const base::string16 process_type_arg_prefix = | 51 const base::string16 process_type_arg_prefix = |
| 48 base::string16(L"--") + base::UTF8ToUTF16(process_type_switch) + L"="; | 52 base::string16(L"--") + base::UTF8ToUTF16(process_type_switch) + L"="; |
| 53 const base::string16 user_data_dir_arg_prefix = | |
| 54 base::string16(L"--") + base::UTF8ToUTF16(user_data_dir_switch) + L"="; | |
| 49 argv.erase( | 55 argv.erase( |
| 50 std::remove_if(argv.begin(), argv.end(), | 56 std::remove_if(argv.begin(), argv.end(), |
| 51 [&process_type_arg_prefix](const base::string16& str) { | 57 [&process_type_arg_prefix, |
| 58 &user_data_dir_arg_prefix](const base::string16& str) { | |
| 52 return base::StartsWith(str, process_type_arg_prefix, | 59 return base::StartsWith(str, process_type_arg_prefix, |
| 53 base::CompareCase::SENSITIVE) || | 60 base::CompareCase::SENSITIVE) || |
| 61 base::StartsWith(str, user_data_dir_arg_prefix, | |
| 62 base::CompareCase::SENSITIVE) || | |
| 54 (!str.empty() && str[0] == L'/'); | 63 (!str.empty() && str[0] == L'/'); |
| 55 }), | 64 }), |
| 56 argv.end()); | 65 argv.end()); |
| 57 | 66 |
| 58 std::unique_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); | 67 std::unique_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); |
| 59 std::vector<std::string> storage; | 68 std::vector<std::string> storage; |
| 60 storage.reserve(argv.size()); | 69 storage.reserve(argv.size()); |
| 61 for (size_t i = 0; i < argv.size(); ++i) { | 70 for (size_t i = 0; i < argv.size(); ++i) { |
| 62 storage.push_back(base::UTF16ToUTF8(argv[i])); | 71 storage.push_back(base::UTF16ToUTF8(argv[i])); |
| 63 argv_as_utf8[i] = &storage[i][0]; | 72 argv_as_utf8[i] = &storage[i][0]; |
| 64 } | 73 } |
| 65 argv_as_utf8[argv.size()] = nullptr; | 74 argv_as_utf8[argv.size()] = nullptr; |
| 66 argv.clear(); | 75 argv.clear(); |
| 76 | |
| 77 crashpad::UserStreamDataSources user_stream_data_sources; | |
| 78 // Interpret an empty user data directory as a missing value. | |
| 79 if (!user_data_dir.empty()) { | |
| 80 // Register an extension to collect stability information. The extension | |
| 81 // will be invoked for any registered process' crashes, but information only | |
| 82 // exists for instrumented browser processes. | |
| 83 user_stream_data_sources.push_back(base::WrapUnique( | |
|
grt (UTC plus 2)
2017/05/11 21:08:16
base::MakeUnique<browser_watcher::StabilityReportU
manzagop (departed)
2017/05/12 19:27:32
Done.
| |
| 84 new browser_watcher::StabilityReportUserStreamDataSource( | |
| 85 user_data_dir))); | |
| 86 } | |
| 87 | |
| 67 return crashpad::HandlerMain(static_cast<int>(storage.size()), | 88 return crashpad::HandlerMain(static_cast<int>(storage.size()), |
| 68 argv_as_utf8.get(), nullptr); | 89 argv_as_utf8.get(), &user_stream_data_sources); |
| 69 } | 90 } |
| 70 | 91 |
| 71 } // namespace crash_reporter | 92 } // namespace crash_reporter |
| OLD | NEW |