OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ | 5 #ifndef COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ |
6 #define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ | 6 #define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/android/application_status_listener.h" | |
11 #include "base/files/file.h" | |
12 #include "base/files/file_path.h" | 10 #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" | 11 #include "base/synchronization/lock.h" |
17 #include "content/public/browser/browser_child_process_observer.h" | 12 #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 | 13 |
26 namespace breakpad { | 14 namespace breakpad { |
27 | 15 |
28 // This class manages the crash minidumps. | 16 // This class manages the crash minidumps. |
29 // On Android, because of process isolation, each renderer process runs with a | 17 // 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 | 18 // 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 | 19 // (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. | 20 // 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 | 21 // 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. | 22 // a file descriptor into which to write the minidump in the event of a crash. |
35 // This class creates these file descriptors and associates them with render | 23 // This class creates these file descriptors and associates them with render |
36 // processes and take the appropriate action when the render process terminates. | 24 // processes and takes the appropriate action when the render process |
37 class CrashDumpManager : public content::BrowserChildProcessObserver, | 25 // terminates. |
38 public content::NotificationObserver { | 26 class CrashDumpManager : public breakpad::CrashDumpObserver::Client { |
39 public: | 27 public: |
40 // The embedder should create a single instance of the CrashDumpManager. | 28 CrashDumpManager(const base::FilePath& crash_dump_dir, int descriptor_id); |
41 static CrashDumpManager* GetInstance(); | |
42 | |
43 // Should be created on the UI thread. | |
44 explicit CrashDumpManager(const base::FilePath& crash_dump_dir); | |
45 | |
46 ~CrashDumpManager() override; | 29 ~CrashDumpManager() override; |
47 | 30 |
48 // Returns a file that should be used to generate a minidump for the process | 31 // breakpad::CrashDumpObserver::Client implementation: |
49 // |child_process_id|. | 32 void OnChildStart(int child_process_id, |
50 base::File CreateMinidumpFile(int child_process_id); | 33 content::FileDescriptorInfo* mappings) override; |
34 void OnChildExit(int child_process_id, | |
35 base::ProcessHandle pid, | |
36 content::ProcessType process_type, | |
37 base::TerminationStatus termination_status, | |
38 base::android::ApplicationState app_state) override; | |
51 | 39 |
52 private: | 40 private: |
53 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; | 41 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; |
54 | 42 |
55 // This enum is used to back a UMA histogram, and must be treated as | 43 // This enum is used to back a UMA histogram, and must be treated as |
56 // append-only. | 44 // append-only. |
57 enum ExitStatus { | 45 enum ExitStatus { |
58 EMPTY_MINIDUMP_WHILE_RUNNING, | 46 EMPTY_MINIDUMP_WHILE_RUNNING, |
59 EMPTY_MINIDUMP_WHILE_PAUSED, | 47 EMPTY_MINIDUMP_WHILE_PAUSED, |
60 EMPTY_MINIDUMP_WHILE_BACKGROUND, | 48 EMPTY_MINIDUMP_WHILE_BACKGROUND, |
61 VALID_MINIDUMP_WHILE_RUNNING, | 49 VALID_MINIDUMP_WHILE_RUNNING, |
62 VALID_MINIDUMP_WHILE_PAUSED, | 50 VALID_MINIDUMP_WHILE_PAUSED, |
63 VALID_MINIDUMP_WHILE_BACKGROUND, | 51 VALID_MINIDUMP_WHILE_BACKGROUND, |
64 MINIDUMP_STATUS_COUNT | 52 MINIDUMP_STATUS_COUNT |
65 }; | 53 }; |
66 | 54 |
67 static void ProcessMinidump(const base::FilePath& minidump_path, | 55 void ProcessMinidump(const base::FilePath& minidump_path, |
68 base::ProcessHandle pid, | 56 base::ProcessHandle pid, |
69 content::ProcessType process_type, | 57 content::ProcessType process_type, |
70 base::TerminationStatus termination_status, | 58 base::TerminationStatus termination_status, |
71 base::android::ApplicationState app_state); | 59 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 | 60 |
94 // This map should only be accessed with its lock aquired as it is accessed | 61 // This map should only be accessed with its lock aquired as it is accessed |
95 // from the PROCESS_LAUNCHER and UI threads. | 62 // from the PROCESS_LAUNCHER and UI threads. |
96 base::Lock child_process_id_to_minidump_path_lock_; | 63 base::Lock child_process_id_to_minidump_path_lock_; |
97 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_; | 64 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_; |
98 | 65 |
66 // The directory in which temporary minidump files should be created. | |
99 base::FilePath crash_dump_dir_; | 67 base::FilePath crash_dump_dir_; |
100 | 68 // The id used to identify the file descriptor in the set of file |
Bernhard Bauer
2016/08/05 15:43:38
Nit: empty line before comment please.
| |
101 static CrashDumpManager* instance_; | 69 // descriptor mappings passed to the child process. |
70 int descriptor_id_; | |
102 | 71 |
103 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); | 72 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); |
104 }; | 73 }; |
105 | 74 |
106 } // namespace breakpad | 75 } // namespace breakpad |
107 | 76 |
108 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ | 77 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ |
OLD | NEW |