1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
media / base / android / media_server_crash_listener.cc [blame]
// Copyright 2016 The Chromium Authors
// 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/jni_android.h"
#include "base/memory/singleton.h"
#include "base/task/single_thread_task_runner.h"
// Must come after all headers that specialize FromJniType() / ToJniType().
#include "media/base/android/media_jni_headers/MediaServerCrashListener_jni.h"
namespace media {
MediaServerCrashListener::MediaServerCrashListener(
OnMediaServerCrashCB on_server_crash_cb,
scoped_refptr<base::SingleThreadTaskRunner> callback_thread)
: on_server_crash_cb_(std::move(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, reinterpret_cast<intptr_t>(this)));
Java_MediaServerCrashListener_startListening(env, j_crash_listener_);
}
MediaServerCrashListener::~MediaServerCrashListener() {
ReleaseWatchdog();
}
void MediaServerCrashListener::ReleaseWatchdog() {
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,
jboolean watchdog_needs_release) {
callback_task_runner_->PostTask(
FROM_HERE, base::BindOnce(on_server_crash_cb_, watchdog_needs_release));
}
} // namespace media