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

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: clang compile errors 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(std::unique_ptr<Client> client) {
52 base::AutoLock auto_lock(registered_clients_lock_);
53 registered_clients_.push_back(std::move(client));
54 }
55
56 void CrashDumpObserver::BrowserChildProcessStarted(
57 int child_process_id,
58 content::FileDescriptorInfo* mappings) {
59 base::AutoLock auto_lock(registered_clients_lock_);
60 for (auto& client : registered_clients_) {
61 client->OnChildStart(child_process_id, mappings);
62 }
63 }
64
65 void CrashDumpObserver::BrowserChildProcessHostDisconnected(
66 const content::ChildProcessData& data) {
67 BrowserThread::PostTask(
68 BrowserThread::FILE, FROM_HERE,
69 base::Bind(&CrashDumpObserver::OnChildExit, weak_factory_.GetWeakPtr(),
70 data.id, data.handle,
71 static_cast<content::ProcessType>(data.process_type),
72 base::TERMINATION_STATUS_MAX_ENUM,
73 base::android::APPLICATION_STATE_UNKNOWN));
74 }
75
76 void CrashDumpObserver::BrowserChildProcessCrashed(
77 const content::ChildProcessData& data,
78 int exit_code) {
79 BrowserThread::PostTask(
80 BrowserThread::FILE, FROM_HERE,
81 base::Bind(&CrashDumpObserver::OnChildExit, weak_factory_.GetWeakPtr(),
82 data.id, data.handle,
83 static_cast<content::ProcessType>(data.process_type),
84 base::TERMINATION_STATUS_ABNORMAL_TERMINATION,
85 base::android::APPLICATION_STATE_UNKNOWN));
86 }
87
88 void CrashDumpObserver::Observe(int type,
89 const content::NotificationSource& source,
90 const content::NotificationDetails& details) {
91 content::RenderProcessHost* rph =
92 content::Source<content::RenderProcessHost>(source).ptr();
93 base::TerminationStatus term_status = base::TERMINATION_STATUS_MAX_ENUM;
94 base::android::ApplicationState app_state =
95 base::android::APPLICATION_STATE_UNKNOWN;
96 switch (type) {
97 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
98 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer
99 // process is cleanly shutdown. However, we still need to close the
100 // minidump_fd we kept open.
101 term_status = base::TERMINATION_STATUS_NORMAL_TERMINATION;
102 break;
103 }
104 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
105 // We do not care about android fast shutdowns as it is a known case where
106 // the renderer is intentionally killed when we are done with it.
107 if (rph->FastShutdownStarted()) {
108 break;
109 }
110 content::RenderProcessHost::RendererClosedDetails* process_details =
111 content::Details<content::RenderProcessHost::RendererClosedDetails>(
112 details)
113 .ptr();
114 term_status = process_details->status;
115 app_state = base::android::ApplicationStatusListener::GetState();
116 break;
117 }
118 default:
119 NOTREACHED();
120 return;
121 }
122
123 BrowserThread::PostTask(
124 BrowserThread::FILE, FROM_HERE,
125 base::Bind(&CrashDumpObserver::OnChildExit, weak_factory_.GetWeakPtr(),
126 rph->GetID(), rph->GetHandle(), content::PROCESS_TYPE_RENDERER,
127 term_status, app_state));
128 }
129
130 } // namespace breakpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698