Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/client/jni/chromoting_jni_instance.h" | |
| 6 | |
| 7 #include "base/android/base_jni_registrar.h" | |
| 8 #include "base/android/jni_android.h" | |
| 9 #include "base/bind.h" | |
| 10 #include "base/bind_helpers.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/memory/singleton.h" | |
| 13 #include "net/android/net_jni_registrar.h" | |
| 14 #include "remoting/base/url_request_context.h" | |
| 15 | |
| 16 namespace remoting { | |
| 17 | |
| 18 ChromotingJNIInstance* ChromotingJNIInstance::GetInstance() { | |
| 19 return Singleton<ChromotingJNIInstance>::get(); | |
| 20 } | |
| 21 | |
| 22 // For now, this just gives us access to the strings supplied from Java. | |
| 23 void ChromotingJNIInstance::ConnectToHost(jstring username, | |
| 24 jstring auth_token, | |
| 25 jstring host_jid, | |
| 26 jstring host_id, | |
| 27 jstring host_pubkey) { | |
| 28 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 29 | |
| 30 username_jstr_ = static_cast<jstring>(env->NewGlobalRef(username)); | |
| 31 auth_token_jstr_ = static_cast<jstring>(env->NewGlobalRef(auth_token)); | |
| 32 host_jid_jstr_ = static_cast<jstring>(env->NewGlobalRef(host_jid)); | |
| 33 host_id_jstr_ = static_cast<jstring>(env->NewGlobalRef(host_id)); | |
| 34 host_pubkey_jstr_ = static_cast<jstring>(env->NewGlobalRef(host_pubkey)); | |
| 35 | |
| 36 username_cstr_ = env->GetStringUTFChars(username_jstr_, NULL); | |
| 37 auth_token_cstr_ = env->GetStringUTFChars(auth_token_jstr_, NULL); | |
| 38 host_jid_cstr_ = env->GetStringUTFChars(host_jid_jstr_, NULL); | |
| 39 host_id_cstr_ = env->GetStringUTFChars(host_id_jstr_, NULL); | |
| 40 host_pubkey_cstr_ = env->GetStringUTFChars(host_pubkey_jstr_, NULL); | |
| 41 | |
| 42 // TODO(solb) Initiate connection from here. | |
| 43 } | |
| 44 | |
| 45 // For the moment, this only releases the Java string references. | |
| 46 void ChromotingJNIInstance::DisconnectFromHost() { | |
| 47 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 48 | |
| 49 env->ReleaseStringUTFChars(username_jstr_, username_cstr_); | |
| 50 env->ReleaseStringUTFChars(auth_token_jstr_, auth_token_cstr_); | |
| 51 env->ReleaseStringUTFChars(host_jid_jstr_, host_jid_cstr_); | |
| 52 env->ReleaseStringUTFChars(host_id_jstr_, host_id_cstr_); | |
| 53 env->ReleaseStringUTFChars(host_pubkey_jstr_, host_pubkey_cstr_); | |
| 54 | |
| 55 username_cstr_ = NULL; | |
| 56 auth_token_cstr_ = NULL; | |
| 57 host_jid_cstr_ = NULL; | |
| 58 host_id_cstr_ = NULL; | |
| 59 host_pubkey_cstr_ = NULL; | |
| 60 | |
| 61 env->DeleteGlobalRef(username_jstr_); | |
| 62 env->DeleteGlobalRef(auth_token_jstr_); | |
| 63 env->DeleteGlobalRef(host_jid_jstr_); | |
| 64 env->DeleteGlobalRef(host_id_jstr_); | |
| 65 env->DeleteGlobalRef(host_pubkey_jstr_); | |
| 66 } | |
| 67 | |
| 68 void ChromotingJNIInstance::OnConnectionState( | |
| 69 protocol::ConnectionToHost::State state, | |
| 70 protocol::ErrorCode error) {} | |
| 71 | |
| 72 void ChromotingJNIInstance::OnConnectionReady(bool ready) {} | |
| 73 | |
| 74 void ChromotingJNIInstance::SetCapabilities(const std::string& capabilities) {} | |
| 75 | |
| 76 void ChromotingJNIInstance::SetPairingResponse( | |
| 77 const protocol::PairingResponse& response) {} | |
| 78 | |
| 79 protocol::ClipboardStub* ChromotingJNIInstance::GetClipboardStub() { | |
| 80 NOTIMPLEMENTED(); | |
| 81 return NULL; | |
| 82 } | |
| 83 | |
| 84 protocol::CursorShapeStub* ChromotingJNIInstance::GetCursorShapeStub() { | |
| 85 NOTIMPLEMENTED(); | |
| 86 return NULL; | |
| 87 } | |
| 88 | |
| 89 // We don't use NOTIMPLEMENTED() here because NegotiatingClientAuthenticator | |
| 90 // calls this even if it doesn't use the configuration method, and we don't | |
| 91 // want to print an error on every run. | |
| 92 scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> | |
| 93 ChromotingJNIInstance::GetTokenFetcher(const std::string& host_public_key) { | |
| 94 LOG(INFO) << "ChromotingJNIInstance::GetTokenFetcher(...) [unimplemented]"; | |
| 95 return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>(); | |
| 96 } | |
| 97 | |
| 98 // This currently only spins up the threads. | |
| 99 ChromotingJNIInstance::ChromotingJNIInstance() | |
| 100 : username_cstr_(NULL), | |
| 101 auth_token_cstr_(NULL), | |
| 102 host_jid_cstr_(NULL), | |
| 103 host_id_cstr_(NULL), | |
| 104 host_pubkey_cstr_(NULL), | |
| 105 pin_cstr_(NULL) { | |
| 106 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 107 | |
| 108 collector_.reset(new base::AtExitManager()); | |
| 109 base::android::RegisterJni(env); | |
| 110 net::android::RegisterJni(env); | |
| 111 | |
| 112 LOG(INFO) << "starting main message loop"; | |
| 113 ui_loop_.reset(new base::MessageLoopForUI()); | |
| 114 ui_loop_->Start(); | |
| 115 | |
| 116 LOG(INFO) << "spawning additional threads"; | |
| 117 ui_runner_ = new AutoThreadTaskRunner(ui_loop_->message_loop_proxy(), | |
| 118 base::MessageLoop::QuitClosure()); | |
| 119 net_runner_ = AutoThread::CreateWithType("native_net", | |
| 120 ui_runner_, | |
| 121 base::MessageLoop::TYPE_IO); | |
| 122 disp_runner_ = AutoThread::CreateWithType("native_disp", | |
| 123 ui_runner_, | |
| 124 base::MessageLoop::TYPE_DEFAULT); | |
| 125 | |
| 126 url_requester_ = new URLRequestContextGetter(ui_runner_, net_runner_); | |
| 127 | |
| 128 class_ = static_cast<jclass>(env->NewGlobalRef(env->FindClass(JAVA_CLASS))); | |
| 129 } | |
| 130 | |
| 131 ChromotingJNIInstance::~ChromotingJNIInstance() { | |
| 132 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 133 env->DeleteGlobalRef(class_); // TODO(solb) detach all threads from JVM | |
|
garykac
2013/07/10 21:56:18
Is this TODO really associated with the code on th
solb
2013/07/10 22:11:57
Done.
| |
| 134 } | |
| 135 | |
| 136 } // namespace remoting | |
| OLD | NEW |