OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "android_webview/browser/aw_browser_terminator.h" | |
6 | |
7 #include <unistd.h> | |
8 | |
9 #include "android_webview/common/aw_descriptors.h" | |
10 #include "base/bind.h" | |
11 #include "base/logging.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/browser/child_process_data.h" | |
14 #include "content/public/browser/notification_service.h" | |
15 #include "content/public/browser/notification_types.h" | |
16 #include "content/public/browser/render_process_host.h" | |
17 | |
18 namespace android_webview { | |
19 | |
20 AwBrowserTerminator::AwBrowserTerminator() {} | |
21 | |
22 AwBrowserTerminator::~AwBrowserTerminator() { | |
23 child_process_id_to_pipe_.clear(); | |
Bernhard Bauer
2016/08/04 16:01:32
Is this actually necessary if you're in the destru
Tobias Sargeant
2016/08/05 14:59:21
Agree, it's not necessary.
| |
24 } | |
25 | |
26 void AwBrowserTerminator::OnChildStart(int child_process_id, | |
27 content::FileDescriptorInfo* mappings) { | |
28 base::AutoLock auto_lock(child_process_id_to_pipe_lock_); | |
29 DCHECK(!ContainsKey(child_process_id_to_pipe_, child_process_id)); | |
Robert Sesek
2016/08/04 16:59:01
Should this be just a DCHECK? This code will conti
Robert Sesek
2016/08/04 16:59:01
IWYU: base/stl_util.h
Tobias Sargeant
2016/08/05 14:59:21
The danger of overwriting one pid->pipe mapping (a
Tobias Sargeant
2016/08/05 14:59:21
Done.
| |
30 | |
31 std::unique_ptr<base::SyncSocket> local_pipe(new base::SyncSocket()); | |
32 std::unique_ptr<base::SyncSocket> child_pipe(new base::SyncSocket()); | |
33 if (base::SyncSocket::CreatePair(local_pipe.get(), child_pipe.get())) { | |
34 LOG(WARNING) << "tobiasjs: mapping: " << child_process_id << " to " | |
Bernhard Bauer
2016/08/04 16:01:32
Nit: You might not want to immortalize yourself in
Tobias Sargeant
2016/08/05 14:59:21
Definitely not!
| |
35 << local_pipe->handle(); | |
36 child_process_id_to_pipe_[child_process_id] = std::move(local_pipe); | |
37 mappings->Transfer(kAndroidWebViewCrashSignalDescriptor, | |
38 base::ScopedFD(dup(child_pipe->handle()))); | |
39 } | |
40 } | |
41 | |
42 void AwBrowserTerminator::OnChildExit( | |
43 int child_process_id, | |
44 base::ProcessHandle pid, | |
45 content::ProcessType process_type, | |
46 base::TerminationStatus termination_status, | |
47 base::android::ApplicationState app_state) { | |
48 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | |
Bernhard Bauer
2016/08/04 16:01:32
Is there a particular reason you need the FILE thr
| |
49 LOG(WARNING) << "tobiasjs: " << __PRETTY_FUNCTION__ << " child_process_id " | |
50 << child_process_id << " pid " << pid << " process_type " | |
51 << process_type << " termination_status " << termination_status | |
52 << " app_state " << app_state; | |
53 std::unique_ptr<base::SyncSocket> pipe; | |
54 | |
55 { | |
56 base::AutoLock auto_lock(child_process_id_to_pipe_lock_); | |
57 const auto& iter = child_process_id_to_pipe_.find(child_process_id); | |
58 if (iter == child_process_id_to_pipe_.end()) { | |
59 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a | |
60 // NOTIFICATION_RENDERER_PROCESS_CLOSED. | |
61 return; | |
62 } | |
63 pipe = std::move(iter->second); | |
64 child_process_id_to_pipe_.erase(iter); | |
65 } | |
66 LOG(WARNING) << "tobiasjs: found pipe " << pipe->handle(); | |
67 DCHECK(pipe->handle() != base::SyncSocket::kInvalidHandle); | |
68 LOG(WARNING) << "tobiasjs: pipe is valid"; | |
69 | |
70 if (termination_status == base::TERMINATION_STATUS_NORMAL_TERMINATION) | |
71 return; | |
72 LOG(WARNING) << "tobiasjs: termination status is not normal"; | |
73 if (pipe->Peek() >= sizeof(int)) { | |
74 int exit_code; | |
75 pipe->Receive(&exit_code, sizeof(exit_code)); | |
76 LOG(WARNING) << "tobiasjs: read exit code " << exit_code << " and dying"; | |
77 LOG(FATAL) << "Renderer process crash detected (code " << exit_code | |
78 << "). Terminating browser."; | |
79 } else { | |
80 // The child process hasn't written anything into the pipe. This implies | |
81 // that it was terminated via SIGKILL by the low memory killer, and thus we | |
82 // need to perform a clean exit. | |
83 LOG(WARNING) << "tobiasjs: clean exit"; | |
84 exit(0); | |
85 } | |
86 } | |
87 | |
88 } // namespace breakpad | |
OLD | NEW |