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 #ifndef CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ |
6 #define CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ | 6 #define CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
12 #include "base/process.h" | 12 #include "base/process.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "content/public/browser/browser_child_process_observer.h" |
14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 class RenderProcessHost; | 19 class RenderProcessHost; |
19 } | 20 } |
20 | 21 |
21 // This class manages the crash minidumps. | 22 // This class manages the crash minidumps. |
22 // On Android, because of process isolation, each renderer process runs with a | 23 // On Android, because of process isolation, each renderer process runs with a |
23 // different UID. As a result, we cannot generate the minidumps in the browser | 24 // different UID. As a result, we cannot generate the minidumps in the browser |
24 // (as the browser process does not have access to some system files for the | 25 // (as the browser process does not have access to some system files for the |
25 // crashed process). So the minidump is generated in the renderer process. | 26 // crashed process). So the minidump is generated in the renderer process. |
26 // Since the isolated process cannot open files, we provide it on creation with | 27 // Since the isolated process cannot open files, we provide it on creation with |
27 // a file descriptor where to write the minidump in the event of a crash. | 28 // a file descriptor where to write the minidump in the event of a crash. |
28 // This class creates these file descriptors and associates them with render | 29 // This class creates these file descriptors and associates them with render |
29 // processes and take the appropriate action when the render process terminates. | 30 // processes and take the appropriate action when the render process terminates. |
30 class CrashDumpManager : public content::NotificationObserver { | 31 class CrashDumpManager : public content::BrowserChildProcessObserver, |
| 32 public content::NotificationObserver { |
31 public: | 33 public: |
32 // This object is a singleton created and owned by the | 34 // This object is a singleton created and owned by the |
33 // ChromeBrowserMainPartsAndroid. | 35 // ChromeBrowserMainPartsAndroid. |
34 static CrashDumpManager* GetInstance(); | 36 static CrashDumpManager* GetInstance(); |
35 | 37 |
36 virtual ~CrashDumpManager(); | 38 virtual ~CrashDumpManager(); |
37 | 39 |
38 // Returns a file descriptor that should be used to generate a minidump for | 40 // Returns a file descriptor that should be used to generate a minidump for |
39 // the process |child_process_id|. | 41 // the process |child_process_id|. |
40 int CreateMinidumpFile(int child_process_id); | 42 int CreateMinidumpFile(int child_process_id); |
41 | 43 |
42 private: | 44 private: |
43 friend class ChromeBrowserMainPartsAndroid; | 45 friend class ChromeBrowserMainPartsAndroid; |
44 | 46 |
45 // Should be created on the UI thread. | 47 // Should be created on the UI thread. |
46 CrashDumpManager(); | 48 CrashDumpManager(); |
47 | 49 |
48 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; | 50 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; |
49 | 51 |
50 static void ProcessMinidump(const base::FilePath& minidump_path, | 52 static void ProcessMinidump(const base::FilePath& minidump_path, |
51 base::ProcessHandle pid); | 53 base::ProcessHandle pid); |
52 | 54 |
| 55 // content::BrowserChildProcessObserver implementation: |
| 56 virtual void BrowserChildProcessHostDisconnected( |
| 57 const content::ChildProcessData& data) OVERRIDE; |
| 58 virtual void BrowserChildProcessCrashed( |
| 59 const content::ChildProcessData& data) OVERRIDE; |
| 60 |
53 // NotificationObserver implementation: | 61 // NotificationObserver implementation: |
54 virtual void Observe(int type, | 62 virtual void Observe(int type, |
55 const content::NotificationSource& source, | 63 const content::NotificationSource& source, |
56 const content::NotificationDetails& details) OVERRIDE; | 64 const content::NotificationDetails& details) OVERRIDE; |
57 | 65 |
| 66 // Called on child process exit (including crash). |
| 67 void OnChildExit(int child_process_id, base::ProcessHandle pid); |
| 68 |
58 content::NotificationRegistrar notification_registrar_; | 69 content::NotificationRegistrar notification_registrar_; |
59 | 70 |
60 // This map should only be accessed with its lock aquired as it is accessed | 71 // This map should only be accessed with its lock aquired as it is accessed |
61 // from the PROCESS_LAUNCHER and UI threads. | 72 // from the PROCESS_LAUNCHER and UI threads. |
62 base::Lock child_process_id_to_minidump_path_lock_; | 73 base::Lock child_process_id_to_minidump_path_lock_; |
63 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_; | 74 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_; |
64 | 75 |
65 static CrashDumpManager* instance_; | 76 static CrashDumpManager* instance_; |
66 | 77 |
67 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); | 78 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); |
68 }; | 79 }; |
69 | 80 |
70 #endif // CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ | 81 #endif // CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ |
OLD | NEW |