summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlambroslambrou <lambroslambrou@chromium.org>2015-09-02 12:46:02 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-02 19:46:45 +0000
commitb5013a8a50592741b917edc79b28a743434287a1 (patch)
tree078605ec55c3501386a776bc27b56ec3b7de4d47
parent989d386cbe93ec261df6bd8a87fef5532dea1669 (diff)
downloadchromium_src-b5013a8a50592741b917edc79b28a743434287a1.zip
chromium_src-b5013a8a50592741b917edc79b28a743434287a1.tar.gz
chromium_src-b5013a8a50592741b917edc79b28a743434287a1.tar.bz2
Android Chromoting: Add new Java/C++ classes for client connection.
This adds new Java/C++ classes (empty stubs) for managing a connection to the host. A new instance will be created each time a connection is made, which should eliminate a class of bugs where notifications are received from previous connections. Now that more than 1 Java class is using JNI, this CL also adds remoting_jni_registrar.cc to manage all the JNI registrations, in line with other examples in Chromium code. This also renames the ..onload.cc file, to follow the naming convention used elsewhere (since our code lives in the remoting/ directory). BUG=526336 Review URL: https://codereview.chromium.org/1319293002 Cr-Commit-Position: refs/heads/master@{#346998}
-rw-r--r--remoting/android/java/src/org/chromium/chromoting/jni/Client.java31
-rw-r--r--remoting/client/jni/chromoting_jni_runtime.cc2
-rw-r--r--remoting/client/jni/chromoting_jni_runtime.h2
-rw-r--r--remoting/client/jni/jni_client.cc30
-rw-r--r--remoting/client/jni/jni_client.h30
-rw-r--r--remoting/client/jni/remoting_jni_onload.cc (renamed from remoting/client/jni/chromoting_jni_onload.cc)3
-rw-r--r--remoting/client/jni/remoting_jni_registrar.cc28
-rw-r--r--remoting/client/jni/remoting_jni_registrar.h17
-rw-r--r--remoting/remoting_android.gypi7
9 files changed, 146 insertions, 4 deletions
diff --git a/remoting/android/java/src/org/chromium/chromoting/jni/Client.java b/remoting/android/java/src/org/chromium/chromoting/jni/Client.java
new file mode 100644
index 0000000..6c67a8c
--- /dev/null
+++ b/remoting/android/java/src/org/chromium/chromoting/jni/Client.java
@@ -0,0 +1,31 @@
+// 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.
+
+package org.chromium.chromoting.jni;
+
+import org.chromium.base.annotations.JNINamespace;
+
+/**
+ * Class to manage a client connection to the host. This class controls the lifetime of the
+ * corresponding C++ object which implements the connection. A new object should be created for
+ * each connection to the host, so that notifications from a connection are always sent to the
+ * right object.
+ */
+@JNINamespace("remoting")
+public class Client {
+ // Pointer to the C++ object, cast to a |long|.
+ private long mNativeJniClient;
+
+ public void init() {
+ mNativeJniClient = nativeInit();
+ }
+
+ private native long nativeInit();
+
+ public void destroy() {
+ nativeDestroy(mNativeJniClient);
+ }
+
+ private native void nativeDestroy(long nativeJniClient);
+}
diff --git a/remoting/client/jni/chromoting_jni_runtime.cc b/remoting/client/jni/chromoting_jni_runtime.cc
index 130c895..6bdf286 100644
--- a/remoting/client/jni/chromoting_jni_runtime.cc
+++ b/remoting/client/jni/chromoting_jni_runtime.cc
@@ -30,7 +30,7 @@ const int kBytesPerPixel = 4;
namespace remoting {
-bool RegisterJni(JNIEnv* env) {
+bool RegisterChromotingJniRuntime(JNIEnv* env) {
return remoting::RegisterNativesImpl(env);
}
diff --git a/remoting/client/jni/chromoting_jni_runtime.h b/remoting/client/jni/chromoting_jni_runtime.h
index 1ca1124..5fb4957 100644
--- a/remoting/client/jni/chromoting_jni_runtime.h
+++ b/remoting/client/jni/chromoting_jni_runtime.h
@@ -18,7 +18,7 @@ template<typename T> struct DefaultSingletonTraits;
namespace remoting {
-bool RegisterJni(JNIEnv* env);
+bool RegisterChromotingJniRuntime(JNIEnv* env);
// Houses the global resources on which the Chromoting components run
// (e.g. message loops and task runners). Proxies outgoing JNI calls from its
diff --git a/remoting/client/jni/jni_client.cc b/remoting/client/jni/jni_client.cc
new file mode 100644
index 0000000..0f634ff
--- /dev/null
+++ b/remoting/client/jni/jni_client.cc
@@ -0,0 +1,30 @@
+// 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.
+
+#include "remoting/client/jni/jni_client.h"
+
+#include "jni/Client_jni.h"
+
+namespace remoting {
+
+JniClient::JniClient() {
+}
+
+JniClient::~JniClient() {
+}
+
+// static
+bool JniClient::RegisterJni(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+void JniClient::Destroy(JNIEnv* env, jobject caller) {
+ delete this;
+}
+
+static jlong Init(JNIEnv* env, jobject caller) {
+ return reinterpret_cast<intptr_t>(new JniClient());
+}
+
+} // namespace remoting
diff --git a/remoting/client/jni/jni_client.h b/remoting/client/jni/jni_client.h
new file mode 100644
index 0000000..56c6bc1
--- /dev/null
+++ b/remoting/client/jni/jni_client.h
@@ -0,0 +1,30 @@
+// 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 REMOTING_CLIENT_JNI_JNI_CLIENT_H_
+#define REMOTING_CLIENT_JNI_JNI_CLIENT_H_
+
+#include <jni.h>
+
+#include "base/macros.h"
+
+namespace remoting {
+
+class JniClient {
+ public:
+ JniClient();
+ ~JniClient();
+
+ // Register C++ methods exposed to Java using JNI.
+ static bool RegisterJni(JNIEnv* env);
+
+ void Destroy(JNIEnv* env, jobject caller);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(JniClient);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_
diff --git a/remoting/client/jni/chromoting_jni_onload.cc b/remoting/client/jni/remoting_jni_onload.cc
index 53e7420..b539747 100644
--- a/remoting/client/jni/chromoting_jni_onload.cc
+++ b/remoting/client/jni/remoting_jni_onload.cc
@@ -7,8 +7,9 @@
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "base/android/jni_utils.h"
+#include "base/bind.h"
#include "net/android/net_jni_registrar.h"
-#include "remoting/client/jni/chromoting_jni_runtime.h"
+#include "remoting/client/jni/remoting_jni_registrar.h"
#include "ui/gfx/android/gfx_jni_registrar.h"
namespace {
diff --git a/remoting/client/jni/remoting_jni_registrar.cc b/remoting/client/jni/remoting_jni_registrar.cc
new file mode 100644
index 0000000..b1be442
--- /dev/null
+++ b/remoting/client/jni/remoting_jni_registrar.cc
@@ -0,0 +1,28 @@
+// 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.
+
+
+#include "remoting/client/jni/remoting_jni_registrar.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_registrar.h"
+#include "base/macros.h"
+#include "remoting/client/jni/chromoting_jni_runtime.h"
+#include "remoting/client/jni/jni_client.h"
+
+namespace remoting {
+
+namespace {
+const base::android::RegistrationMethod kRemotingRegisteredMethods[] = {
+ {"JniClient", JniClient::RegisterJni},
+ {"ChromotingJniRuntime", RegisterChromotingJniRuntime}
+};
+} // namespace
+
+bool RegisterJni(JNIEnv* env) {
+ return RegisterNativeMethods(env, kRemotingRegisteredMethods,
+ arraysize(kRemotingRegisteredMethods));
+}
+
+} // namespace remoting
diff --git a/remoting/client/jni/remoting_jni_registrar.h b/remoting/client/jni/remoting_jni_registrar.h
new file mode 100644
index 0000000..e301fbe
--- /dev/null
+++ b/remoting/client/jni/remoting_jni_registrar.h
@@ -0,0 +1,17 @@
+// 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 REMOTING_CLIENT_JNI_REMOTING_JNI_REGISTRAR_H_
+#define REMOTING_CLIENT_JNI_REMOTING_JNI_REGISTRAR_H_
+
+#include <jni.h>
+
+namespace remoting {
+
+// Register all JNI bindings necessary for remoting.
+bool RegisterJni(JNIEnv* env);
+
+} // namespace remoting
+
+#endif // REMOTING_CLIENT_JNI_REMOTING_JNI_REGISTRAR_H_
diff --git a/remoting/remoting_android.gypi b/remoting/remoting_android.gypi
index c05119d..061465c 100644
--- a/remoting/remoting_android.gypi
+++ b/remoting/remoting_android.gypi
@@ -10,6 +10,7 @@
'target_name': 'remoting_jni_headers',
'type': 'none',
'sources': [
+ 'android/java/src/org/chromium/chromoting/jni/Client.java',
'android/java/src/org/chromium/chromoting/jni/JniInterface.java',
],
'variables': {
@@ -33,11 +34,15 @@
'client/jni/android_keymap.h',
'client/jni/chromoting_jni_instance.cc',
'client/jni/chromoting_jni_instance.h',
- 'client/jni/chromoting_jni_onload.cc',
'client/jni/chromoting_jni_runtime.cc',
'client/jni/chromoting_jni_runtime.h',
+ 'client/jni/jni_client.cc',
+ 'client/jni/jni_client.h',
'client/jni/jni_frame_consumer.cc',
'client/jni/jni_frame_consumer.h',
+ 'client/jni/remoting_jni_onload.cc',
+ 'client/jni/remoting_jni_registrar.cc',
+ 'client/jni/remoting_jni_registrar.h',
],
}, # end of target 'remoting_client_jni'
{