OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ |
| 6 #define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <memory> |
| 10 |
| 11 #include "base/android/application_status_listener.h" |
| 12 #include "base/memory/singleton.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/process/kill.h" |
| 15 #include "base/process/process.h" |
| 16 #include "content/public/browser/browser_child_process_observer.h" |
| 17 #include "content/public/browser/file_descriptor_info.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 breakpad { |
| 23 |
| 24 // XXX: fix comments |
| 25 // This class manages behavior of the browser on renderer crashes when |
| 26 // microdumps are used for capturing the crash stack. Normally, in this case |
| 27 // the browser doesn't need to do much, because a microdump is written into |
| 28 // Android log by the renderer process itself. However, the browser may need to |
| 29 // crash itself on a renderer crash. Since on Android renderers are not child |
| 30 // processes of the browser, it can't access the exit code. Instead, the browser |
| 31 // uses a dedicated pipe in order to receive the information about the renderer |
| 32 // crash status. |
| 33 class CrashDumpObserver : public content::BrowserChildProcessObserver, |
| 34 public content::NotificationObserver { |
| 35 public: |
| 36 class Client { |
| 37 public: |
| 38 Client() {} |
| 39 virtual ~Client() {} |
| 40 |
| 41 virtual void OnChildStart(int child_process_id, |
| 42 content::FileDescriptorInfo* mappings) = 0; |
| 43 virtual void OnChildExit(int child_process_id, |
| 44 base::ProcessHandle pid, |
| 45 content::ProcessType process_type, |
| 46 base::TerminationStatus termination_status, |
| 47 base::android::ApplicationState app_state) = 0; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(Client); |
| 50 }; |
| 51 |
| 52 // There is only a single instance of CrashDumpObserver per browser |
| 53 // process. It needs to be created on the UI thread. |
| 54 static CrashDumpObserver* GetInstance(); |
| 55 |
| 56 void RegisterClient(std::unique_ptr<Client> client); |
| 57 |
| 58 void BrowserChildProcessStarted(int child_process_id, |
| 59 content::FileDescriptorInfo* mappings); |
| 60 |
| 61 private: |
| 62 friend struct base::DefaultSingletonTraits<CrashDumpObserver>; |
| 63 |
| 64 CrashDumpObserver(); |
| 65 ~CrashDumpObserver() override; |
| 66 |
| 67 // content::BrowserChildProcessObserver implementation: |
| 68 void BrowserChildProcessHostDisconnected( |
| 69 const content::ChildProcessData& data) override; |
| 70 void BrowserChildProcessCrashed(const content::ChildProcessData& data, |
| 71 int exit_code) override; |
| 72 |
| 73 // NotificationObserver implementation: |
| 74 void Observe(int type, |
| 75 const content::NotificationSource& source, |
| 76 const content::NotificationDetails& details) override; |
| 77 |
| 78 // Called on child process exit (including crash). |
| 79 void OnChildExit(int child_process_id, |
| 80 base::ProcessHandle pid, |
| 81 content::ProcessType process_type, |
| 82 base::TerminationStatus termination_status, |
| 83 base::android::ApplicationState app_state); |
| 84 |
| 85 content::NotificationRegistrar notification_registrar_; |
| 86 |
| 87 base::Lock registered_clients_lock_; |
| 88 std::list<std::unique_ptr<Client>> registered_clients_; |
| 89 |
| 90 base::WeakPtrFactory<CrashDumpObserver> weak_factory_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(CrashDumpObserver); |
| 93 }; |
| 94 |
| 95 } // namespace breakpad |
| 96 |
| 97 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ |
OLD | NEW |