| 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/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/library_loader/library_loader_hooks.h" |
| 10 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 16 #include "google_apis/google_api_keys.h" | 17 #include "google_apis/google_api_keys.h" |
| 17 #include "jni/JniInterface_jni.h" | 18 #include "jni/JniInterface_jni.h" |
| 18 #include "media/base/yuv_convert.h" | 19 #include "media/base/yuv_convert.h" |
| 19 #include "remoting/base/url_request_context_getter.h" | 20 #include "remoting/base/url_request_context_getter.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 176 } |
| 176 | 177 |
| 177 // ChromotingJniRuntime implementation. | 178 // ChromotingJniRuntime implementation. |
| 178 | 179 |
| 179 // static | 180 // static |
| 180 ChromotingJniRuntime* ChromotingJniRuntime::GetInstance() { | 181 ChromotingJniRuntime* ChromotingJniRuntime::GetInstance() { |
| 181 return Singleton<ChromotingJniRuntime>::get(); | 182 return Singleton<ChromotingJniRuntime>::get(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 ChromotingJniRuntime::ChromotingJniRuntime() { | 185 ChromotingJniRuntime::ChromotingJniRuntime() { |
| 185 at_exit_manager_.reset(new base::AtExitManager()); | |
| 186 | |
| 187 // On Android, the UI thread is managed by Java, so we need to attach and | 186 // On Android, the UI thread is managed by Java, so we need to attach and |
| 188 // start a special type of message loop to allow Chromium code to run tasks. | 187 // start a special type of message loop to allow Chromium code to run tasks. |
| 189 ui_loop_.reset(new base::MessageLoopForUI()); | 188 ui_loop_.reset(new base::MessageLoopForUI()); |
| 190 ui_loop_->Start(); | 189 ui_loop_->Start(); |
| 191 | 190 |
| 192 // TODO(solb) Stop pretending to control the managed UI thread's lifetime. | 191 // TODO(solb) Stop pretending to control the managed UI thread's lifetime. |
| 193 ui_task_runner_ = new AutoThreadTaskRunner(ui_loop_->message_loop_proxy(), | 192 ui_task_runner_ = new AutoThreadTaskRunner(ui_loop_->message_loop_proxy(), |
| 194 base::MessageLoop::QuitClosure()); | 193 base::MessageLoop::QuitClosure()); |
| 195 network_task_runner_ = AutoThread::CreateWithType("native_net", | 194 network_task_runner_ = AutoThread::CreateWithType("native_net", |
| 196 ui_task_runner_, | 195 ui_task_runner_, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 217 network_task_runner_->PostTask(FROM_HERE, base::Bind( | 216 network_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 218 &ChromotingJniRuntime::DetachFromVmAndSignal, | 217 &ChromotingJniRuntime::DetachFromVmAndSignal, |
| 219 base::Unretained(this), | 218 base::Unretained(this), |
| 220 &done_event)); | 219 &done_event)); |
| 221 done_event.Wait(); | 220 done_event.Wait(); |
| 222 display_task_runner_->PostTask(FROM_HERE, base::Bind( | 221 display_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 223 &ChromotingJniRuntime::DetachFromVmAndSignal, | 222 &ChromotingJniRuntime::DetachFromVmAndSignal, |
| 224 base::Unretained(this), | 223 base::Unretained(this), |
| 225 &done_event)); | 224 &done_event)); |
| 226 done_event.Wait(); | 225 done_event.Wait(); |
| 226 base::android::LibraryLoaderExitHook(); |
| 227 base::android::DetachFromVM(); | 227 base::android::DetachFromVM(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void ChromotingJniRuntime::ConnectToHost(const char* username, | 230 void ChromotingJniRuntime::ConnectToHost(const char* username, |
| 231 const char* auth_token, | 231 const char* auth_token, |
| 232 const char* host_jid, | 232 const char* host_jid, |
| 233 const char* host_id, | 233 const char* host_id, |
| 234 const char* host_pubkey, | 234 const char* host_pubkey, |
| 235 const char* pairing_id, | 235 const char* pairing_id, |
| 236 const char* pairing_secret, | 236 const char* pairing_secret, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 364 |
| 365 JNIEnv* env = base::android::AttachCurrentThread(); | 365 JNIEnv* env = base::android::AttachCurrentThread(); |
| 366 Java_JniInterface_redrawGraphicsInternal(env); | 366 Java_JniInterface_redrawGraphicsInternal(env); |
| 367 } | 367 } |
| 368 | 368 |
| 369 void ChromotingJniRuntime::DetachFromVmAndSignal(base::WaitableEvent* waiter) { | 369 void ChromotingJniRuntime::DetachFromVmAndSignal(base::WaitableEvent* waiter) { |
| 370 base::android::DetachFromVM(); | 370 base::android::DetachFromVM(); |
| 371 waiter->Signal(); | 371 waiter->Signal(); |
| 372 } | 372 } |
| 373 } // namespace remoting | 373 } // namespace remoting |
| OLD | NEW |