Chromium Code Reviews| 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..276842168cdeafdf175497b6a9823adc5775137f |
| --- /dev/null |
| +++ b/media/base/android/media_server_crash_listener.cc |
| @@ -0,0 +1,56 @@ |
| +// 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_(callback_thread) { |
|
watk
2016/11/12 04:22:16
You should move this into the member variable to a
|
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + CHECK(env); |
| + |
| + j_crash_listener_.Reset(Java_MediaServerCrashListener_create( |
| + env, base::android::GetApplicationContext(), |
| + reinterpret_cast<intptr_t>(this))); |
| + |
| + is_listening_ = |
| + Java_MediaServerCrashListener_startListening(env, j_crash_listener_); |
| +} |
| + |
| +MediaServerCrashListener::~MediaServerCrashListener() { |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + Java_MediaServerCrashListener_releaseWatchdog(env, j_crash_listener_); |
| +} |
| + |
| +void MediaServerCrashListener::EnsureListening() { |
| + if (is_listening_) |
| + return; |
| + |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + is_listening_ = |
| + Java_MediaServerCrashListener_startListening(env, j_crash_listener_); |
| +} |
| + |
| +void MediaServerCrashListener::OnMediaServerCrashDetected( |
| + JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj) { |
| + if (on_server_crash_cb_) |
|
DaleCurtis
2016/11/11 23:32:15
Seems this should clear is_listening_?
tguilbert
2016/11/14 23:18:07
This was an artifact of the previous iteration. Up
|
| + callback_task_runner_->PostTask(FROM_HERE, on_server_crash_cb_); |
| +} |
| + |
| +} // namespace media |