| 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 | 29 |
| 43 // Should be created on the UI thread. | 30 // breakpad::CrashDumpObserver::Client implementation: |
| 44 explicit CrashDumpManager(const base::FilePath& crash_dump_dir); | 31 void OnChildStart(int child_process_id, |
| 45 | 32 content::FileDescriptorInfo* mappings) override; |
| 46 ~CrashDumpManager() override; | 33 void OnChildExit(int child_process_id, |
| 47 | 34 base::ProcessHandle pid, |
| 48 // Returns a file that should be used to generate a minidump for the process | 35 content::ProcessType process_type, |
| 49 // |child_process_id|. | 36 base::TerminationStatus termination_status, |
| 50 base::File CreateMinidumpFile(int child_process_id); | 37 base::android::ApplicationState app_state) override; |
| 51 | 38 |
| 52 private: | 39 private: |
| 53 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; | 40 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; |
| 54 | 41 |
| 55 // This enum is used to back a UMA histogram, and must be treated as | 42 // This enum is used to back a UMA histogram, and must be treated as |
| 56 // append-only. | 43 // append-only. |
| 57 enum ExitStatus { | 44 enum ExitStatus { |
| 58 EMPTY_MINIDUMP_WHILE_RUNNING, | 45 EMPTY_MINIDUMP_WHILE_RUNNING, |
| 59 EMPTY_MINIDUMP_WHILE_PAUSED, | 46 EMPTY_MINIDUMP_WHILE_PAUSED, |
| 60 EMPTY_MINIDUMP_WHILE_BACKGROUND, | 47 EMPTY_MINIDUMP_WHILE_BACKGROUND, |
| 61 VALID_MINIDUMP_WHILE_RUNNING, | 48 VALID_MINIDUMP_WHILE_RUNNING, |
| 62 VALID_MINIDUMP_WHILE_PAUSED, | 49 VALID_MINIDUMP_WHILE_PAUSED, |
| 63 VALID_MINIDUMP_WHILE_BACKGROUND, | 50 VALID_MINIDUMP_WHILE_BACKGROUND, |
| 64 MINIDUMP_STATUS_COUNT | 51 MINIDUMP_STATUS_COUNT |
| 65 }; | 52 }; |
| 66 | 53 |
| 67 static void ProcessMinidump(const base::FilePath& minidump_path, | 54 ~CrashDumpManager() override; |
| 68 base::ProcessHandle pid, | |
| 69 content::ProcessType process_type, | |
| 70 base::TerminationStatus termination_status, | |
| 71 base::android::ApplicationState app_state); | |
| 72 | 55 |
| 73 // content::BrowserChildProcessObserver implementation: | 56 void ProcessMinidump(const base::FilePath& minidump_path, |
| 74 void BrowserChildProcessHostDisconnected( | 57 base::ProcessHandle pid, |
| 75 const content::ChildProcessData& data) override; | 58 content::ProcessType process_type, |
| 76 void BrowserChildProcessCrashed( | 59 base::TerminationStatus termination_status, |
| 77 const content::ChildProcessData& data, | 60 base::android::ApplicationState app_state); |
| 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 |
| 67 // The directory in which temporary minidump files should be created. |
| 99 base::FilePath crash_dump_dir_; | 68 base::FilePath crash_dump_dir_; |
| 100 | 69 |
| 101 static CrashDumpManager* instance_; | 70 // The id used to identify the file descriptor in the set of file |
| 71 // descriptor mappings passed to the child process. |
| 72 int descriptor_id_; |
| 102 | 73 |
| 103 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); | 74 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); |
| 104 }; | 75 }; |
| 105 | 76 |
| 106 } // namespace breakpad | 77 } // namespace breakpad |
| 107 | 78 |
| 108 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ | 79 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ |
| OLD | NEW |