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/arc/crash_collector/arc_crash_collector_bridge.h" | 5 #include "components/arc/crash_collector/arc_crash_collector_bridge.h" |
| 6 | 6 |
| 7 #include <sysexits.h> | 7 #include <sysexits.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/process/launch.h" | 13 #include "base/process/launch.h" |
| 14 #include "mojo/edk/embedder/embedder.h" | 14 #include "mojo/edk/embedder/embedder.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | |
| 17 const char kCrashReporterPath[] = "/sbin/crash_reporter"; | 18 const char kCrashReporterPath[] = "/sbin/crash_reporter"; |
| 19 | |
| 20 // Waits for the process to exit. | |
| 21 void WaitForProcessToExit(base::Process process) { | |
| 22 int exit_code = 0; | |
| 23 if (!process.WaitForExit(&exit_code)) { | |
| 24 LOG(ERROR) << "Failed to wait for " << kCrashReporterPath; | |
| 25 } else if (exit_code != EX_OK) { | |
| 26 LOG(ERROR) << kCrashReporterPath << " failed with exit code " << exit_code; | |
| 27 } | |
| 28 } | |
| 29 | |
| 18 } | 30 } |
| 19 | 31 |
| 20 namespace arc { | 32 namespace arc { |
| 21 | 33 |
| 22 ArcCrashCollectorBridge::ArcCrashCollectorBridge(ArcBridgeService* bridge) | 34 ArcCrashCollectorBridge::ArcCrashCollectorBridge( |
| 23 : ArcService(bridge), binding_(this) { | 35 ArcBridgeService* bridge, |
| 36 scoped_refptr<base::TaskRunner> blocking_task_runner) | |
| 37 : ArcService(bridge), | |
| 38 blocking_task_runner_(blocking_task_runner), | |
| 39 binding_(this) { | |
| 24 arc_bridge_service()->crash_collector()->AddObserver(this); | 40 arc_bridge_service()->crash_collector()->AddObserver(this); |
| 25 } | 41 } |
| 26 | 42 |
| 27 ArcCrashCollectorBridge::~ArcCrashCollectorBridge() { | 43 ArcCrashCollectorBridge::~ArcCrashCollectorBridge() { |
| 28 arc_bridge_service()->crash_collector()->RemoveObserver(this); | 44 arc_bridge_service()->crash_collector()->RemoveObserver(this); |
| 29 } | 45 } |
| 30 | 46 |
| 31 void ArcCrashCollectorBridge::OnInstanceReady() { | 47 void ArcCrashCollectorBridge::OnInstanceReady() { |
| 32 mojom::CrashCollectorHostPtr host_ptr; | 48 mojom::CrashCollectorHostPtr host_ptr; |
| 33 binding_.Bind(mojo::GetProxy(&host_ptr)); | 49 binding_.Bind(mojo::GetProxy(&host_ptr)); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 44 std::make_pair(handle.get().handle, STDIN_FILENO)}; | 60 std::make_pair(handle.get().handle, STDIN_FILENO)}; |
| 45 | 61 |
| 46 base::LaunchOptions options; | 62 base::LaunchOptions options; |
| 47 options.fds_to_remap = &fd_map; | 63 options.fds_to_remap = &fd_map; |
| 48 | 64 |
| 49 auto process = | 65 auto process = |
| 50 base::LaunchProcess({kCrashReporterPath, "--arc_java_crash=" + type.get(), | 66 base::LaunchProcess({kCrashReporterPath, "--arc_java_crash=" + type.get(), |
| 51 "--arc_device=" + device_, "--arc_board=" + board_, | 67 "--arc_device=" + device_, "--arc_board=" + board_, |
| 52 "--arc_cpu_abi=" + cpu_abi_}, | 68 "--arc_cpu_abi=" + cpu_abi_}, |
| 53 options); | 69 options); |
| 54 | 70 blocking_task_runner_->PostTask(FROM_HERE, |
|
hidehiko
2016/09/26 14:17:22
Optional: How about moving everything, incl. Launc
hashimoto
2016/09/27 06:48:26
Done.
| |
| 55 int exit_code; | 71 base::Bind(&WaitForProcessToExit, |
| 56 if (!process.WaitForExit(&exit_code)) { | 72 base::Passed(std::move(process)))); |
| 57 LOG(ERROR) << "Failed to wait for " << kCrashReporterPath; | |
| 58 } else if (exit_code != EX_OK) { | |
| 59 LOG(ERROR) << kCrashReporterPath << " failed with exit code " << exit_code; | |
| 60 } | |
| 61 } | 73 } |
| 62 | 74 |
| 63 void ArcCrashCollectorBridge::SetBuildProperties(const mojo::String& device, | 75 void ArcCrashCollectorBridge::SetBuildProperties(const mojo::String& device, |
| 64 const mojo::String& board, | 76 const mojo::String& board, |
| 65 const mojo::String& cpu_abi) { | 77 const mojo::String& cpu_abi) { |
| 66 device_ = device.get(); | 78 device_ = device.get(); |
| 67 board_ = board.get(); | 79 board_ = board.get(); |
| 68 cpu_abi_ = cpu_abi.get(); | 80 cpu_abi_ = cpu_abi.get(); |
| 69 } | 81 } |
| 70 | 82 |
| 71 } // namespace arc | 83 } // namespace arc |
| OLD | NEW |