OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/client/jni/chromoting_jni.h" | 5 #include "remoting/client/jni/chromoting_jni_runtime.h" |
6 | 6 |
7 #include "base/android/base_jni_registrar.h" | 7 #include "base/android/base_jni_registrar.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "media/base/yuv_convert.h" | 10 #include "media/base/yuv_convert.h" |
11 #include "net/android/net_jni_registrar.h" | 11 #include "net/android/net_jni_registrar.h" |
12 #include "remoting/base/url_request_context.h" | 12 #include "remoting/base/url_request_context.h" |
13 | 13 |
14 // Class and package name of the Java class supporting the methods we call. | 14 // Class and package name of the Java class supporting the methods we call. |
15 const char* const JAVA_CLASS = "org/chromium/chromoting/jni/JniInterface"; | 15 const char* const JAVA_CLASS = "org/chromium/chromoting/jni/JniInterface"; |
16 | 16 |
17 namespace remoting { | 17 namespace remoting { |
18 | 18 |
19 // static | 19 // static |
20 ChromotingJni* ChromotingJni::GetInstance() { | 20 ChromotingJniRuntime* ChromotingJniRuntime::GetInstance() { |
21 return Singleton<ChromotingJni>::get(); | 21 return Singleton<ChromotingJniRuntime>::get(); |
22 } | 22 } |
23 | 23 |
24 ChromotingJni::ChromotingJni() { | 24 ChromotingJniRuntime::ChromotingJniRuntime() { |
25 // Obtain a reference to the Java environment. (Future calls to this function | 25 // Obtain a reference to the Java environment. (Future calls to this function |
26 // made from the same thread return the same stored reference instead of | 26 // made from the same thread return the same stored reference instead of |
27 // repeating the work of attaching to the JVM.) | 27 // repeating the work of attaching to the JVM.) |
28 JNIEnv* env = base::android::AttachCurrentThread(); | 28 JNIEnv* env = base::android::AttachCurrentThread(); |
29 | 29 |
30 // The base and networks stacks must be registered with JNI in order to work | 30 // The base and networks stacks must be registered with JNI in order to work |
31 // on Android. An AtExitManager cleans this up at process exit. | 31 // on Android. An AtExitManager cleans this up at process exit. |
32 at_exit_manager_.reset(new base::AtExitManager()); | 32 at_exit_manager_.reset(new base::AtExitManager()); |
33 base::android::RegisterJni(env); | 33 base::android::RegisterJni(env); |
34 net::android::RegisterJni(env); | 34 net::android::RegisterJni(env); |
(...skipping 16 matching lines...) Expand all Loading... |
51 | 51 |
52 url_requester_ = new URLRequestContextGetter(ui_task_runner_, | 52 url_requester_ = new URLRequestContextGetter(ui_task_runner_, |
53 network_task_runner_); | 53 network_task_runner_); |
54 | 54 |
55 // Allows later decoding of video frames. | 55 // Allows later decoding of video frames. |
56 media::InitializeCPUSpecificYUVConversions(); | 56 media::InitializeCPUSpecificYUVConversions(); |
57 | 57 |
58 class_ = static_cast<jclass>(env->NewGlobalRef(env->FindClass(JAVA_CLASS))); | 58 class_ = static_cast<jclass>(env->NewGlobalRef(env->FindClass(JAVA_CLASS))); |
59 } | 59 } |
60 | 60 |
61 ChromotingJni::~ChromotingJni() { | 61 ChromotingJniRuntime::~ChromotingJniRuntime() { |
62 // The singleton should only ever be destroyed on the main thread. | 62 // The singleton should only ever be destroyed on the main thread. |
63 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 63 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
64 | 64 |
65 // The session must be shut down first, since it depends on our other | 65 // The session must be shut down first, since it depends on our other |
66 // components' still being alive. | 66 // components' still being alive. |
67 DisconnectFromHost(); | 67 DisconnectFromHost(); |
68 | 68 |
69 JNIEnv* env = base::android::AttachCurrentThread(); | 69 JNIEnv* env = base::android::AttachCurrentThread(); |
70 env->DeleteGlobalRef(class_); | 70 env->DeleteGlobalRef(class_); |
71 // TODO(solb): crbug.com/259594 Detach all threads from JVM here. | 71 // TODO(solb): crbug.com/259594 Detach all threads from JVM here. |
72 } | 72 } |
73 | 73 |
74 void ChromotingJni::ConnectToHost(const char* username, | 74 void ChromotingJniRuntime::ConnectToHost(const char* username, |
75 const char* auth_token, | 75 const char* auth_token, |
76 const char* host_jid, | 76 const char* host_jid, |
77 const char* host_id, | 77 const char* host_id, |
78 const char* host_pubkey) { | 78 const char* host_pubkey) { |
79 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 79 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
80 DCHECK(!session_); | 80 DCHECK(!session_); |
81 session_ = new ChromotingJniInstance(username, | 81 session_ = new ChromotingJniInstance(this, |
| 82 username, |
82 auth_token, | 83 auth_token, |
83 host_jid, | 84 host_jid, |
84 host_id, | 85 host_id, |
85 host_pubkey); | 86 host_pubkey); |
86 } | 87 } |
87 | 88 |
88 void ChromotingJni::DisconnectFromHost() { | 89 void ChromotingJniRuntime::DisconnectFromHost() { |
89 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 90 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
90 if (session_) { | 91 if (session_) { |
91 session_->Cleanup(); | 92 session_->Cleanup(); |
92 session_ = NULL; | 93 session_ = NULL; |
93 } | 94 } |
94 } | 95 } |
95 | 96 |
96 void ChromotingJni::ReportConnectionStatus( | 97 void ChromotingJniRuntime::ReportConnectionStatus( |
97 protocol::ConnectionToHost::State state, | 98 protocol::ConnectionToHost::State state, |
98 protocol::ErrorCode error) { | 99 protocol::ErrorCode error) { |
99 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 100 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
100 | 101 |
101 JNIEnv* env = base::android::AttachCurrentThread(); | 102 JNIEnv* env = base::android::AttachCurrentThread(); |
102 env->CallStaticVoidMethod( | 103 env->CallStaticVoidMethod( |
103 class_, | 104 class_, |
104 env->GetStaticMethodID(class_, "reportConnectionStatus", "(II)V"), | 105 env->GetStaticMethodID(class_, "reportConnectionStatus", "(II)V"), |
105 state, | 106 state, |
106 error); | 107 error); |
107 } | 108 } |
108 | 109 |
109 void ChromotingJni::DisplayAuthenticationPrompt() { | 110 void ChromotingJniRuntime::DisplayAuthenticationPrompt() { |
110 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 111 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
111 | 112 |
112 JNIEnv* env = base::android::AttachCurrentThread(); | 113 JNIEnv* env = base::android::AttachCurrentThread(); |
113 env->CallStaticVoidMethod( | 114 env->CallStaticVoidMethod( |
114 class_, | 115 class_, |
115 env->GetStaticMethodID(class_, "displayAuthenticationPrompt", "()V")); | 116 env->GetStaticMethodID(class_, "displayAuthenticationPrompt", "()V")); |
116 } | 117 } |
117 | 118 |
118 void ChromotingJni::UpdateImageBuffer(int width, int height, jobject buffer) { | 119 void ChromotingJniRuntime::UpdateImageBuffer(int width, |
| 120 int height, |
| 121 jobject buffer) { |
119 DCHECK(display_task_runner_->BelongsToCurrentThread()); | 122 DCHECK(display_task_runner_->BelongsToCurrentThread()); |
120 | 123 |
121 JNIEnv* env = base::android::AttachCurrentThread(); | 124 JNIEnv* env = base::android::AttachCurrentThread(); |
122 env->SetStaticIntField( | 125 env->SetStaticIntField( |
123 class_, | 126 class_, |
124 env->GetStaticFieldID(class_, "sWidth", "I"), | 127 env->GetStaticFieldID(class_, "sWidth", "I"), |
125 width); | 128 width); |
126 env->SetStaticIntField( | 129 env->SetStaticIntField( |
127 class_, | 130 class_, |
128 env->GetStaticFieldID(class_, "sHeight", "I"), | 131 env->GetStaticFieldID(class_, "sHeight", "I"), |
129 height); | 132 height); |
130 env->SetStaticObjectField( | 133 env->SetStaticObjectField( |
131 class_, | 134 class_, |
132 env->GetStaticFieldID(class_, "sBuffer", "Ljava/nio/ByteBuffer;"), | 135 env->GetStaticFieldID(class_, "sBuffer", "Ljava/nio/ByteBuffer;"), |
133 buffer); | 136 buffer); |
134 } | 137 } |
135 | 138 |
136 void ChromotingJni::RedrawCanvas() { | 139 void ChromotingJniRuntime::RedrawCanvas() { |
137 DCHECK(display_task_runner_->BelongsToCurrentThread()); | 140 DCHECK(display_task_runner_->BelongsToCurrentThread()); |
138 | 141 |
139 JNIEnv* env = base::android::AttachCurrentThread(); | 142 JNIEnv* env = base::android::AttachCurrentThread(); |
140 env->CallStaticVoidMethod( | 143 env->CallStaticVoidMethod( |
141 class_, | 144 class_, |
142 env->GetStaticMethodID(class_, "redrawGraphicsInternal", "()V")); | 145 env->GetStaticMethodID(class_, "redrawGraphicsInternal", "()V")); |
143 } | 146 } |
144 | 147 |
145 } // namespace remoting | 148 } // namespace remoting |
OLD | NEW |