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 <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "third_party/crashpad/crashpad/handler/handler_main.h" | 16 #include "third_party/crashpad/crashpad/handler/handler_main.h" |
17 | 17 |
18 namespace crash_reporter { | 18 namespace crash_reporter { |
19 | 19 |
20 int RunAsCrashpadHandler(const base::CommandLine& command_line) { | 20 int RunAsCrashpadHandler(const base::CommandLine& command_line) { |
21 std::vector<base::string16> argv = command_line.argv(); | 21 std::vector<base::string16> argv = command_line.argv(); |
22 const base::string16 process_type = L"--type="; | 22 const base::string16 process_type = L"--type="; |
23 argv.erase(std::remove_if(argv.begin(), argv.end(), | 23 argv.erase(std::remove_if(argv.begin(), argv.end(), |
24 [&process_type](const base::string16& str) { | 24 [&process_type](const base::string16& str) { |
25 return base::StartsWith( | 25 return base::StartsWith( |
26 str, process_type, | 26 str, process_type, |
27 base::CompareCase::SENSITIVE) || | 27 base::CompareCase::SENSITIVE) || |
28 (!str.empty() && str[0] == L'/'); | 28 (!str.empty() && str[0] == L'/'); |
29 }), | 29 }), |
30 argv.end()); | 30 argv.end()); |
31 | 31 |
32 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); | 32 std::unique_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); |
33 std::vector<std::string> storage; | 33 std::vector<std::string> storage; |
34 storage.reserve(argv.size()); | 34 storage.reserve(argv.size()); |
35 for (size_t i = 0; i < argv.size(); ++i) { | 35 for (size_t i = 0; i < argv.size(); ++i) { |
36 storage.push_back(base::UTF16ToUTF8(argv[i])); | 36 storage.push_back(base::UTF16ToUTF8(argv[i])); |
37 argv_as_utf8[i] = &storage[i][0]; | 37 argv_as_utf8[i] = &storage[i][0]; |
38 } | 38 } |
39 argv_as_utf8[argv.size()] = nullptr; | 39 argv_as_utf8[argv.size()] = nullptr; |
40 argv.clear(); | 40 argv.clear(); |
41 return crashpad::HandlerMain(static_cast<int>(storage.size()), | 41 return crashpad::HandlerMain(static_cast<int>(storage.size()), |
42 argv_as_utf8.get()); | 42 argv_as_utf8.get()); |
43 } | 43 } |
44 | 44 |
45 } // namespace crash_reporter | 45 } // namespace crash_reporter |
OLD | NEW |