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

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

Issue 2200693002: Refactor CrashDump*Manager to use a shared CrashDumpObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clang compile errors Created 4 years, 4 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..d1bc46968a5eff6f7ace1c88abb5559f9b6fcee4
--- /dev/null
+++ b/components/crash/content/browser/crash_dump_observer_android.h
@@ -0,0 +1,97 @@
+// 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 <list>
+#include <memory>
+
+#include "base/android/application_status_listener.h"
+#include "base/memory/singleton.h"
+#include "base/memory/weak_ptr.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 {
+
+// XXX: fix comments
+// This class manages behavior of the browser on renderer crashes when
+// microdumps are used for capturing the crash stack. Normally, in this case
+// the browser doesn't need to do much, because a microdump is written into
+// Android log by the renderer process itself. However, the browser may need to
+// crash itself on a renderer crash. Since on Android renderers are not child
+// processes of the browser, it can't access the exit code. Instead, the browser
+// uses a dedicated pipe in order to receive the information about the renderer
+// crash status.
+class CrashDumpObserver : public content::BrowserChildProcessObserver,
+ public content::NotificationObserver {
+ public:
+ class Client {
+ public:
+ Client() {}
+ virtual ~Client() {}
+
+ virtual void OnChildStart(int child_process_id,
+ content::FileDescriptorInfo* mappings) = 0;
+ virtual void OnChildExit(int child_process_id,
+ base::ProcessHandle pid,
+ content::ProcessType process_type,
+ base::TerminationStatus termination_status,
+ base::android::ApplicationState app_state) = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(Client);
+ };
+
+ // There is only a single instance of CrashDumpObserver per browser
+ // process. It needs to be created on the UI thread.
+ static CrashDumpObserver* GetInstance();
+
+ void RegisterClient(std::unique_ptr<Client> client);
+
+ void BrowserChildProcessStarted(int child_process_id,
+ content::FileDescriptorInfo* mappings);
+
+ private:
+ friend struct base::DefaultSingletonTraits<CrashDumpObserver>;
+
+ CrashDumpObserver();
+ ~CrashDumpObserver() override;
+
+ // 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::list<std::unique_ptr<Client>> registered_clients_;
+
+ base::WeakPtrFactory<CrashDumpObserver> weak_factory_;
+
+ 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