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

Side by Side Diff: android_webview/browser/aw_browser_terminator.cc

Issue 2393853002: Refactor CrashDump*Manager to use a shared CrashDumpObserver singleton. (Closed)
Patch Set: fix initialization in ShellBrowserMainParts 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
OLDNEW
(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 namespace android_webview {
21
22 AwBrowserTerminator::AwBrowserTerminator() {}
23
24 AwBrowserTerminator::~AwBrowserTerminator() {}
25
26 void AwBrowserTerminator::OnChildStart(int child_process_id,
27 content::FileDescriptorInfo* mappings) {
28 DCHECK_CURRENTLY_ON(content::BrowserThread::PROCESS_LAUNCHER);
29
30 base::AutoLock auto_lock(child_process_id_to_pipe_lock_);
31 DCHECK(!ContainsKey(child_process_id_to_pipe_, child_process_id));
32
33 std::unique_ptr<base::SyncSocket> local_pipe(new base::SyncSocket());
Bernhard Bauer 2016/10/14 10:41:01 auto local_pipe = base::MakeUnique<base::SyncSocke
Tobias Sargeant 2016/12/08 16:41:41 This is moved code, but ok.
34 std::unique_ptr<base::SyncSocket> child_pipe(new base::SyncSocket());
35 if (base::SyncSocket::CreatePair(local_pipe.get(), child_pipe.get())) {
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 std::unique_ptr<base::SyncSocket> pipe;
49
50 {
51 base::AutoLock auto_lock(child_process_id_to_pipe_lock_);
52 const auto& iter = child_process_id_to_pipe_.find(child_process_id);
53 if (iter == child_process_id_to_pipe_.end()) {
54 // We might get a NOTIFICATION_RENDERER_PROCESS_TERMINATED and a
boliu 2016/10/13 21:07:18 hmm, you probably want to document on the observer
Tobias Sargeant 2016/12/08 16:41:41 Done.
55 // NOTIFICATION_RENDERER_PROCESS_CLOSED.
56 return;
57 }
58 pipe = std::move(iter->second);
59 child_process_id_to_pipe_.erase(iter);
60 }
61 DCHECK(pipe->handle() != base::SyncSocket::kInvalidHandle);
62
63 if (termination_status == base::TERMINATION_STATUS_NORMAL_TERMINATION)
64 return;
65 if (pipe->Peek() >= sizeof(int)) {
66 int exit_code;
67 pipe->Receive(&exit_code, sizeof(exit_code));
68 LOG(FATAL) << "Renderer process crash detected (code " << exit_code
69 << "). Terminating browser.";
70 } else {
71 // The child process hasn't written anything into the pipe. This implies
72 // that it was terminated via SIGKILL by the low memory killer, and thus we
73 // need to perform a clean exit.
74 exit(0);
75 }
76 }
77
78 } // namespace breakpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698