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 COMPONENTS_BREAKPAD_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ |
6 #define CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ | 6 #define COMPONENTS_BREAKPAD_BROWSER_CRASH_DUMP_MANAGER_ANDROID_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/process.h" | 12 #include "base/process/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/browser_child_process_observer.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 class RenderProcessHost; | 19 class RenderProcessHost; |
20 } | 20 } |
21 | 21 |
| 22 namespace breakpad { |
| 23 |
22 // This class manages the crash minidumps. | 24 // This class manages the crash minidumps. |
23 // On Android, because of process isolation, each renderer process runs with a | 25 // On Android, because of process isolation, each renderer process runs with a |
24 // different UID. As a result, we cannot generate the minidumps in the browser | 26 // different UID. As a result, we cannot generate the minidumps in the browser |
25 // (as the browser process does not have access to some system files for the | 27 // (as the browser process does not have access to some system files for the |
26 // crashed process). So the minidump is generated in the renderer process. | 28 // crashed process). So the minidump is generated in the renderer process. |
27 // Since the isolated process cannot open files, we provide it on creation with | 29 // Since the isolated process cannot open files, we provide it on creation with |
28 // a file descriptor where to write the minidump in the event of a crash. | 30 // a file descriptor where to write the minidump in the event of a crash. |
29 // This class creates these file descriptors and associates them with render | 31 // This class creates these file descriptors and associates them with render |
30 // processes and take the appropriate action when the render process terminates. | 32 // processes and take the appropriate action when the render process terminates. |
31 class CrashDumpManager : public content::BrowserChildProcessObserver, | 33 class CrashDumpManager : public content::BrowserChildProcessObserver, |
32 public content::NotificationObserver { | 34 public content::NotificationObserver { |
33 public: | 35 public: |
34 // This object is a singleton created and owned by the | 36 // The embedder should create a single instance of the CrashDumpManager. |
35 // ChromeBrowserMainPartsAndroid. | |
36 static CrashDumpManager* GetInstance(); | 37 static CrashDumpManager* GetInstance(); |
37 | 38 |
| 39 // Should be created on the UI thread. |
| 40 explicit CrashDumpManager(const base::FilePath& crash_dump_dir); |
| 41 |
38 virtual ~CrashDumpManager(); | 42 virtual ~CrashDumpManager(); |
39 | 43 |
40 // Returns a file descriptor that should be used to generate a minidump for | 44 // Returns a file descriptor that should be used to generate a minidump for |
41 // the process |child_process_id|. | 45 // the process |child_process_id|. |
42 int CreateMinidumpFile(int child_process_id); | 46 int CreateMinidumpFile(int child_process_id); |
43 | 47 |
44 private: | 48 private: |
45 friend class ChromeBrowserMainPartsAndroid; | |
46 | |
47 // Should be created on the UI thread. | |
48 explicit CrashDumpManager(const base::FilePath& crash_dump_dir); | |
49 | |
50 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; | 49 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; |
51 | 50 |
52 static void ProcessMinidump(const base::FilePath& minidump_path, | 51 static void ProcessMinidump(const base::FilePath& minidump_path, |
53 base::ProcessHandle pid); | 52 base::ProcessHandle pid); |
54 | 53 |
55 // content::BrowserChildProcessObserver implementation: | 54 // content::BrowserChildProcessObserver implementation: |
56 virtual void BrowserChildProcessHostDisconnected( | 55 virtual void BrowserChildProcessHostDisconnected( |
57 const content::ChildProcessData& data) OVERRIDE; | 56 const content::ChildProcessData& data) OVERRIDE; |
58 virtual void BrowserChildProcessCrashed( | 57 virtual void BrowserChildProcessCrashed( |
59 const content::ChildProcessData& data) OVERRIDE; | 58 const content::ChildProcessData& data) OVERRIDE; |
(...skipping 13 matching lines...) Expand all Loading... |
73 base::Lock child_process_id_to_minidump_path_lock_; | 72 base::Lock child_process_id_to_minidump_path_lock_; |
74 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_; | 73 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_; |
75 | 74 |
76 base::FilePath crash_dump_dir_; | 75 base::FilePath crash_dump_dir_; |
77 | 76 |
78 static CrashDumpManager* instance_; | 77 static CrashDumpManager* instance_; |
79 | 78 |
80 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); | 79 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); |
81 }; | 80 }; |
82 | 81 |
83 #endif // CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ | 82 } // namespace breakpad |
| 83 |
| 84 #endif // COMPONENTS_BREAKPAD_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ |
OLD | NEW |