OLD | NEW |
---|---|
1 | |
Robert Sesek
2016/08/04 16:59:01
nit: spurious blank line
Tobias Sargeant
2016/08/05 14:59:21
Done.
| |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 2 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 4 // found in the LICENSE file. |
4 | 5 |
5 #ifndef COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ | 6 #ifndef COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ |
6 #define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ | 7 #define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ |
7 | 8 |
8 #include <map> | 9 #include <map> |
9 | 10 |
10 #include "base/android/application_status_listener.h" | |
11 #include "base/files/file.h" | |
12 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
13 #include "base/macros.h" | |
14 #include "base/process/kill.h" | |
15 #include "base/process/process.h" | |
16 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
17 #include "content/public/browser/browser_child_process_observer.h" | 13 #include "components/crash/content/browser/crash_dump_observer_android.h" |
18 #include "content/public/browser/notification_observer.h" | |
19 #include "content/public/browser/notification_registrar.h" | |
20 #include "content/public/common/process_type.h" | |
21 | |
22 namespace content { | |
23 class RenderProcessHost; | |
24 } | |
25 | 14 |
26 namespace breakpad { | 15 namespace breakpad { |
27 | 16 |
28 // This class manages the crash minidumps. | 17 // This class manages the crash minidumps. |
29 // On Android, because of process isolation, each renderer process runs with a | 18 // On Android, because of process isolation, each renderer process runs with a |
30 // different UID. As a result, we cannot generate the minidumps in the browser | 19 // different UID. As a result, we cannot generate the minidumps in the browser |
31 // (as the browser process does not have access to some system files for the | 20 // (as the browser process does not have access to some system files for the |
32 // crashed process). So the minidump is generated in the renderer process. | 21 // crashed process). So the minidump is generated in the renderer process. |
33 // Since the isolated process cannot open files, we provide it on creation with | 22 // Since the isolated process cannot open files, we provide it on creation with |
34 // a file descriptor where to write the minidump in the event of a crash. | 23 // a file descriptor where to write the minidump in the event of a crash. |
35 // This class creates these file descriptors and associates them with render | 24 // This class creates these file descriptors and associates them with render |
36 // processes and take the appropriate action when the render process terminates. | 25 // processes and take the appropriate action when the render process terminates. |
37 class CrashDumpManager : public content::BrowserChildProcessObserver, | 26 class CrashDumpManager : public breakpad::CrashDumpObserver::Client { |
38 public content::NotificationObserver { | |
39 public: | 27 public: |
40 // The embedder should create a single instance of the CrashDumpManager. | |
41 static CrashDumpManager* GetInstance(); | |
42 | |
43 // Should be created on the UI thread. | 28 // Should be created on the UI thread. |
44 explicit CrashDumpManager(const base::FilePath& crash_dump_dir); | 29 explicit CrashDumpManager(const base::FilePath& crash_dump_dir, |
45 | 30 int mapping_index); |
Robert Sesek
2016/08/04 16:59:01
What is |mapping_index| ? Should be documented.
Tobias Sargeant
2016/08/05 14:59:21
Done (combination of a better name, and a comment
| |
46 ~CrashDumpManager() override; | 31 ~CrashDumpManager() override; |
47 | 32 |
Robert Sesek
2016/08/04 16:59:01
// breakpad::CrashDumpObserver::Client implementat
Tobias Sargeant
2016/08/05 14:59:21
Done.
| |
48 // Returns a file that should be used to generate a minidump for the process | 33 void OnChildStart(int child_process_id, |
49 // |child_process_id|. | 34 content::FileDescriptorInfo* mappings) override; |
50 base::File CreateMinidumpFile(int child_process_id); | 35 void OnChildExit(int child_process_id, |
36 base::ProcessHandle pid, | |
37 content::ProcessType process_type, | |
38 base::TerminationStatus termination_status, | |
39 base::android::ApplicationState app_state) override; | |
51 | 40 |
52 private: | 41 private: |
53 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; | 42 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; |
54 | 43 |
55 // This enum is used to back a UMA histogram, and must be treated as | 44 // This enum is used to back a UMA histogram, and must be treated as |
56 // append-only. | 45 // append-only. |
57 enum ExitStatus { | 46 enum ExitStatus { |
58 EMPTY_MINIDUMP_WHILE_RUNNING, | 47 EMPTY_MINIDUMP_WHILE_RUNNING, |
59 EMPTY_MINIDUMP_WHILE_PAUSED, | 48 EMPTY_MINIDUMP_WHILE_PAUSED, |
60 EMPTY_MINIDUMP_WHILE_BACKGROUND, | 49 EMPTY_MINIDUMP_WHILE_BACKGROUND, |
61 VALID_MINIDUMP_WHILE_RUNNING, | 50 VALID_MINIDUMP_WHILE_RUNNING, |
62 VALID_MINIDUMP_WHILE_PAUSED, | 51 VALID_MINIDUMP_WHILE_PAUSED, |
63 VALID_MINIDUMP_WHILE_BACKGROUND, | 52 VALID_MINIDUMP_WHILE_BACKGROUND, |
64 MINIDUMP_STATUS_COUNT | 53 MINIDUMP_STATUS_COUNT |
65 }; | 54 }; |
66 | 55 |
67 static void ProcessMinidump(const base::FilePath& minidump_path, | 56 void ProcessMinidump(const base::FilePath& minidump_path, |
68 base::ProcessHandle pid, | 57 base::ProcessHandle pid, |
69 content::ProcessType process_type, | 58 content::ProcessType process_type, |
70 base::TerminationStatus termination_status, | 59 base::TerminationStatus termination_status, |
71 base::android::ApplicationState app_state); | 60 base::android::ApplicationState app_state); |
72 | |
73 // content::BrowserChildProcessObserver implementation: | |
74 void BrowserChildProcessHostDisconnected( | |
75 const content::ChildProcessData& data) override; | |
76 void BrowserChildProcessCrashed( | |
77 const content::ChildProcessData& data, | |
78 int exit_code) override; | |
79 | |
80 // NotificationObserver implementation: | |
81 void Observe(int type, | |
82 const content::NotificationSource& source, | |
83 const content::NotificationDetails& details) override; | |
84 | |
85 // Called on child process exit (including crash). | |
86 void OnChildExit(int child_process_id, | |
87 base::ProcessHandle pid, | |
88 content::ProcessType process_type, | |
89 base::TerminationStatus termination_status, | |
90 base::android::ApplicationState app_state); | |
91 | |
92 content::NotificationRegistrar notification_registrar_; | |
93 | 61 |
94 // This map should only be accessed with its lock aquired as it is accessed | 62 // This map should only be accessed with its lock aquired as it is accessed |
95 // from the PROCESS_LAUNCHER and UI threads. | 63 // from the PROCESS_LAUNCHER and UI threads. |
96 base::Lock child_process_id_to_minidump_path_lock_; | 64 base::Lock child_process_id_to_minidump_path_lock_; |
97 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_; | 65 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_; |
98 | 66 |
99 base::FilePath crash_dump_dir_; | 67 base::FilePath crash_dump_dir_; |
100 | 68 int mapping_index_; |
101 static CrashDumpManager* instance_; | |
102 | 69 |
103 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); | 70 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); |
104 }; | 71 }; |
105 | 72 |
106 } // namespace breakpad | 73 } // namespace breakpad |
107 | 74 |
108 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ | 75 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ |
OLD | NEW |