Chromium Code Reviews| Index: remoting/android/host/src/org/chromium/chromoting/host/jni/Host.java |
| diff --git a/remoting/android/host/src/org/chromium/chromoting/host/jni/Host.java b/remoting/android/host/src/org/chromium/chromoting/host/jni/Host.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a85adcd487f2ee243ed0cc2613d340f12217eecc |
| --- /dev/null |
| +++ b/remoting/android/host/src/org/chromium/chromoting/host/jni/Host.java |
| @@ -0,0 +1,44 @@ |
| +// 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. |
| + |
| +package org.chromium.chromoting.host.jni; |
| + |
| +import android.content.Context; |
| + |
| +import org.chromium.base.ContextUtils; |
| +import org.chromium.base.annotations.JNINamespace; |
| + |
| +/** |
| + * Class to allow Java code to access the native C++ implementation of the Host process. This class |
| + * controls the lifetime of the corresponding C++ object. |
| + */ |
| +@JNINamespace("remoting") |
| +public class Host { |
| + // Pointer to the C++ object, cast to a |long|. |
| + private long mNativeJniHost; |
| + |
| + private static boolean sLoaded; |
| + |
| + // Called once from the main Activity. Loads and initializes the native |
| + // code. |
| + public static void loadLibrary(Context context) { |
| + if (sLoaded) return; |
|
Sergey Ulanov
2016/04/07 00:41:06
Do we need synchronization here?
Or if we don't ex
Lambros
2016/04/11 18:44:47
It's only called during Activity.onCreate() on the
|
| + |
| + System.loadLibrary("remoting_host_jni"); |
| + ContextUtils.initApplicationContext(context.getApplicationContext()); |
| + sLoaded = true; |
| + } |
| + |
| + public Host() { |
| + mNativeJniHost = nativeInit(); |
| + } |
| + |
| + private native long nativeInit(); |
| + |
| + public void destroy() { |
| + nativeDestroy(mNativeJniHost); |
| + } |
| + |
| + private native void nativeDestroy(long nativeJniHost); |
| +} |