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/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 | |
Lei Zhang
2016/10/05 18:00:00
Can you say something about what thread this class
Tobias Sargeant
2016/10/06 17:42:22
The observer lives on the browser main thread. (I'
| |
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 : public base::RefCountedThreadSafe<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 friend class base::RefCountedThreadSafe<Client>; | |
45 Client(); | |
46 virtual ~Client(); | |
47 | |
48 private: | |
49 DISALLOW_COPY_AND_ASSIGN(Client); | |
50 }; | |
51 | |
52 static CrashDumpObserver* GetInstance(); | |
53 | |
54 CrashDumpObserver(); | |
55 ~CrashDumpObserver() override; | |
56 | |
57 void RegisterClient(scoped_refptr<Client> client); | |
58 void UnregisterClient(scoped_refptr<Client> client); | |
59 | |
60 void BrowserChildProcessStarted(int child_process_id, | |
61 content::FileDescriptorInfo* mappings); | |
62 | |
63 private: | |
64 // content::BrowserChildProcessObserver implementation: | |
65 void BrowserChildProcessHostDisconnected( | |
66 const content::ChildProcessData& data) override; | |
67 void BrowserChildProcessCrashed(const content::ChildProcessData& data, | |
68 int exit_code) override; | |
69 | |
70 // NotificationObserver implementation: | |
71 void Observe(int type, | |
72 const content::NotificationSource& source, | |
73 const content::NotificationDetails& details) override; | |
74 | |
75 // Called on child process exit (including crash). | |
76 void OnChildExit(int child_process_id, | |
77 base::ProcessHandle pid, | |
78 content::ProcessType process_type, | |
79 base::TerminationStatus termination_status, | |
80 base::android::ApplicationState app_state); | |
81 | |
82 content::NotificationRegistrar notification_registrar_; | |
83 | |
84 base::Lock registered_clients_lock_; | |
85 std::list<scoped_refptr<Client>> registered_clients_; | |
Lei Zhang
2016/10/05 18:00:00
As is, there's no advantage of having this as a li
Tobias Sargeant
2016/10/13 12:52:14
Have changed it.
| |
86 | |
87 static CrashDumpObserver* instance_; | |
Lei Zhang
2016/10/05 18:00:00
Can this just be declared in crash_dump_observer_a
Tobias Sargeant
2016/10/06 17:42:22
It could be done this way. Would it be preferable
Tobias Sargeant
2016/10/13 12:52:14
PS4 does things this way.
boliu
2016/10/13 21:07:18
LazyInstance seems overkill and wrong, because thi
| |
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 |