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/process/kill.h" |
| 14 #include "base/process/process.h" |
| 15 #include "content/public/browser/browser_child_process_observer.h" |
| 16 #include "content/public/browser/file_descriptor_info.h" |
| 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/common/process_type.h" |
| 20 |
| 21 namespace breakpad { |
| 22 |
| 23 // This class centralises the observation of child processes for the |
| 24 // purpose of reacting to child process crashes. |
| 25 class CrashDumpObserver : public content::BrowserChildProcessObserver, |
| 26 public content::NotificationObserver { |
| 27 public: |
| 28 // CrashDumpObserver client interface. |
| 29 // Note: do not access the CrashDumpObserver singleton to add or |
| 30 // remove clients from within client callbacks. |
| 31 class Client { |
| 32 public: |
| 33 // Called on the launcher thread. |
| 34 virtual void OnChildStart(int child_process_id, |
| 35 content::FileDescriptorInfo* mappings) = 0; |
| 36 // Called on the blocking pool. |
| 37 virtual void OnChildExit(int child_process_id, |
| 38 base::ProcessHandle pid, |
| 39 content::ProcessType process_type, |
| 40 base::TerminationStatus termination_status, |
| 41 base::android::ApplicationState app_state) = 0; |
| 42 |
| 43 protected: |
| 44 virtual ~Client() {} |
| 45 }; |
| 46 |
| 47 static CrashDumpObserver* GetInstance(); |
| 48 |
| 49 void RegisterClient(Client* client); |
| 50 void UnregisterClient(Client* client); |
| 51 |
| 52 void BrowserChildProcessStarted(int child_process_id, |
| 53 content::FileDescriptorInfo* mappings); |
| 54 |
| 55 private: |
| 56 friend struct base::DefaultSingletonTraits<CrashDumpObserver>; |
| 57 |
| 58 CrashDumpObserver(); |
| 59 ~CrashDumpObserver() override; |
| 60 |
| 61 // content::BrowserChildProcessObserver implementation: |
| 62 void BrowserChildProcessHostDisconnected( |
| 63 const content::ChildProcessData& data) override; |
| 64 void BrowserChildProcessCrashed(const content::ChildProcessData& data, |
| 65 int exit_code) override; |
| 66 |
| 67 // NotificationObserver implementation: |
| 68 void Observe(int type, |
| 69 const content::NotificationSource& source, |
| 70 const content::NotificationDetails& details) override; |
| 71 |
| 72 void OnChildExitOnBlockingPool(Client* client, |
| 73 int child_process_id, |
| 74 base::ProcessHandle pid, |
| 75 content::ProcessType process_type, |
| 76 base::TerminationStatus termination_status, |
| 77 base::android::ApplicationState app_state); |
| 78 |
| 79 // Called on child process exit (including crash). |
| 80 void OnChildExit(int child_process_id, |
| 81 base::ProcessHandle pid, |
| 82 content::ProcessType process_type, |
| 83 base::TerminationStatus termination_status, |
| 84 base::android::ApplicationState app_state); |
| 85 |
| 86 content::NotificationRegistrar notification_registrar_; |
| 87 |
| 88 base::Lock registered_clients_lock_; |
| 89 std::list<Client*> registered_clients_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(CrashDumpObserver); |
| 92 }; |
| 93 |
| 94 } // namespace breakpad |
| 95 |
| 96 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ |
OLD | NEW |