OLD | NEW |
---|---|
(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/lazy_instance.h" | |
11 #include "base/logging.h" | |
12 #include "base/stl_util.h" | |
13 #include "base/threading/sequenced_worker_pool.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 breakpad { | |
23 | |
24 CrashDumpObserver::Client::Client() {} | |
25 | |
26 CrashDumpObserver::Client::~Client() {} | |
27 | |
28 namespace { | |
29 base::LazyInstance<CrashDumpObserver> g_instance = LAZY_INSTANCE_INITIALIZER; | |
30 } | |
31 | |
32 // static | |
33 void CrashDumpObserver::Create() { | |
34 GetInstance(); | |
35 } | |
36 | |
37 // static | |
38 CrashDumpObserver* CrashDumpObserver::GetInstance() { | |
39 return g_instance.Pointer(); | |
boliu
2016/10/13 21:07:19
If you have an explicit Create, you probably want
Bernhard Bauer
2016/10/14 10:41:01
And vice-versa, would it make sense to verify that
Tobias Sargeant
2016/12/08 16:41:41
Done.
| |
40 } | |
41 | |
42 CrashDumpObserver::CrashDumpObserver() { | |
43 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
44 notification_registrar_.Add(this, | |
45 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
46 content::NotificationService::AllSources()); | |
47 notification_registrar_.Add(this, | |
48 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
49 content::NotificationService::AllSources()); | |
50 BrowserChildProcessObserver::Add(this); | |
51 } | |
52 | |
53 CrashDumpObserver::~CrashDumpObserver() { | |
54 BrowserChildProcessObserver::Remove(this); | |
55 } | |
56 | |
57 void CrashDumpObserver::OnChildExit(int child_process_id, | |
58 base::ProcessHandle pid, | |
59 content::ProcessType process_type, | |
60 base::TerminationStatus termination_status, | |
61 base::android::ApplicationState app_state) { | |
62 base::AutoLock auto_lock(registered_clients_lock_); | |
63 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | |
boliu
2016/10/13 21:07:19
old implementation uses FILE thread?
probably sho
Tobias Sargeant
2016/12/08 16:41:41
Done.
| |
64 base::SequencedWorkerPool::SequenceToken token = pool->GetSequenceToken(); | |
65 | |
66 for (auto& client : registered_clients_) { | |
67 pool->PostSequencedWorkerTask( | |
68 token, FROM_HERE, | |
69 base::Bind(&Client::OnChildExit, client, child_process_id, pid, | |
Bernhard Bauer
2016/10/14 10:41:01
Actually, why do you need to post this to a backgr
Tobias Sargeant
2016/12/08 16:41:41
Per the discussion offline, the post has been remo
| |
70 process_type, termination_status, app_state)); | |
71 } | |
72 } | |
73 | |
74 void CrashDumpObserver::RegisterClient(scoped_refptr<Client> client) { | |
75 base::AutoLock auto_lock(registered_clients_lock_); | |
76 if (!ContainsValue(registered_clients_, client)) | |
77 registered_clients_.push_back(std::move(client)); | |
78 } | |
79 | |
80 void CrashDumpObserver::UnregisterClient(scoped_refptr<Client> client) { | |
81 base::AutoLock auto_lock(registered_clients_lock_); | |
82 registered_clients_.erase(std::remove(registered_clients_.begin(), | |
83 registered_clients_.end(), client), | |
84 registered_clients_.end()); | |
85 } | |
86 | |
87 void CrashDumpObserver::BrowserChildProcessStarted( | |
88 int child_process_id, | |
89 content::FileDescriptorInfo* mappings) { | |
90 base::AutoLock auto_lock(registered_clients_lock_); | |
91 for (auto& client : registered_clients_) { | |
92 client->OnChildStart(child_process_id, mappings); | |
boliu
2016/10/13 21:07:19
if a client decides to remove itself inside OnChil
Tobias Sargeant
2016/12/08 16:41:41
Clients can't be removed now, but registering new
| |
93 } | |
94 } | |
95 | |
96 void CrashDumpObserver::BrowserChildProcessHostDisconnected( | |
97 const content::ChildProcessData& data) { | |
Bernhard Bauer
2016/10/14 10:41:01
Can you add some DCHECKs for the threads the vario
Tobias Sargeant
2016/12/08 16:41:41
Done.
| |
98 OnChildExit(data.id, data.handle, | |
99 static_cast<content::ProcessType>(data.process_type), | |
100 base::TERMINATION_STATUS_MAX_ENUM, | |
101 base::android::APPLICATION_STATE_UNKNOWN); | |
102 } | |
103 | |
104 void CrashDumpObserver::BrowserChildProcessCrashed( | |
105 const content::ChildProcessData& data, | |
106 int exit_code) { | |
107 OnChildExit(data.id, data.handle, | |
108 static_cast<content::ProcessType>(data.process_type), | |
109 base::TERMINATION_STATUS_ABNORMAL_TERMINATION, | |
110 base::android::APPLICATION_STATE_UNKNOWN); | |
111 } | |
112 | |
113 void CrashDumpObserver::Observe(int type, | |
114 const content::NotificationSource& source, | |
115 const content::NotificationDetails& details) { | |
116 content::RenderProcessHost* rph = | |
117 content::Source<content::RenderProcessHost>(source).ptr(); | |
118 base::TerminationStatus term_status = base::TERMINATION_STATUS_MAX_ENUM; | |
119 base::android::ApplicationState app_state = | |
120 base::android::APPLICATION_STATE_UNKNOWN; | |
121 switch (type) { | |
122 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { | |
123 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer | |
124 // process is cleanly shutdown. However, we still need to close the | |
125 // minidump_fd we kept open. | |
126 term_status = base::TERMINATION_STATUS_NORMAL_TERMINATION; | |
127 break; | |
128 } | |
129 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | |
130 // We do not care about android fast shutdowns as it is a known case where | |
131 // the renderer is intentionally killed when we are done with it. | |
132 if (rph->FastShutdownStarted()) { | |
133 break; | |
134 } | |
135 content::RenderProcessHost::RendererClosedDetails* process_details = | |
136 content::Details<content::RenderProcessHost::RendererClosedDetails>( | |
137 details) | |
138 .ptr(); | |
139 term_status = process_details->status; | |
140 app_state = base::android::ApplicationStatusListener::GetState(); | |
141 break; | |
142 } | |
143 default: | |
144 NOTREACHED(); | |
145 return; | |
146 } | |
147 | |
148 OnChildExit(rph->GetID(), rph->GetHandle(), content::PROCESS_TYPE_RENDERER, | |
149 term_status, app_state); | |
150 } | |
151 | |
152 } // namespace breakpad | |
OLD | NEW |