Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(648)

Side by Side Diff: components/arc/crash_collector/arc_crash_collector_bridge.cc

Issue 2367333002: arc: Stop waiting for crash reporter on UI thread (Closed)
Patch Set: Everything on the blocking task runner Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/arc/crash_collector/arc_crash_collector_bridge.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Runs crash_reporter to save the crash info provided via the pipe.
21 void RunCrashReporter(const std::string& crash_type,
22 const std::string& device,
23 const std::string& board,
24 const std::string& cpu_abi,
25 mojo::edk::ScopedPlatformHandle pipe) {
26 base::FileHandleMappingVector fd_map = {
27 std::make_pair(pipe.get().handle, STDIN_FILENO)};
28
29 base::LaunchOptions options;
30 options.fds_to_remap = &fd_map;
31
32 auto process =
33 base::LaunchProcess({kCrashReporterPath, "--arc_java_crash=" + crash_type,
34 "--arc_device=" + device, "--arc_board=" + board,
35 "--arc_cpu_abi=" + cpu_abi},
36 options);
37
38 int exit_code = 0;
39 if (!process.WaitForExit(&exit_code)) {
40 LOG(ERROR) << "Failed to wait for " << kCrashReporterPath;
41 } else if (exit_code != EX_OK) {
42 LOG(ERROR) << kCrashReporterPath << " failed with exit code " << exit_code;
43 }
18 } 44 }
19 45
46 } // namespace
47
20 namespace arc { 48 namespace arc {
21 49
22 ArcCrashCollectorBridge::ArcCrashCollectorBridge(ArcBridgeService* bridge) 50 ArcCrashCollectorBridge::ArcCrashCollectorBridge(
23 : ArcService(bridge), binding_(this) { 51 ArcBridgeService* bridge,
52 scoped_refptr<base::TaskRunner> blocking_task_runner)
53 : ArcService(bridge),
54 blocking_task_runner_(blocking_task_runner),
55 binding_(this) {
24 arc_bridge_service()->crash_collector()->AddObserver(this); 56 arc_bridge_service()->crash_collector()->AddObserver(this);
25 } 57 }
26 58
27 ArcCrashCollectorBridge::~ArcCrashCollectorBridge() { 59 ArcCrashCollectorBridge::~ArcCrashCollectorBridge() {
28 arc_bridge_service()->crash_collector()->RemoveObserver(this); 60 arc_bridge_service()->crash_collector()->RemoveObserver(this);
29 } 61 }
30 62
31 void ArcCrashCollectorBridge::OnInstanceReady() { 63 void ArcCrashCollectorBridge::OnInstanceReady() {
32 mojom::CrashCollectorHostPtr host_ptr; 64 mojom::CrashCollectorHostPtr host_ptr;
33 binding_.Bind(mojo::GetProxy(&host_ptr)); 65 binding_.Bind(mojo::GetProxy(&host_ptr));
34 arc_bridge_service()->crash_collector()->instance()->Init( 66 arc_bridge_service()->crash_collector()->instance()->Init(
35 std::move(host_ptr)); 67 std::move(host_ptr));
36 } 68 }
37 69
38 void ArcCrashCollectorBridge::DumpCrash(const mojo::String& type, 70 void ArcCrashCollectorBridge::DumpCrash(const mojo::String& type,
39 mojo::ScopedHandle pipe) { 71 mojo::ScopedHandle pipe) {
40 mojo::edk::ScopedPlatformHandle handle; 72 mojo::edk::ScopedPlatformHandle pipe_handle;
41 mojo::edk::PassWrappedPlatformHandle(pipe.get().value(), &handle); 73 mojo::edk::PassWrappedPlatformHandle(pipe.get().value(), &pipe_handle);
42 74
43 base::FileHandleMappingVector fd_map = { 75 blocking_task_runner_->PostTask(
44 std::make_pair(handle.get().handle, STDIN_FILENO)}; 76 FROM_HERE, base::Bind(&RunCrashReporter, type, device_, board_, cpu_abi_,
45 77 base::Passed(std::move(pipe_handle))));
46 base::LaunchOptions options;
47 options.fds_to_remap = &fd_map;
48
49 auto process =
50 base::LaunchProcess({kCrashReporterPath, "--arc_java_crash=" + type.get(),
51 "--arc_device=" + device_, "--arc_board=" + board_,
52 "--arc_cpu_abi=" + cpu_abi_},
53 options);
54
55 int exit_code;
56 if (!process.WaitForExit(&exit_code)) {
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 } 78 }
62 79
63 void ArcCrashCollectorBridge::SetBuildProperties(const mojo::String& device, 80 void ArcCrashCollectorBridge::SetBuildProperties(const mojo::String& device,
64 const mojo::String& board, 81 const mojo::String& board,
65 const mojo::String& cpu_abi) { 82 const mojo::String& cpu_abi) {
66 device_ = device.get(); 83 device_ = device.get();
67 board_ = board.get(); 84 board_ = board.get();
68 cpu_abi_ = cpu_abi.get(); 85 cpu_abi_ = cpu_abi.get();
69 } 86 }
70 87
71 } // namespace arc 88 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/crash_collector/arc_crash_collector_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698