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

Unified Diff: components/crash/content/browser/crash_dump_observer_android.h

Issue 2393853002: Refactor CrashDump*Manager to use a shared CrashDumpObserver singleton. (Closed)
Patch Set: fix initialization in ShellBrowserMainParts Created 4 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: components/crash/content/browser/crash_dump_observer_android.h
diff --git a/components/crash/content/browser/crash_dump_observer_android.h b/components/crash/content/browser/crash_dump_observer_android.h
new file mode 100644
index 0000000000000000000000000000000000000000..e97b9a2811dd57dd6bc83f327771690e6161605d
--- /dev/null
+++ b/components/crash/content/browser/crash_dump_observer_android.h
@@ -0,0 +1,94 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_
+#define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/android/application_status_listener.h"
+#include "base/memory/ref_counted.h"
+#include "base/process/kill.h"
+#include "base/process/process.h"
+#include "content/public/browser/browser_child_process_observer.h"
+#include "content/public/browser/file_descriptor_info.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/common/process_type.h"
+
+namespace breakpad {
+
+// This class centralises the observation of child processes for the
+// purpose of reacting to child process crashes.
+// The CrashDumpObserver instance exists on the browser main thread.
+class CrashDumpObserver : public content::BrowserChildProcessObserver,
+ public content::NotificationObserver {
+ public:
+ // CrashDumpObserver client interface.
+ // Note: do not access the CrashDumpObserver singleton to add or
+ // remove clients from within client callbacks.
+ class Client : public base::RefCountedThreadSafe<Client> {
Bernhard Bauer 2016/10/14 10:41:01 Hm, it would be nice not to make the refcountednes
Tobias Sargeant 2016/12/08 16:41:41 Done, as we discussed. Described above.
+ public:
+ // Called on the launcher thread.
+ virtual void OnChildStart(int child_process_id,
+ content::FileDescriptorInfo* mappings) = 0;
+ // Called on the blocking pool.
+ virtual void OnChildExit(int child_process_id,
+ base::ProcessHandle pid,
+ content::ProcessType process_type,
+ base::TerminationStatus termination_status,
+ base::android::ApplicationState app_state) = 0;
+
+ protected:
+ friend class base::RefCountedThreadSafe<Client>;
+ Client();
+ virtual ~Client();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Client);
+ };
+
+ static void Create();
+ static CrashDumpObserver* GetInstance();
+
+ CrashDumpObserver();
Bernhard Bauer 2016/10/14 10:41:02 Can you make constructor and destructor private? A
Tobias Sargeant 2016/12/08 16:41:41 Done.
+ ~CrashDumpObserver() override;
+
+ void RegisterClient(scoped_refptr<Client> client);
boliu 2016/10/13 21:07:19 not sure if there's a new rule, but at least accor
Bernhard Bauer 2016/10/14 10:41:01 If the method takes a reference, the rule is to pa
Tobias Sargeant 2016/12/08 16:41:41 Acknowledged.
+ void UnregisterClient(scoped_refptr<Client> client);
+
+ void BrowserChildProcessStarted(int child_process_id,
boliu 2016/10/13 21:07:19 this one seems odd because embedder is supposed to
Tobias Sargeant 2016/12/08 16:41:41 Yes, I am. So while you're correct that it's a bit
+ content::FileDescriptorInfo* mappings);
+
+ private:
+ // content::BrowserChildProcessObserver implementation:
+ void BrowserChildProcessHostDisconnected(
+ const content::ChildProcessData& data) override;
+ void BrowserChildProcessCrashed(const content::ChildProcessData& data,
+ int exit_code) override;
+
+ // NotificationObserver implementation:
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
+
+ // Called on child process exit (including crash).
+ void OnChildExit(int child_process_id,
+ base::ProcessHandle pid,
+ content::ProcessType process_type,
+ base::TerminationStatus termination_status,
+ base::android::ApplicationState app_state);
+
+ content::NotificationRegistrar notification_registrar_;
+
+ base::Lock registered_clients_lock_;
+ std::vector<scoped_refptr<Client>> registered_clients_;
boliu 2016/10/13 21:07:19 there is only ever one client is there ever going
Tobias Sargeant 2016/12/08 16:41:41 Yes. WebView will eventually have both CrashDumpMa
+
+ DISALLOW_COPY_AND_ASSIGN(CrashDumpObserver);
+};
+
+} // namespace breakpad
+
+#endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_DUMP_OBSERVER_ANDROID_H_

Powered by Google App Engine
This is Rietveld 408576698