Chromium Code Reviews| 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/lazy_instance.h" | |
| 13 #include "base/memory/ref_counted.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 // This class centralises the observation of child processes for the | |
| 25 // purpose of reacting to child process crashes. | |
| 26 // The CrashDumpObserver instance exists on the browser main thread. | |
| 27 class CrashDumpObserver : public content::BrowserChildProcessObserver, | |
| 28 public content::NotificationObserver { | |
| 29 public: | |
| 30 // CrashDumpObserver client interface. | |
| 31 // Client methods will be called synchronously in the order in which | |
| 32 // clients were registered. It is the implementer's responsibility | |
| 33 // to post tasks to the appropriate threads if required (and be | |
| 34 // aware that this may break ordering guarantees). | |
| 35 class Client { | |
| 36 public: | |
| 37 // OnChildStart is called on the launcher thread. | |
| 38 virtual void OnChildStart(int child_process_id, | |
| 39 content::FileDescriptorInfo* mappings) = 0; | |
| 40 // OnChildExit is called on the UI thread. | |
| 41 // OnChildExit may be called twice (once for the child process | |
| 42 // termination, and once for the IPC channel disconnection). | |
| 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 virtual ~Client() {} | |
| 50 }; | |
| 51 | |
| 52 // The global CrashDumpObserver instance is created by calling | |
| 53 // Create (on the UI thread), and lives until process exit. Tests | |
|
Robert Sesek
2016/12/14 22:44:14
Rather than making this a LazyInstance, would it b
Tobias Sargeant
2016/12/15 14:59:48
I tried doing this for AwContentBrowserClient, and
Robert Sesek
2016/12/15 17:10:57
OK, I thought that may be the case. Thanks for che
| |
| 54 // making use of this class should register an AtExitManager. | |
| 55 static void Create(); | |
| 56 | |
| 57 // Fetch a pointer to the global CrashDumpObserver instance. The | |
| 58 // global instance must have been created by the time GetInstance is | |
| 59 // called. | |
| 60 static CrashDumpObserver* GetInstance(); | |
| 61 | |
| 62 void RegisterClient(std::unique_ptr<Client> client); | |
| 63 | |
| 64 // BrowserChildProcessStarted must be called from | |
| 65 // ContentBrowserClient::GetAdditionalMappedFilesForChildProcess | |
| 66 // overrides, to notify the CrashDumpObserver of child process | |
| 67 // creation, and to allow clients to register any fd mappings they | |
| 68 // need. | |
| 69 void BrowserChildProcessStarted(int child_process_id, | |
| 70 content::FileDescriptorInfo* mappings); | |
| 71 | |
| 72 private: | |
| 73 friend struct base::DefaultLazyInstanceTraits<CrashDumpObserver>; | |
| 74 | |
| 75 CrashDumpObserver(); | |
| 76 ~CrashDumpObserver() override; | |
| 77 | |
| 78 // content::BrowserChildProcessObserver implementation: | |
| 79 void BrowserChildProcessHostDisconnected( | |
| 80 const content::ChildProcessData& data) override; | |
| 81 void BrowserChildProcessCrashed(const content::ChildProcessData& data, | |
| 82 int exit_code) override; | |
| 83 // On Android we will never observe BrowserChildProcessCrashed | |
| 84 // because we do not receive exit codes from zygote spawned | |
| 85 // processes. | |
| 86 | |
| 87 // NotificationObserver implementation: | |
| 88 void Observe(int type, | |
| 89 const content::NotificationSource& source, | |
| 90 const content::NotificationDetails& details) override; | |
| 91 | |
| 92 // Called on child process exit (including crash). | |
| 93 void OnChildExit(int child_process_id, | |
| 94 base::ProcessHandle pid, | |
| 95 content::ProcessType process_type, | |
| 96 base::TerminationStatus termination_status, | |
| 97 base::android::ApplicationState app_state); | |
| 98 | |
| 99 content::NotificationRegistrar notification_registrar_; | |
| 100 | |
| 101 base::Lock registered_clients_lock_; | |
| 102 std::vector<std::unique_ptr<Client>> registered_clients_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(CrashDumpObserver); | |
| 105 }; | |
| 106 | |
| 107 } // namespace breakpad | |
| 108 | |
| 109 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ | |
| OLD | NEW |