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 <memory> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/android/application_status_listener.h" |
| 12 #include "base/memory/ref_counted.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 // The CrashDumpObserver instance exists on the browser main thread. |
| 26 class CrashDumpObserver : public content::BrowserChildProcessObserver, |
| 27 public content::NotificationObserver { |
| 28 public: |
| 29 // CrashDumpObserver client interface. |
| 30 // Note: do not access the CrashDumpObserver singleton to add or |
| 31 // remove clients from within client callbacks. |
| 32 class Client : public base::RefCountedThreadSafe<Client> { |
| 33 public: |
| 34 // Called on the launcher thread. |
| 35 virtual void OnChildStart(int child_process_id, |
| 36 content::FileDescriptorInfo* mappings) = 0; |
| 37 // Called on the blocking pool. |
| 38 virtual void OnChildExit(int child_process_id, |
| 39 base::ProcessHandle pid, |
| 40 content::ProcessType process_type, |
| 41 base::TerminationStatus termination_status, |
| 42 base::android::ApplicationState app_state) = 0; |
| 43 |
| 44 protected: |
| 45 friend class base::RefCountedThreadSafe<Client>; |
| 46 Client(); |
| 47 virtual ~Client(); |
| 48 |
| 49 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(Client); |
| 51 }; |
| 52 |
| 53 static void Create(); |
| 54 static CrashDumpObserver* GetInstance(); |
| 55 |
| 56 CrashDumpObserver(); |
| 57 ~CrashDumpObserver() override; |
| 58 |
| 59 void RegisterClient(scoped_refptr<Client> client); |
| 60 void UnregisterClient(scoped_refptr<Client> client); |
| 61 |
| 62 void BrowserChildProcessStarted(int child_process_id, |
| 63 content::FileDescriptorInfo* mappings); |
| 64 |
| 65 private: |
| 66 // content::BrowserChildProcessObserver implementation: |
| 67 void BrowserChildProcessHostDisconnected( |
| 68 const content::ChildProcessData& data) override; |
| 69 void BrowserChildProcessCrashed(const content::ChildProcessData& data, |
| 70 int exit_code) override; |
| 71 |
| 72 // NotificationObserver implementation: |
| 73 void Observe(int type, |
| 74 const content::NotificationSource& source, |
| 75 const content::NotificationDetails& details) override; |
| 76 |
| 77 // Called on child process exit (including crash). |
| 78 void OnChildExit(int child_process_id, |
| 79 base::ProcessHandle pid, |
| 80 content::ProcessType process_type, |
| 81 base::TerminationStatus termination_status, |
| 82 base::android::ApplicationState app_state); |
| 83 |
| 84 content::NotificationRegistrar notification_registrar_; |
| 85 |
| 86 base::Lock registered_clients_lock_; |
| 87 std::vector<scoped_refptr<Client>> registered_clients_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(CrashDumpObserver); |
| 90 }; |
| 91 |
| 92 } // namespace breakpad |
| 93 |
| 94 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ |
OLD | NEW |