| 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 | 13 |
| 22 namespace breakpad { | 14 namespace breakpad { |
| 23 | 15 |
| 24 // This class manages the crash minidumps. | 16 // This class manages the crash minidumps. |
| 25 // 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 |
| 26 // 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 |
| 27 // (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 |
| 28 // crashed process). So the minidump is generated in the renderer process. | 20 // crashed process). So the minidump is generated in the renderer process. |
| 29 // 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 |
| 30 // 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. |
| 31 // This class creates these file descriptors and associates them with render | 23 // This class creates these file descriptors and associates them with render |
| 32 // processes and take the appropriate action when the render process terminates. | 24 // processes and takes the appropriate action when the render process |
| 33 class CrashDumpManager : public content::BrowserChildProcessObserver, | 25 // terminates. |
| 34 public content::NotificationObserver { | 26 class CrashDumpManager : public breakpad::CrashDumpObserver::Client { |
| 35 public: | 27 public: |
| 36 // The embedder should create a single instance of the CrashDumpManager. | 28 CrashDumpManager(const base::FilePath& crash_dump_dir, int descriptor_id); |
| 37 static CrashDumpManager* GetInstance(); | |
| 38 | |
| 39 // Should be created on the UI thread. | |
| 40 explicit CrashDumpManager(const base::FilePath& crash_dump_dir); | |
| 41 | |
| 42 ~CrashDumpManager() override; | 29 ~CrashDumpManager() override; |
| 43 | 30 |
| 44 // Returns a file that should be used to generate a minidump for the process | 31 // breakpad::CrashDumpObserver::Client implementation: |
| 45 // |child_process_id|. | 32 void OnChildStart(int child_process_id, |
| 46 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; |
| 47 | 39 |
| 48 private: | 40 private: |
| 49 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; | 41 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath; |
| 50 | 42 |
| 51 // 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 |
| 52 // append-only. | 44 // append-only. |
| 53 enum ExitStatus { | 45 enum ExitStatus { |
| 54 EMPTY_MINIDUMP_WHILE_RUNNING, | 46 EMPTY_MINIDUMP_WHILE_RUNNING, |
| 55 EMPTY_MINIDUMP_WHILE_PAUSED, | 47 EMPTY_MINIDUMP_WHILE_PAUSED, |
| 56 EMPTY_MINIDUMP_WHILE_BACKGROUND, | 48 EMPTY_MINIDUMP_WHILE_BACKGROUND, |
| 57 VALID_MINIDUMP_WHILE_RUNNING, | 49 VALID_MINIDUMP_WHILE_RUNNING, |
| 58 VALID_MINIDUMP_WHILE_PAUSED, | 50 VALID_MINIDUMP_WHILE_PAUSED, |
| 59 VALID_MINIDUMP_WHILE_BACKGROUND, | 51 VALID_MINIDUMP_WHILE_BACKGROUND, |
| 60 MINIDUMP_STATUS_COUNT | 52 MINIDUMP_STATUS_COUNT |
| 61 }; | 53 }; |
| 62 | 54 |
| 63 static void ProcessMinidump(const base::FilePath& minidump_path, | 55 static void ProcessMinidump(const base::FilePath& minidump_path, |
| 56 const base::FilePath& crash_dump_dir, |
| 64 base::ProcessHandle pid, | 57 base::ProcessHandle pid, |
| 65 content::ProcessType process_type, | 58 content::ProcessType process_type, |
| 66 base::TerminationStatus termination_status, | 59 base::TerminationStatus termination_status, |
| 67 base::android::ApplicationState app_state); | 60 base::android::ApplicationState app_state); |
| 68 | 61 |
| 69 // content::BrowserChildProcessObserver implementation: | |
| 70 void BrowserChildProcessHostDisconnected( | |
| 71 const content::ChildProcessData& data) override; | |
| 72 void BrowserChildProcessCrashed( | |
| 73 const content::ChildProcessData& data, | |
| 74 int exit_code) override; | |
| 75 | |
| 76 // NotificationObserver implementation: | |
| 77 void Observe(int type, | |
| 78 const content::NotificationSource& source, | |
| 79 const content::NotificationDetails& details) override; | |
| 80 | |
| 81 // Called on child process exit (including crash). | |
| 82 void OnChildExit(int child_process_id, | |
| 83 base::ProcessHandle pid, | |
| 84 content::ProcessType process_type, | |
| 85 base::TerminationStatus termination_status, | |
| 86 base::android::ApplicationState app_state); | |
| 87 | |
| 88 content::NotificationRegistrar notification_registrar_; | |
| 89 | |
| 90 // 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 |
| 91 // from the PROCESS_LAUNCHER and UI threads. | 63 // from the PROCESS_LAUNCHER and UI threads. |
| 92 base::Lock child_process_id_to_minidump_path_lock_; | 64 base::Lock child_process_id_to_minidump_path_lock_; |
| 93 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_; | 65 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_; |
| 94 | 66 |
| 67 // The directory in which temporary minidump files should be created. |
| 95 base::FilePath crash_dump_dir_; | 68 base::FilePath crash_dump_dir_; |
| 96 | 69 |
| 97 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_; |
| 98 | 73 |
| 99 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); | 74 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); |
| 100 }; | 75 }; |
| 101 | 76 |
| 102 } // namespace breakpad | 77 } // namespace breakpad |
| 103 | 78 |
| 104 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ | 79 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_ |
| OLD | NEW |