| 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_runtime.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 kJavaClass = "org/chromium/chromoting/jni/JniInterface"; | 
| 16 | 16 | 
| 17 namespace remoting { | 17 namespace remoting { | 
| 18 | 18 | 
| 19 // static | 19 // static | 
| 20 ChromotingJniRuntime* ChromotingJniRuntime::GetInstance() { | 20 ChromotingJniRuntime* ChromotingJniRuntime::GetInstance() { | 
| 21   return Singleton<ChromotingJniRuntime>::get(); | 21   return Singleton<ChromotingJniRuntime>::get(); | 
| 22 } | 22 } | 
| 23 | 23 | 
| 24 ChromotingJniRuntime::ChromotingJniRuntime() { | 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 | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 48                                                     base::MessageLoop::TYPE_IO); | 48                                                     base::MessageLoop::TYPE_IO); | 
| 49   display_task_runner_ = AutoThread::Create("native_disp", | 49   display_task_runner_ = AutoThread::Create("native_disp", | 
| 50                                             ui_task_runner_); | 50                                             ui_task_runner_); | 
| 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(kJavaClass))); | 
| 59 } | 59 } | 
| 60 | 60 | 
| 61 ChromotingJniRuntime::~ChromotingJniRuntime() { | 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): Detach all threads from JVM here. | 
|  | 72   // crbug.com/259594 | 
| 72 } | 73 } | 
| 73 | 74 | 
| 74 void ChromotingJniRuntime::ConnectToHost(const char* username, | 75 void ChromotingJniRuntime::ConnectToHost(const char* username, | 
| 75                                   const char* auth_token, | 76                                   const char* auth_token, | 
| 76                                   const char* host_jid, | 77                                   const char* host_jid, | 
| 77                                   const char* host_id, | 78                                   const char* host_id, | 
| 78                                   const char* host_pubkey) { | 79                                   const char* host_pubkey) { | 
| 79   DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 80   DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 
| 80   DCHECK(!session_); | 81   DCHECK(!session_); | 
| 81   session_ = new ChromotingJniInstance(this, | 82   session_ = new ChromotingJniInstance(this, | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 139 void ChromotingJniRuntime::RedrawCanvas() { | 140 void ChromotingJniRuntime::RedrawCanvas() { | 
| 140   DCHECK(display_task_runner_->BelongsToCurrentThread()); | 141   DCHECK(display_task_runner_->BelongsToCurrentThread()); | 
| 141 | 142 | 
| 142   JNIEnv* env = base::android::AttachCurrentThread(); | 143   JNIEnv* env = base::android::AttachCurrentThread(); | 
| 143   env->CallStaticVoidMethod( | 144   env->CallStaticVoidMethod( | 
| 144       class_, | 145       class_, | 
| 145       env->GetStaticMethodID(class_, "redrawGraphicsInternal", "()V")); | 146       env->GetStaticMethodID(class_, "redrawGraphicsInternal", "()V")); | 
| 146 } | 147 } | 
| 147 | 148 | 
| 148 }  // namespace remoting | 149 }  // namespace remoting | 
| OLD | NEW | 
|---|