Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: components/crash/content/browser/crash_dump_observer_android.h

Issue 2393853002: Refactor CrashDump*Manager to use a shared CrashDumpObserver singleton. (Closed)
Patch Set: Review changes: remove refcounting, ability to unregister clients, move responsibility for posting to clients Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
54 // making use of this class should register an AtExitManager.
55 static void Create();
56 // Fetch a pointer to the global CrashDumpObserver instance. The
Bernhard Bauer 2016/12/08 17:41:25 Nit: empty line before the comment?
Tobias Sargeant 2016/12/12 11:49:51 Done.
57 // global instance must have been created by the time GetInstance is
58 // called.
59 static CrashDumpObserver* GetInstance();
60
61 void RegisterClient(std::unique_ptr<Client> client);
62
63 // BrowserChildProcessStarted must be called from
64 // ContentBrowserClient::GetAdditionalMappedFilesForChildProcess
65 // overrides, to notify the CrashDumpObserver of child process
66 // creation, and to allow clients to register any fd mappings they
67 // need.
68 void BrowserChildProcessStarted(int child_process_id,
69 content::FileDescriptorInfo* mappings);
70
71 private:
72 friend struct base::DefaultLazyInstanceTraits<CrashDumpObserver>;
73
74 CrashDumpObserver();
75 ~CrashDumpObserver() override;
76
77 // content::BrowserChildProcessObserver implementation:
78 void BrowserChildProcessHostDisconnected(
79 const content::ChildProcessData& data) override;
80 void BrowserChildProcessCrashed(const content::ChildProcessData& data,
81 int exit_code) override;
82 // On Android we will never observe BrowserChildProcessCrashed
83 // because we do not receive exit codes from zygote spawned
84 // processes.
85
86 // NotificationObserver implementation:
87 void Observe(int type,
88 const content::NotificationSource& source,
89 const content::NotificationDetails& details) override;
90
91 // Called on child process exit (including crash).
92 void OnChildExit(int child_process_id,
93 base::ProcessHandle pid,
94 content::ProcessType process_type,
95 base::TerminationStatus termination_status,
96 base::android::ApplicationState app_state);
97
98 content::NotificationRegistrar notification_registrar_;
99
100 base::Lock registered_clients_lock_;
101 std::vector<std::unique_ptr<Client>> registered_clients_;
102
103 DISALLOW_COPY_AND_ASSIGN(CrashDumpObserver);
104 };
105
106 } // namespace breakpad
107
108 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698