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

Unified Diff: media/base/android/media_server_crash_listener.cc

Issue 2471903002: Add MediaServiceThrottler (Closed)
Patch Set: Limit crashes from watchdog creation failures Created 4 years, 1 month 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: media/base/android/media_server_crash_listener.cc
diff --git a/media/base/android/media_server_crash_listener.cc b/media/base/android/media_server_crash_listener.cc
new file mode 100644
index 0000000000000000000000000000000000000000..99611148992869c4414f2273e15807264c08d0a3
--- /dev/null
+++ b/media/base/android/media_server_crash_listener.cc
@@ -0,0 +1,49 @@
+// Copyright 2016 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.
+
+#include "media/base/android/media_server_crash_listener.h"
+
+#include "base/android/context_utils.h"
+#include "base/android/jni_android.h"
+#include "base/memory/singleton.h"
+#include "jni/MediaServerCrashListener_jni.h"
+
+namespace media {
+
+// static
+bool MediaServerCrashListener::RegisterMediaServerCrashListener(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+MediaServerCrashListener::MediaServerCrashListener(
+ const base::Closure& on_server_crash_cb,
+ scoped_refptr<base::SingleThreadTaskRunner> callback_thread)
+ : on_server_crash_cb_(on_server_crash_cb),
+ callback_task_runner_(std::move(callback_thread)) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ CHECK(env);
+
+ j_crash_listener_.Reset(Java_MediaServerCrashListener_create(
+ env, base::android::GetApplicationContext(),
+ reinterpret_cast<intptr_t>(this)));
+ Java_MediaServerCrashListener_startListening(env, j_crash_listener_);
+}
+
+MediaServerCrashListener::~MediaServerCrashListener() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_MediaServerCrashListener_releaseWatchdog(env, j_crash_listener_);
+}
+
+void MediaServerCrashListener::EnsureListening() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_MediaServerCrashListener_startListening(env, j_crash_listener_);
+}
+
+void MediaServerCrashListener::OnMediaServerCrashDetected(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj) {
+ callback_task_runner_->PostTask(FROM_HERE, on_server_crash_cb_);
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698