OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_OBSERVER_ANDROID_H_ | 5 #ifndef COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ |
6 #define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ | 6 #define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/android/application_status_listener.h" | 11 #include "base/android/application_status_listener.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/process/kill.h" | 14 #include "base/process/kill.h" |
15 #include "base/process/process.h" | 15 #include "base/process/process.h" |
16 #include "content/public/browser/browser_child_process_observer.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" | 17 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/posix_file_descriptor_info.h" |
20 #include "content/public/common/process_type.h" | 20 #include "content/public/common/process_type.h" |
21 | 21 |
22 namespace breakpad { | 22 namespace breakpad { |
23 | 23 |
24 // This class centralises the observation of child processes for the | 24 // This class centralises the observation of child processes for the |
25 // purpose of reacting to child process crashes. | 25 // purpose of reacting to child process crashes. |
26 // The CrashDumpObserver instance exists on the browser main thread. | 26 // The CrashDumpObserver instance exists on the browser main thread. |
27 class CrashDumpObserver : public content::BrowserChildProcessObserver, | 27 class CrashDumpObserver : public content::BrowserChildProcessObserver, |
28 public content::NotificationObserver { | 28 public content::NotificationObserver { |
29 public: | 29 public: |
30 // CrashDumpObserver client interface. | 30 // CrashDumpObserver client interface. |
31 // Client methods will be called synchronously in the order in which | 31 // Client methods will be called synchronously in the order in which |
32 // clients were registered. It is the implementer's responsibility | 32 // clients were registered. It is the implementer's responsibility |
33 // to post tasks to the appropriate threads if required (and be | 33 // to post tasks to the appropriate threads if required (and be |
34 // aware that this may break ordering guarantees). | 34 // aware that this may break ordering guarantees). |
35 class Client { | 35 class Client { |
36 public: | 36 public: |
37 // OnChildStart is called on the launcher thread. | 37 // OnChildStart is called on the launcher thread. |
38 virtual void OnChildStart(int child_process_id, | 38 virtual void OnChildStart(int child_process_id, |
39 content::FileDescriptorInfo* mappings) = 0; | 39 content::PosixFileDescriptorInfo* mappings) = 0; |
40 // OnChildExit is called on the UI thread. | 40 // OnChildExit is called on the UI thread. |
41 // OnChildExit may be called twice (once for the child process | 41 // OnChildExit may be called twice (once for the child process |
42 // termination, and once for the IPC channel disconnection). | 42 // termination, and once for the IPC channel disconnection). |
43 virtual void OnChildExit(int child_process_id, | 43 virtual void OnChildExit(int child_process_id, |
44 base::ProcessHandle pid, | 44 base::ProcessHandle pid, |
45 content::ProcessType process_type, | 45 content::ProcessType process_type, |
46 base::TerminationStatus termination_status, | 46 base::TerminationStatus termination_status, |
47 base::android::ApplicationState app_state) = 0; | 47 base::android::ApplicationState app_state) = 0; |
48 | 48 |
49 virtual ~Client() {} | 49 virtual ~Client() {} |
(...skipping 10 matching lines...) Loading... |
60 static CrashDumpObserver* GetInstance(); | 60 static CrashDumpObserver* GetInstance(); |
61 | 61 |
62 void RegisterClient(std::unique_ptr<Client> client); | 62 void RegisterClient(std::unique_ptr<Client> client); |
63 | 63 |
64 // BrowserChildProcessStarted must be called from | 64 // BrowserChildProcessStarted must be called from |
65 // ContentBrowserClient::GetAdditionalMappedFilesForChildProcess | 65 // ContentBrowserClient::GetAdditionalMappedFilesForChildProcess |
66 // overrides, to notify the CrashDumpObserver of child process | 66 // overrides, to notify the CrashDumpObserver of child process |
67 // creation, and to allow clients to register any fd mappings they | 67 // creation, and to allow clients to register any fd mappings they |
68 // need. | 68 // need. |
69 void BrowserChildProcessStarted(int child_process_id, | 69 void BrowserChildProcessStarted(int child_process_id, |
70 content::FileDescriptorInfo* mappings); | 70 content::PosixFileDescriptorInfo* mappings); |
71 | 71 |
72 private: | 72 private: |
73 friend struct base::LazyInstanceTraitsBase<CrashDumpObserver>; | 73 friend struct base::LazyInstanceTraitsBase<CrashDumpObserver>; |
74 | 74 |
75 CrashDumpObserver(); | 75 CrashDumpObserver(); |
76 ~CrashDumpObserver() override; | 76 ~CrashDumpObserver() override; |
77 | 77 |
78 // content::BrowserChildProcessObserver implementation: | 78 // content::BrowserChildProcessObserver implementation: |
79 void BrowserChildProcessHostDisconnected( | 79 void BrowserChildProcessHostDisconnected( |
80 const content::ChildProcessData& data) override; | 80 const content::ChildProcessData& data) override; |
(...skipping 22 matching lines...) Loading... |
103 | 103 |
104 // child_process_id to process id. | 104 // child_process_id to process id. |
105 std::map<int, base::ProcessHandle> child_process_id_to_pid_; | 105 std::map<int, base::ProcessHandle> child_process_id_to_pid_; |
106 | 106 |
107 DISALLOW_COPY_AND_ASSIGN(CrashDumpObserver); | 107 DISALLOW_COPY_AND_ASSIGN(CrashDumpObserver); |
108 }; | 108 }; |
109 | 109 |
110 } // namespace breakpad | 110 } // namespace breakpad |
111 | 111 |
112 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ | 112 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_ |
OLD | NEW |