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

Side by Side Diff: components/crash/content/browser/crash_dump_observer_android.cc

Issue 2200693002: Refactor CrashDump*Manager to use a shared CrashDumpObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cast compile error Created 4 years, 4 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 2015 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 "components/crash/content/browser/crash_dump_observer_android.h"
6
7 #include <unistd.h>
8
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/child_process_data.h"
13 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/notification_types.h"
15 #include "content/public/browser/render_process_host.h"
16
17 using content::BrowserThread;
18
19 namespace breakpad {
20
21 // static
22 CrashDumpObserver* CrashDumpObserver::GetInstance() {
23 return base::Singleton<CrashDumpObserver>::get();
24 }
25
26 CrashDumpObserver::CrashDumpObserver() : weak_factory_(this) {
27 notification_registrar_.Add(this,
28 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
29 content::NotificationService::AllSources());
30 notification_registrar_.Add(this,
31 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
32 content::NotificationService::AllSources());
33 }
34
35 CrashDumpObserver::~CrashDumpObserver() {}
36
37 void CrashDumpObserver::OnChildExit(int child_process_id,
38 base::ProcessHandle pid,
39 content::ProcessType process_type,
40 base::TerminationStatus termination_status,
41 base::android::ApplicationState app_state) {
42 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
43
44 base::AutoLock auto_lock(registered_clients_lock_);
45 for (auto& client : registered_clients_) {
46 client->OnChildExit(child_process_id, pid, process_type, termination_status,
47 app_state);
48 }
49 }
50
51 void CrashDumpObserver::RegisterClient(Client* client) {
52 base::AutoLock auto_lock(registered_clients_lock_);
53 if (std::find(std::begin(registered_clients_), std::end(registered_clients_),
54 client) != std::end(registered_clients_))
Robert Sesek 2016/08/04 16:59:01 nit: needs braces since the condition is multi-lin
Tobias Sargeant 2016/08/05 14:59:21 Done.
55 return;
56 registered_clients_.push_back(client);
57 }
58
59 void CrashDumpObserver::UnregisterClient(Client* client) {
60 base::AutoLock auto_lock(registered_clients_lock_);
61 registered_clients_.remove(client);
62 }
63
64 void CrashDumpObserver::BrowserChildProcessStarted(
65 int child_process_id,
66 content::FileDescriptorInfo* mappings) {
67 base::AutoLock auto_lock(registered_clients_lock_);
68 for (auto& client : registered_clients_) {
69 client->OnChildStart(child_process_id, mappings);
70 }
71 }
72
73 void CrashDumpObserver::BrowserChildProcessHostDisconnected(
74 const content::ChildProcessData& data) {
75 BrowserThread::PostTask(
76 BrowserThread::FILE, FROM_HERE,
77 base::Bind(&CrashDumpObserver::OnChildExit, weak_factory_.GetWeakPtr(),
78 data.id, data.handle,
79 static_cast<content::ProcessType>(data.process_type),
80 base::TERMINATION_STATUS_MAX_ENUM,
81 base::android::APPLICATION_STATE_UNKNOWN));
82 }
83
84 void CrashDumpObserver::BrowserChildProcessCrashed(
85 const content::ChildProcessData& data,
86 int exit_code) {
87 BrowserThread::PostTask(
88 BrowserThread::FILE, FROM_HERE,
89 base::Bind(&CrashDumpObserver::OnChildExit, weak_factory_.GetWeakPtr(),
90 data.id, data.handle,
91 static_cast<content::ProcessType>(data.process_type),
92 base::TERMINATION_STATUS_ABNORMAL_TERMINATION,
93 base::android::APPLICATION_STATE_UNKNOWN));
94 }
95
96 void CrashDumpObserver::Observe(int type,
97 const content::NotificationSource& source,
98 const content::NotificationDetails& details) {
99 content::RenderProcessHost* rph =
100 content::Source<content::RenderProcessHost>(source).ptr();
101 base::TerminationStatus term_status = base::TERMINATION_STATUS_MAX_ENUM;
102 base::android::ApplicationState app_state =
103 base::android::APPLICATION_STATE_UNKNOWN;
104 switch (type) {
105 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
106 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer
107 // process is cleanly shutdown. However, we still need to close the
108 // minidump_fd we kept open.
109 term_status = base::TERMINATION_STATUS_NORMAL_TERMINATION;
110 break;
111 }
112 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
113 // We do not care about android fast shutdowns as it is a known case where
114 // the renderer is intentionally killed when we are done with it.
115 if (rph->FastShutdownStarted()) {
116 break;
117 }
118 content::RenderProcessHost::RendererClosedDetails* process_details =
119 content::Details<content::RenderProcessHost::RendererClosedDetails>(
120 details)
121 .ptr();
122 term_status = process_details->status;
123 app_state = base::android::ApplicationStatusListener::GetState();
124 break;
125 }
126 default:
127 NOTREACHED();
128 return;
129 }
130
131 BrowserThread::PostTask(
132 BrowserThread::FILE, FROM_HERE,
133 base::Bind(&CrashDumpObserver::OnChildExit, weak_factory_.GetWeakPtr(),
Bernhard Bauer 2016/08/04 16:01:32 Actually, do you even need the weak pointer? This
Tobias Sargeant 2016/08/05 14:59:22 I think you're right. And being able to simplify t
134 rph->GetID(), rph->GetHandle(), content::PROCESS_TYPE_RENDERER,
135 term_status, app_state));
136 }
137
138 } // namespace breakpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698