OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/android/crash_dump_manager.h" | 5 #include "chrome/browser/android/crash_dump_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/posix/global_descriptors.h" | 12 #include "base/posix/global_descriptors.h" |
13 #include "base/process.h" | 13 #include "base/process.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/common/descriptors_android.h" | 18 #include "chrome/common/descriptors_android.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/child_process_data.h" | 20 #include "content/public/browser/child_process_data.h" |
21 #include "content/public/browser/file_descriptor_info.h" | 21 #include "content/public/browser/file_descriptor_info.h" |
22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
25 | 25 |
26 using content::BrowserThread; | 26 using content::BrowserThread; |
27 | 27 |
| 28 // static |
| 29 CrashDumpManager* CrashDumpManager::instance_ = NULL; |
| 30 |
| 31 // static |
| 32 CrashDumpManager* CrashDumpManager::GetInstance() { |
| 33 return instance_; |
| 34 } |
| 35 |
28 CrashDumpManager::CrashDumpManager() { | 36 CrashDumpManager::CrashDumpManager() { |
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 38 DCHECK(!instance_); |
| 39 |
| 40 instance_ = this; |
| 41 |
30 notification_registrar_.Add(this, | 42 notification_registrar_.Add(this, |
31 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 43 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
32 content::NotificationService::AllSources()); | 44 content::NotificationService::AllSources()); |
33 notification_registrar_.Add(this, | 45 notification_registrar_.Add(this, |
34 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 46 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
35 content::NotificationService::AllSources()); | 47 content::NotificationService::AllSources()); |
36 notification_registrar_.Add(this, | 48 notification_registrar_.Add(this, |
37 content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, | 49 content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, |
38 content::NotificationService::AllSources()); | 50 content::NotificationService::AllSources()); |
39 notification_registrar_.Add(this, | 51 notification_registrar_.Add(this, |
40 content::NOTIFICATION_CHILD_PROCESS_CRASHED, | 52 content::NOTIFICATION_CHILD_PROCESS_CRASHED, |
41 content::NotificationService::AllSources()); | 53 content::NotificationService::AllSources()); |
42 } | 54 } |
43 | 55 |
44 CrashDumpManager::~CrashDumpManager() { | 56 CrashDumpManager::~CrashDumpManager() { |
| 57 instance_ = NULL; |
45 } | 58 } |
46 | 59 |
47 int CrashDumpManager::CreateMinidumpFile(int child_process_id) { | 60 int CrashDumpManager::CreateMinidumpFile(int child_process_id) { |
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)); |
49 FilePath minidump_path; | 62 FilePath minidump_path; |
50 if (!file_util::CreateTemporaryFile(&minidump_path)) | 63 if (!file_util::CreateTemporaryFile(&minidump_path)) |
51 return base::kInvalidPlatformFileValue; | 64 return base::kInvalidPlatformFileValue; |
52 | 65 |
53 base::PlatformFileError error; | 66 base::PlatformFileError error; |
54 // We need read permission as the minidump is generated in several phases | 67 // We need read permission as the minidump is generated in several phases |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // NOTIFICATION_RENDERER_PROCESS_CLOSED. | 163 // NOTIFICATION_RENDERER_PROCESS_CLOSED. |
151 return; | 164 return; |
152 } | 165 } |
153 minidump_path = iter->second; | 166 minidump_path = iter->second; |
154 child_process_id_to_minidump_path_.erase(iter); | 167 child_process_id_to_minidump_path_.erase(iter); |
155 } | 168 } |
156 BrowserThread::PostTask( | 169 BrowserThread::PostTask( |
157 BrowserThread::FILE, FROM_HERE, | 170 BrowserThread::FILE, FROM_HERE, |
158 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, pid)); | 171 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, pid)); |
159 } | 172 } |
OLD | NEW |