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