Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: remoting/client/jni/jni_client.cc

Issue 2753963002: Refactoring and rewriting the chromoting jni instance to be chromoting session. (Closed)
Patch Set: JNI client is the session delegate. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/client/jni/jni_client.h ('k') | remoting/client/jni/jni_runtime_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/jni_client.h" 5 #include "remoting/client/jni/jni_client.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "jni/Client_jni.h" 10 #include "jni/Client_jni.h"
11 #include "remoting/client/audio_player_android.h"
11 #include "remoting/client/chromoting_client_runtime.h" 12 #include "remoting/client/chromoting_client_runtime.h"
12 #include "remoting/client/jni/chromoting_jni_instance.h" 13 #include "remoting/client/chromoting_session.h"
13 #include "remoting/client/jni/connect_to_host_info.h" 14 #include "remoting/client/connect_to_host_info.h"
14 #include "remoting/client/jni/jni_gl_display_handler.h" 15 #include "remoting/client/jni/jni_gl_display_handler.h"
15 #include "remoting/client/jni/jni_pairing_secret_fetcher.h" 16 #include "remoting/client/jni/jni_pairing_secret_fetcher.h"
17 #include "remoting/client/jni/jni_runtime_delegate.h"
16 #include "remoting/client/jni/jni_touch_event_data.h" 18 #include "remoting/client/jni/jni_touch_event_data.h"
17 #include "remoting/protocol/video_renderer.h" 19 #include "remoting/protocol/video_renderer.h"
18 20
19 using base::android::ConvertJavaStringToUTF8; 21 using base::android::ConvertJavaStringToUTF8;
20 using base::android::ConvertUTF8ToJavaString; 22 using base::android::ConvertUTF8ToJavaString;
21 using base::android::JavaParamRef; 23 using base::android::JavaParamRef;
22 using base::android::ScopedJavaLocalRef; 24 using base::android::ScopedJavaLocalRef;
23 25
24 namespace remoting { 26 namespace remoting {
25 27
26 JniClient::JniClient(base::android::ScopedJavaGlobalRef<jobject> java_client) 28 JniClient::JniClient(base::android::ScopedJavaGlobalRef<jobject> java_client)
27 : java_client_(java_client), weak_factory_(this) { 29 : java_client_(java_client), weak_factory_(this) {
28 runtime_ = ChromotingClientRuntime::GetInstance(); 30 runtime_ = ChromotingClientRuntime::GetInstance();
29 weak_ptr_ = weak_factory_.GetWeakPtr(); 31 weak_ptr_ = weak_factory_.GetWeakPtr();
30 } 32 }
31 33
32 JniClient::~JniClient() { 34 JniClient::~JniClient() {
33 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); 35 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
34 36
35 // The session must be shut down first, since it depends on our other 37 // The session must be shut down first, since it depends on our other
36 // components' still being alive. 38 // components' still being alive.
37 DisconnectFromHost(); 39 DisconnectFromHost();
38 } 40 }
39 41
40 void JniClient::ConnectToHost(const ConnectToHostInfo& info) { 42 void JniClient::ConnectToHost(const ConnectToHostInfo& info) {
41 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); 43 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
42 DCHECK(!display_handler_); 44 DCHECK(!display_handler_);
45 DCHECK(!audio_player_);
43 DCHECK(!session_); 46 DCHECK(!session_);
44 DCHECK(!secret_fetcher_); 47 DCHECK(!secret_fetcher_);
45 display_handler_.reset(new JniGlDisplayHandler(java_client_)); 48 display_handler_.reset(new JniGlDisplayHandler(java_client_));
46 secret_fetcher_.reset( 49 secret_fetcher_.reset(
47 new JniPairingSecretFetcher(GetWeakPtr(), info.host_id)); 50 new JniPairingSecretFetcher(GetWeakPtr(), info.host_id));
48 session_.reset( 51
49 new ChromotingJniInstance(GetWeakPtr(), secret_fetcher_->GetWeakPtr(), 52 protocol::ClientAuthenticationConfig client_auth_config;
50 display_handler_->CreateCursorShapeStub(), 53 client_auth_config.host_id = info.host_id;
51 display_handler_->CreateVideoRenderer(), info)); 54 client_auth_config.pairing_client_id = info.pairing_id;
55 client_auth_config.pairing_secret = info.pairing_secret;
56 client_auth_config.fetch_secret_callback = base::Bind(
57 &JniPairingSecretFetcher::FetchSecret, secret_fetcher_->GetWeakPtr());
58
59 audio_player_.reset(new AudioPlayerAndroid());
60
61 session_.reset(new ChromotingSession(
62 weak_ptr_, display_handler_->CreateCursorShapeStub(),
63 display_handler_->CreateVideoRenderer(), audio_player_->GetWeakPtr(),
64 info, client_auth_config));
52 session_->Connect(); 65 session_->Connect();
53 } 66 }
54 67
55 void JniClient::DisconnectFromHost() { 68 void JniClient::DisconnectFromHost() {
56 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); 69 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
57 if (session_) { 70 if (session_) {
58 session_->Disconnect(); 71 session_->Disconnect();
59 runtime_->network_task_runner()->DeleteSoon(FROM_HERE, 72 runtime_->network_task_runner()->DeleteSoon(FROM_HERE,
60 session_.release()); 73 session_.release());
61 } 74 }
62 if (secret_fetcher_) { 75 if (secret_fetcher_) {
63 runtime_->network_task_runner()->DeleteSoon(FROM_HERE, 76 runtime_->network_task_runner()->DeleteSoon(FROM_HERE,
64 secret_fetcher_.release()); 77 secret_fetcher_.release());
65 } 78 }
66 display_handler_.reset(); 79 display_handler_.reset();
80 audio_player_.reset();
Yuwei 2017/03/30 21:18:56 You will need to delete audio_player_ on the netwo
67 } 81 }
68 82
69 void JniClient::OnConnectionState(protocol::ConnectionToHost::State state, 83 void JniClient::OnConnectionState(protocol::ConnectionToHost::State state,
70 protocol::ErrorCode error) { 84 protocol::ErrorCode error) {
71 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread()); 85 DCHECK(runtime_->ui_task_runner()->BelongsToCurrentThread());
72 86
73 JNIEnv* env = base::android::AttachCurrentThread(); 87 JNIEnv* env = base::android::AttachCurrentThread();
74 Java_Client_onConnectionState(env, java_client_, state, error); 88 Java_Client_onConnectionState(env, java_client_, state, error);
75 } 89 }
76 90
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 info.host_jid = ConvertJavaStringToUTF8(env, host_jid); 171 info.host_jid = ConvertJavaStringToUTF8(env, host_jid);
158 info.host_id = ConvertJavaStringToUTF8(env, host_id); 172 info.host_id = ConvertJavaStringToUTF8(env, host_id);
159 info.host_pubkey = ConvertJavaStringToUTF8(env, host_pubkey); 173 info.host_pubkey = ConvertJavaStringToUTF8(env, host_pubkey);
160 info.pairing_id = ConvertJavaStringToUTF8(env, pair_id); 174 info.pairing_id = ConvertJavaStringToUTF8(env, pair_id);
161 info.pairing_secret = ConvertJavaStringToUTF8(env, pair_secret); 175 info.pairing_secret = ConvertJavaStringToUTF8(env, pair_secret);
162 info.capabilities = ConvertJavaStringToUTF8(env, capabilities); 176 info.capabilities = ConvertJavaStringToUTF8(env, capabilities);
163 info.flags = ConvertJavaStringToUTF8(env, flags); 177 info.flags = ConvertJavaStringToUTF8(env, flags);
164 info.host_version = ConvertJavaStringToUTF8(env, host_version); 178 info.host_version = ConvertJavaStringToUTF8(env, host_version);
165 info.host_os = ConvertJavaStringToUTF8(env, host_os); 179 info.host_os = ConvertJavaStringToUTF8(env, host_os);
166 info.host_os_version = ConvertJavaStringToUTF8(env, host_os_version); 180 info.host_os_version = ConvertJavaStringToUTF8(env, host_os_version);
181
167 ConnectToHost(info); 182 ConnectToHost(info);
168 } 183 }
169 184
170 void JniClient::Disconnect(JNIEnv* env, 185 void JniClient::Disconnect(JNIEnv* env,
171 const base::android::JavaParamRef<jobject>& caller) { 186 const base::android::JavaParamRef<jobject>& caller) {
172 DisconnectFromHost(); 187 DisconnectFromHost();
173 } 188 }
174 189
175 void JniClient::AuthenticationResponse( 190 void JniClient::AuthenticationResponse(
176 JNIEnv* env, 191 JNIEnv* env,
177 const JavaParamRef<jobject>& caller, 192 const JavaParamRef<jobject>& caller,
178 const JavaParamRef<jstring>& pin, 193 const JavaParamRef<jstring>& pin,
179 jboolean createPair, 194 jboolean createPair,
180 const JavaParamRef<jstring>& deviceName) { 195 const JavaParamRef<jstring>& deviceName) {
181 session_->ProvideSecret(ConvertJavaStringToUTF8(env, pin), createPair, 196 if (session_) {
182 ConvertJavaStringToUTF8(env, deviceName)); 197 session_->ProvideSecret(ConvertJavaStringToUTF8(env, pin), createPair,
198 ConvertJavaStringToUTF8(env, deviceName));
199 }
200
201 if (secret_fetcher_) {
202 runtime_->network_task_runner()->PostTask(
203 FROM_HERE, base::Bind(&JniPairingSecretFetcher::ProvideSecret,
204 secret_fetcher_->GetWeakPtr(),
205 ConvertJavaStringToUTF8(env, pin)));
206 }
183 } 207 }
184 208
185 void JniClient::SendMouseEvent( 209 void JniClient::SendMouseEvent(
186 JNIEnv* env, 210 JNIEnv* env,
187 const base::android::JavaParamRef<jobject>& caller, 211 const base::android::JavaParamRef<jobject>& caller,
188 jint x, 212 jint x,
189 jint y, 213 jint y,
190 jint whichButton, 214 jint whichButton,
191 jboolean buttonDown) { 215 jboolean buttonDown) {
192 // Button must be within the bounds of the MouseEvent_MouseButton enum. 216 // Button must be within the bounds of the MouseEvent_MouseButton enum.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 session_->EnableVideoChannel(enable); 278 session_->EnableVideoChannel(enable);
255 } 279 }
256 280
257 void JniClient::OnThirdPartyTokenFetched( 281 void JniClient::OnThirdPartyTokenFetched(
258 JNIEnv* env, 282 JNIEnv* env,
259 const base::android::JavaParamRef<jobject>& caller, 283 const base::android::JavaParamRef<jobject>& caller,
260 const JavaParamRef<jstring>& token, 284 const JavaParamRef<jstring>& token,
261 const JavaParamRef<jstring>& shared_secret) { 285 const JavaParamRef<jstring>& shared_secret) {
262 runtime_->network_task_runner()->PostTask( 286 runtime_->network_task_runner()->PostTask(
263 FROM_HERE, 287 FROM_HERE,
264 base::Bind(&ChromotingJniInstance::HandleOnThirdPartyTokenFetched, 288 base::Bind(&ChromotingSession::HandleOnThirdPartyTokenFetched,
265 session_->GetWeakPtr(), ConvertJavaStringToUTF8(env, token), 289 session_->GetWeakPtr(), ConvertJavaStringToUTF8(env, token),
266 ConvertJavaStringToUTF8(env, shared_secret))); 290 ConvertJavaStringToUTF8(env, shared_secret)));
267 } 291 }
268 292
269 void JniClient::SendExtensionMessage( 293 void JniClient::SendExtensionMessage(
270 JNIEnv* env, 294 JNIEnv* env,
271 const base::android::JavaParamRef<jobject>& caller, 295 const base::android::JavaParamRef<jobject>& caller,
272 const JavaParamRef<jstring>& type, 296 const JavaParamRef<jstring>& type,
273 const JavaParamRef<jstring>& data) { 297 const JavaParamRef<jstring>& data) {
274 session_->SendClientMessage(ConvertJavaStringToUTF8(env, type), 298 session_->SendClientMessage(ConvertJavaStringToUTF8(env, type),
275 ConvertJavaStringToUTF8(env, data)); 299 ConvertJavaStringToUTF8(env, data));
276 } 300 }
277 301
278 void JniClient::Destroy(JNIEnv* env, const JavaParamRef<jobject>& caller) { 302 void JniClient::Destroy(JNIEnv* env, const JavaParamRef<jobject>& caller) {
279 delete this; 303 delete this;
280 } 304 }
281 305
282 base::WeakPtr<JniClient> JniClient::GetWeakPtr() { 306 base::WeakPtr<JniClient> JniClient::GetWeakPtr() {
283 return weak_ptr_; 307 return weak_ptr_;
284 } 308 }
285 309
286 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& caller) { 310 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& caller) {
287 return reinterpret_cast<intptr_t>( 311 return reinterpret_cast<intptr_t>(
288 new JniClient(base::android::ScopedJavaGlobalRef<jobject>(env, caller))); 312 new JniClient(base::android::ScopedJavaGlobalRef<jobject>(env, caller)));
289 } 313 }
290 314
291 } // namespace remoting 315 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/jni/jni_client.h ('k') | remoting/client/jni/jni_runtime_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698