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 "base/stl_util.h" | |
13 #include "base/sync_socket.h" | |
14 #include "content/public/browser/browser_thread.h" | |
15 #include "content/public/browser/child_process_data.h" | |
16 #include "content/public/browser/notification_service.h" | |
17 #include "content/public/browser/notification_types.h" | |
18 #include "content/public/browser/render_process_host.h" | |
19 | |
20 using content::BrowserThread; | |
21 | |
22 namespace android_webview { | |
23 | |
24 AwBrowserTerminator::AwBrowserTerminator() {} | |
25 | |
26 AwBrowserTerminator::~AwBrowserTerminator() {} | |
27 | |
28 void AwBrowserTerminator::OnChildStart(int child_process_id, | |
29 content::FileDescriptorInfo* mappings) { | |
30 DCHECK_CURRENTLY_ON(content::BrowserThread::PROCESS_LAUNCHER); | |
31 | |
32 base::AutoLock auto_lock(child_process_id_to_pipe_lock_); | |
33 DCHECK(!ContainsKey(child_process_id_to_pipe_, child_process_id)); | |
34 | |
35 auto local_pipe = base::MakeUnique<base::SyncSocket>(); | |
36 auto child_pipe = base::MakeUnique<base::SyncSocket>(); | |
37 if (base::SyncSocket::CreatePair(local_pipe.get(), child_pipe.get())) { | |
38 child_process_id_to_pipe_[child_process_id] = std::move(local_pipe); | |
39 mappings->Transfer(kAndroidWebViewCrashSignalDescriptor, | |
40 base::ScopedFD(dup(child_pipe->handle()))); | |
41 } | |
42 } | |
43 | |
44 void AwBrowserTerminator::ProcessTerminationStatus( | |
45 std::unique_ptr<base::SyncSocket> pipe) { | |
46 if (pipe->Peek() >= sizeof(int)) { | |
47 int exit_code; | |
48 pipe->Receive(&exit_code, sizeof(exit_code)); | |
49 LOG(FATAL) << "Renderer process crash detected (code " << exit_code | |
50 << "). Terminating browser."; | |
51 } else { | |
52 // The child process hasn't written anything into the pipe. This implies | |
53 // that it was terminated via SIGKILL by the low memory killer, and thus we | |
54 // need to perform a clean exit. | |
55 exit(0); | |
56 } | |
57 } | |
58 | |
59 void AwBrowserTerminator::OnChildExit( | |
60 int child_process_id, | |
61 base::ProcessHandle pid, | |
62 content::ProcessType process_type, | |
63 base::TerminationStatus termination_status, | |
64 base::android::ApplicationState app_state) { | |
65 std::unique_ptr<base::SyncSocket> pipe; | |
66 | |
67 { | |
68 base::AutoLock auto_lock(child_process_id_to_pipe_lock_); | |
69 const auto& iter = child_process_id_to_pipe_.find(child_process_id); | |
70 if (iter == child_process_id_to_pipe_.end()) { | |
71 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a | |
72 // NOTIFICATION_RENDERER_PROCESS_CLOSED. | |
73 return; | |
74 } | |
75 pipe = std::move(iter->second); | |
76 child_process_id_to_pipe_.erase(iter); | |
77 } | |
78 if (termination_status == base::TERMINATION_STATUS_NORMAL_TERMINATION) | |
79 return; | |
80 DCHECK(pipe->handle() != base::SyncSocket::kInvalidHandle); | |
81 BrowserThread::PostTask( | |
82 BrowserThread::FILE, FROM_HERE, | |
83 base::Bind(&AwBrowserTerminator::ProcessTerminationStatus, | |
Bernhard Bauer
2016/12/08 17:41:25
Nit: Things have slightly changed in base::Bind la
Tobias Sargeant
2016/12/12 11:49:51
Thanks for the tip. I've left this as it is, becau
| |
84 base::Unretained(this), base::Passed(std::move(pipe)))); | |
85 } | |
86 | |
87 } // namespace breakpad | |
OLD | NEW |