Chromium Code Reviews| 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/logging.h" | |
| 11 #include "base/stl_util.h" | |
| 12 #include "base/threading/sequenced_worker_pool.h" | |
| 13 #include "content/public/browser/browser_thread.h" | |
| 14 #include "content/public/browser/child_process_data.h" | |
| 15 #include "content/public/browser/notification_service.h" | |
| 16 #include "content/public/browser/notification_types.h" | |
| 17 #include "content/public/browser/render_process_host.h" | |
| 18 | |
| 19 using content::BrowserThread; | |
| 20 | |
| 21 namespace breakpad { | |
| 22 | |
| 23 // static | |
| 24 CrashDumpObserver* CrashDumpObserver::GetInstance() { | |
| 25 return base::Singleton<CrashDumpObserver>::get(); | |
| 26 } | |
| 27 | |
| 28 CrashDumpObserver::CrashDumpObserver() { | |
| 29 notification_registrar_.Add(this, | |
| 30 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
| 31 content::NotificationService::AllSources()); | |
| 32 notification_registrar_.Add(this, | |
| 33 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
| 34 content::NotificationService::AllSources()); | |
| 35 } | |
| 36 | |
| 37 CrashDumpObserver::~CrashDumpObserver() {} | |
| 38 | |
| 39 void CrashDumpObserver::OnChildExitOnBlockingPool( | |
| 40 Client* client, | |
| 41 int child_process_id, | |
| 42 base::ProcessHandle pid, | |
| 43 content::ProcessType process_type, | |
| 44 base::TerminationStatus termination_status, | |
| 45 base::android::ApplicationState app_state) { | |
| 46 base::AutoLock auto_lock(registered_clients_lock_); | |
| 47 // Only call Client::OnChildExit if we haven't been removed in the | |
| 48 // interim. | |
| 49 if (ContainsValue(registered_clients_, client)) { | |
| 50 LOG(WARNING) << "tobiasjs: " << __PRETTY_FUNCTION__ << " not deleted " | |
|
Bernhard Bauer
2016/08/05 15:43:38
Ahem :)
| |
| 51 << client; | |
| 52 client->OnChildExit(child_process_id, pid, process_type, termination_status, | |
| 53 app_state); | |
| 54 } | |
| 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(); | |
| 64 base::SequencedWorkerPool::SequenceToken token = pool->GetSequenceToken(); | |
| 65 | |
| 66 for (auto& client : registered_clients_) { | |
| 67 LOG(WARNING) << "tobiasjs: " << __PRETTY_FUNCTION__ << " " << client; | |
| 68 pool->PostSequencedWorkerTask( | |
| 69 token, FROM_HERE, | |
| 70 base::Bind(&CrashDumpObserver::OnChildExitOnBlockingPool, | |
| 71 base::Unretained(this), client, child_process_id, pid, | |
| 72 process_type, termination_status, app_state)); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 void CrashDumpObserver::RegisterClient(Client* client) { | |
| 77 base::AutoLock auto_lock(registered_clients_lock_); | |
| 78 if (std::find(std::begin(registered_clients_), std::end(registered_clients_), | |
| 79 client) != std::end(registered_clients_)) { | |
| 80 return; | |
| 81 } | |
| 82 registered_clients_.push_back(client); | |
| 83 } | |
| 84 | |
| 85 void CrashDumpObserver::UnregisterClient(Client* client) { | |
| 86 base::AutoLock auto_lock(registered_clients_lock_); | |
| 87 registered_clients_.remove(client); | |
| 88 } | |
| 89 | |
| 90 void CrashDumpObserver::BrowserChildProcessStarted( | |
| 91 int child_process_id, | |
| 92 content::FileDescriptorInfo* mappings) { | |
| 93 base::AutoLock auto_lock(registered_clients_lock_); | |
| 94 for (auto& client : registered_clients_) { | |
| 95 client->OnChildStart(child_process_id, mappings); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 void CrashDumpObserver::BrowserChildProcessHostDisconnected( | |
| 100 const content::ChildProcessData& data) { | |
| 101 OnChildExit(data.id, data.handle, | |
| 102 static_cast<content::ProcessType>(data.process_type), | |
| 103 base::TERMINATION_STATUS_MAX_ENUM, | |
| 104 base::android::APPLICATION_STATE_UNKNOWN); | |
| 105 } | |
| 106 | |
| 107 void CrashDumpObserver::BrowserChildProcessCrashed( | |
| 108 const content::ChildProcessData& data, | |
| 109 int exit_code) { | |
| 110 OnChildExit(data.id, data.handle, | |
| 111 static_cast<content::ProcessType>(data.process_type), | |
| 112 base::TERMINATION_STATUS_ABNORMAL_TERMINATION, | |
| 113 base::android::APPLICATION_STATE_UNKNOWN); | |
| 114 } | |
| 115 | |
| 116 void CrashDumpObserver::Observe(int type, | |
| 117 const content::NotificationSource& source, | |
| 118 const content::NotificationDetails& details) { | |
| 119 content::RenderProcessHost* rph = | |
| 120 content::Source<content::RenderProcessHost>(source).ptr(); | |
| 121 base::TerminationStatus term_status = base::TERMINATION_STATUS_MAX_ENUM; | |
| 122 base::android::ApplicationState app_state = | |
| 123 base::android::APPLICATION_STATE_UNKNOWN; | |
| 124 switch (type) { | |
| 125 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { | |
| 126 // NOTIFICATION_RENDERER_PROCESS_TERMINATED is sent when the renderer | |
| 127 // process is cleanly shutdown. However, we still need to close the | |
| 128 // minidump_fd we kept open. | |
| 129 term_status = base::TERMINATION_STATUS_NORMAL_TERMINATION; | |
| 130 break; | |
| 131 } | |
| 132 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | |
| 133 // We do not care about android fast shutdowns as it is a known case where | |
| 134 // the renderer is intentionally killed when we are done with it. | |
| 135 if (rph->FastShutdownStarted()) { | |
| 136 break; | |
| 137 } | |
| 138 content::RenderProcessHost::RendererClosedDetails* process_details = | |
| 139 content::Details<content::RenderProcessHost::RendererClosedDetails>( | |
| 140 details) | |
| 141 .ptr(); | |
| 142 term_status = process_details->status; | |
| 143 app_state = base::android::ApplicationStatusListener::GetState(); | |
| 144 break; | |
| 145 } | |
| 146 default: | |
| 147 NOTREACHED(); | |
| 148 return; | |
| 149 } | |
| 150 | |
| 151 OnChildExit(rph->GetID(), rph->GetHandle(), content::PROCESS_TYPE_RENDERER, | |
| 152 term_status, app_state); | |
| 153 } | |
| 154 | |
| 155 } // namespace breakpad | |
| OLD | NEW |