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

Unified Diff: remoting/client/jni/chromoting_jni_instance.cc

Issue 18612018: Restructure chromoting_jni_instance handling of Java strings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on top of issue 18477010 Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: remoting/client/jni/chromoting_jni_instance.cc
diff --git a/remoting/client/jni/chromoting_jni_instance.cc b/remoting/client/jni/chromoting_jni_instance.cc
index ba68da87ad202445e3851c2cd7190f8d8e918544..cb44baf894a4b9c0942e77dbde400e67e6e20323 100644
--- a/remoting/client/jni/chromoting_jni_instance.cc
+++ b/remoting/client/jni/chromoting_jni_instance.cc
@@ -22,34 +22,34 @@ ChromotingJNIInstance* ChromotingJNIInstance::GetInstance() {
return Singleton<ChromotingJNIInstance>::get();
}
-ChromotingJNIInstance::ChromotingJNIInstance()
- : username_cstr_(NULL),
- auth_token_cstr_(NULL),
- host_jid_cstr_(NULL),
- host_id_cstr_(NULL),
- host_pubkey_cstr_(NULL),
- pin_cstr_(NULL) {
+ChromotingJNIInstance::ChromotingJNIInstance() {
JNIEnv* env = base::android::AttachCurrentThread();
+ // The base and networks stacks must be registered with the JNI in order to
Wez 2013/07/11 22:32:08 nit: the JNI -> JNI
solb 2013/07/11 23:59:09 Done.
+ // work on Android. A (required) AtExitManager cleans this up at world's end.
Wez 2013/07/11 22:32:08 nit: why is (required) needed here?
solb 2013/07/11 23:59:09 Done.
collector_.reset(new base::AtExitManager());
base::android::RegisterJni(env);
net::android::RegisterJni(env);
- LOG(INFO) << "starting main message loop";
+ // On Android, the UI thread is managed by the Java side of things, so we
Wez 2013/07/11 22:32:08 nit: by the Java side of things -> by Java
solb 2013/07/11 23:59:09 Done.
+ // need to attach and start a special type of message loop in order to allow
+ // Chromium code to queue tasks there.
+ LOG(INFO) << "Starting main message loop";
ui_loop_.reset(new base::MessageLoopForUI());
ui_loop_->Start();
- LOG(INFO) << "spawning additional threads";
- ui_runner_ = new AutoThreadTaskRunner(ui_loop_->message_loop_proxy(),
+ LOG(INFO) << "Spawning additional threads";
+ ui_task_runner_ = new AutoThreadTaskRunner(ui_loop_->message_loop_proxy(),
base::MessageLoop::QuitClosure());
- net_runner_ = AutoThread::CreateWithType("native_net",
- ui_runner_,
+ network_task_runner_ = AutoThread::CreateWithType("native_net",
+ ui_task_runner_,
base::MessageLoop::TYPE_IO);
- disp_runner_ = AutoThread::CreateWithType("native_disp",
- ui_runner_,
+ display_task_runner_ = AutoThread::CreateWithType("native_disp",
+ ui_task_runner_,
base::MessageLoop::TYPE_DEFAULT);
- url_requester_ = new URLRequestContextGetter(ui_runner_, net_runner_);
+ url_requester_ = new URLRequestContextGetter(ui_task_runner_,
+ network_task_runner_);
class_ = static_cast<jclass>(env->NewGlobalRef(env->FindClass(JAVA_CLASS)));
}
@@ -60,89 +60,62 @@ ChromotingJNIInstance::~ChromotingJNIInstance() {
// TODO(solb) detach all threads from JVM
Wez 2013/07/11 22:32:08 Why the TODO?
solb 2013/07/11 23:59:09 As I mentioned in a prior CL, it's something I pla
Wez 2013/07/12 00:24:48 OK, please file a bug for that work and refer to i
Wez 2013/07/12 01:25:44 Ping.
}
-void ChromotingJNIInstance::ConnectToHost(jstring username,
- jstring auth_token,
- jstring host_jid,
- jstring host_id,
- jstring host_pubkey) {
- JNIEnv* env = base::android::AttachCurrentThread();
-
- username_jstr_ = static_cast<jstring>(env->NewGlobalRef(username));
- auth_token_jstr_ = static_cast<jstring>(env->NewGlobalRef(auth_token));
- host_jid_jstr_ = static_cast<jstring>(env->NewGlobalRef(host_jid));
- host_id_jstr_ = static_cast<jstring>(env->NewGlobalRef(host_id));
- host_pubkey_jstr_ = static_cast<jstring>(env->NewGlobalRef(host_pubkey));
-
- username_cstr_ = env->GetStringUTFChars(username_jstr_, NULL);
- auth_token_cstr_ = env->GetStringUTFChars(auth_token_jstr_, NULL);
- host_jid_cstr_ = env->GetStringUTFChars(host_jid_jstr_, NULL);
- host_id_cstr_ = env->GetStringUTFChars(host_id_jstr_, NULL);
- host_pubkey_cstr_ = env->GetStringUTFChars(host_pubkey_jstr_, NULL);
+void ChromotingJNIInstance::ConnectToHost(const char* username,
+ const char* auth_token,
+ const char* host_jid,
+ const char* host_id,
+ const char* host_pubkey) {
Wez 2013/07/11 22:32:08 nit: DCHECK() that you're called on the expected t
solb 2013/07/11 23:59:09 The threading of this method has become less impor
Wez 2013/07/12 00:24:48 Don't other threads read these values, though? Are
+ username_ = username;
+ auth_token_ = auth_token;
+ host_jid_ = host_jid;
+ host_id_ = host_id;
+ host_pubkey_ = host_pubkey;
// We're a singleton, so Unretained is safe here.
- disp_runner_->PostTask(FROM_HERE, base::Bind(
+ display_task_runner_->PostTask(FROM_HERE, base::Bind(
&ChromotingJNIInstance::ConnectToHostOnDisplayThread,
base::Unretained(this)));
}
void ChromotingJNIInstance::DisconnectFromHost() {
- JNIEnv* env = base::android::AttachCurrentThread();
-
- env->ReleaseStringUTFChars(username_jstr_, username_cstr_);
- env->ReleaseStringUTFChars(auth_token_jstr_, auth_token_cstr_);
- env->ReleaseStringUTFChars(host_jid_jstr_, host_jid_cstr_);
- env->ReleaseStringUTFChars(host_id_jstr_, host_id_cstr_);
- env->ReleaseStringUTFChars(host_pubkey_jstr_, host_pubkey_cstr_);
-
- username_cstr_ = NULL;
- auth_token_cstr_ = NULL;
- host_jid_cstr_ = NULL;
- host_id_cstr_ = NULL;
- host_pubkey_cstr_ = NULL;
-
- env->DeleteGlobalRef(username_jstr_);
- env->DeleteGlobalRef(auth_token_jstr_);
- env->DeleteGlobalRef(host_jid_jstr_);
- env->DeleteGlobalRef(host_id_jstr_);
- env->DeleteGlobalRef(host_pubkey_jstr_);
-
- if (pin_cstr_) {
- // AuthenticatedWithPin() has been called.
- env->ReleaseStringUTFChars(pin_jstr_, pin_cstr_);
- pin_cstr_ = NULL;
- env->DeleteGlobalRef(pin_jstr_);
+ // All our work must be done on the network thread.
Wez 2013/07/11 22:32:08 ConnectToHost seems to store the strings while on
solb 2013/07/11 23:59:09 Done.
+ if (!network_task_runner_->BelongsToCurrentThread()) {
+ // We're a singleton, so Unretained is safe here.
Wez 2013/07/11 22:32:08 Why does being a singleton make it safe? Who delet
solb 2013/07/11 23:59:09 The singleton is deleted automatically at exit, wh
Wez 2013/07/12 00:24:48 Ah, OK, so the guarantee is that the object will o
Wez 2013/07/12 01:25:44 Blah... by which time there can be no further pend
+ network_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &ChromotingJNIInstance::DisconnectFromHost,
+ base::Unretained(this)));
+ return;
}
- // We're a singleton, so Unretained is safe here.
- net_runner_->PostTask(FROM_HERE, base::Bind(
- &ChromotingJNIInstance::DisconnectFromHostOnNetworkThread,
- base::Unretained(this)));
+ client_.reset();
+ connection_.reset();
+ client_context_.reset();
+ client_config_.reset();
+ chat_.reset(); // This object must outlive client_.
Wez 2013/07/11 22:32:08 nit: Suggest putting a comment before |client_| "|
solb 2013/07/11 23:59:09 Done.
+ chat_config_.reset(); // TODO(solb) Restructure to reuse between sessions.
Wez 2013/07/11 22:32:08 Either remove this TODO or elaborate on what you i
solb 2013/07/11 23:59:09 Done.
+ netset_.reset();
}
-void ChromotingJNIInstance::AuthenticateWithPin(jstring pin) {
- JNIEnv* env = base::android::AttachCurrentThread();
-
- pin_jstr_ = static_cast<jstring>(env->NewGlobalRef(pin));
- pin_cstr_ = env->GetStringUTFChars(pin_jstr_, NULL);
-
- net_runner_->PostTask(FROM_HERE, base::Bind(announce_secret_, pin_cstr_));
+void ChromotingJNIInstance::AuthenticateWithPin(const char* pin) {
+ pin_ = pin;
+ network_task_runner_->PostTask(FROM_HERE, base::Bind(announce_secret_, pin_));
}
void ChromotingJNIInstance::FetchSecret(
bool pairable,
- const protocol::SecretFetchedCallback& callback_encore) {
+ const protocol::SecretFetchedCallback& callback) {
// All our work must be done on the UI thread.
Wez 2013/07/11 22:32:08 Previous method says network thread, not UI thread
solb 2013/07/11 23:59:09 I believe it's correct as written. This method is
- if (!ui_runner_->BelongsToCurrentThread()) {
+ if (!ui_task_runner_->BelongsToCurrentThread()) {
// We're a singleton, so Unretained is safe here.
- ui_runner_->PostTask(FROM_HERE, base::Bind(
+ ui_task_runner_->PostTask(FROM_HERE, base::Bind(
&ChromotingJNIInstance::FetchSecret,
base::Unretained(this),
pairable,
- callback_encore));
+ callback));
return;
}
- announce_secret_ = callback_encore;
+ announce_secret_ = callback;
JNIEnv* env = base::android::AttachCurrentThread();
env->CallStaticVoidMethod(
class_,
@@ -153,9 +126,9 @@ void ChromotingJNIInstance::OnConnectionState(
protocol::ConnectionToHost::State state,
protocol::ErrorCode error) {
// All our work must be done on the UI thread.
Wez 2013/07/11 22:32:08 Here too
solb 2013/07/11 23:59:09 Once again, we're invoked on the network thread bu
Wez 2013/07/12 00:24:48 See comment above; no need for this comment at all
- if (!ui_runner_->BelongsToCurrentThread()) {
+ if (!ui_task_runner_->BelongsToCurrentThread()) {
// We're a singleton, so Unretained is safe here.
- ui_runner_->PostTask(FROM_HERE, base::Bind(
+ ui_task_runner_->PostTask(FROM_HERE, base::Bind(
&ChromotingJNIInstance::OnConnectionState,
base::Unretained(this),
state,
@@ -171,13 +144,16 @@ void ChromotingJNIInstance::OnConnectionState(
error);
}
-void ChromotingJNIInstance::OnConnectionReady(bool ready) {
-}
+// We ignore this message, since OnConnectionState() tells us the same thing.
Wez 2013/07/11 22:32:08 nit: Move this into the body of the method
solb 2013/07/11 23:59:09 Done.
+void ChromotingJNIInstance::OnConnectionReady(bool ready) {}
Wez 2013/07/11 22:32:08 Why do both exist, then?
solb 2013/07/11 23:59:09 Done.
+// We ignore this message because we don't deal with capabilities.
Wez 2013/07/11 22:32:08 You don't really need this comment; it's clear fro
solb 2013/07/11 23:59:09 Done.
void ChromotingJNIInstance::SetCapabilities(const std::string& capabilities) {}
+// We ignore this message because OnConnectionState() reveals the same info.
Wez 2013/07/11 22:32:08 nit: Move this comment into the body of the method
solb 2013/07/11 23:59:09 Done.
void ChromotingJNIInstance::SetPairingResponse(
- const protocol::PairingResponse& response) {}
+ const protocol::PairingResponse& response) {
+}
protocol::ClipboardStub* ChromotingJNIInstance::GetClipboardStub() {
NOTIMPLEMENTED();
@@ -189,40 +165,37 @@ protocol::CursorShapeStub* ChromotingJNIInstance::GetCursorShapeStub() {
return NULL;
}
-// We don't use NOTIMPLEMENTED() here because NegotiatingClientAuthenticator
-// calls this even if it doesn't use the configuration method, and we don't
-// want to print an error on every run.
+// We don't support third party authentication, so we return a null pointer.
Wez 2013/07/11 22:32:08 nit: Move this inside the method, and reword e.g.
solb 2013/07/11 23:59:09 Done.
scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
ChromotingJNIInstance::GetTokenFetcher(const std::string& host_public_key) {
- LOG(INFO) << "ChromotingJNIInstance::GetTokenFetcher(...) [unimplemented]";
return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>();
}
void ChromotingJNIInstance::ConnectToHostOnDisplayThread() {
- DCHECK(disp_runner_->BelongsToCurrentThread());
+ DCHECK(display_task_runner_->BelongsToCurrentThread());
if (!frames_.get()) {
- frames_ = new FrameConsumerProxy(disp_runner_);
+ frames_ = new FrameConsumerProxy(display_task_runner_);
// TODO(solb) Instantiate some FrameConsumer implementation and attach it.
}
// We're a singleton, so Unretained is safe here.
- net_runner_->PostTask(FROM_HERE, base::Bind(
+ network_task_runner_->PostTask(FROM_HERE, base::Bind(
&ChromotingJNIInstance::ConnectToHostOnNetworkThread,
base::Unretained(this)));
}
void ChromotingJNIInstance::ConnectToHostOnNetworkThread() {
- DCHECK(net_runner_->BelongsToCurrentThread());
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
client_config_.reset(new ClientConfig());
- client_config_->host_jid = host_jid_cstr_;
- client_config_->host_public_key = host_pubkey_cstr_;
+ client_config_->host_jid = host_jid_;
+ client_config_->host_public_key = host_pubkey_;
// We're a singleton, so Unretained is safe here.
Wez 2013/07/11 22:32:08 nit: Blank line before this comment.
solb 2013/07/11 23:59:09 Done.
client_config_->fetch_secret_callback = base::Bind(
&ChromotingJNIInstance::FetchSecret,
base::Unretained(this));
- client_config_->authentication_tag = host_id_cstr_;
+ client_config_->authentication_tag = host_id_;
// TODO(solb) Move these hardcoded values elsewhere:
client_config_->authentication_methods.push_back(
@@ -232,7 +205,7 @@ void ChromotingJNIInstance::ConnectToHostOnNetworkThread() {
client_config_->authentication_methods.push_back(
protocol::AuthenticationMethod::FromString("spake2_plain"));
- client_context_.reset(new ClientContext(net_runner_.get()));
+ client_context_.reset(new ClientContext(network_task_runner_.get()));
client_context_->Start();
connection_.reset(new protocol::ConnectionToHost(true));
@@ -250,8 +223,8 @@ void ChromotingJNIInstance::ConnectToHostOnNetworkThread() {
chat_config_->use_tls = CHAT_USE_TLS;
chat_.reset(new XmppSignalStrategy(url_requester_,
- username_cstr_,
- auth_token_cstr_,
+ username_,
+ auth_token_,
CHAT_AUTH_METHOD,
*chat_config_));
@@ -262,16 +235,4 @@ void ChromotingJNIInstance::ConnectToHostOnNetworkThread() {
client_->Start(chat_.get(), fact.Pass());
}
-void ChromotingJNIInstance::DisconnectFromHostOnNetworkThread() {
- DCHECK(net_runner_->BelongsToCurrentThread());
-
- client_.reset();
- connection_.reset();
- client_context_.reset();
- client_config_.reset();
- chat_.reset(); // This object must outlive client_.
- chat_config_.reset(); // TODO(solb) Restructure to reuse between sessions.
- netset_.reset();
-}
-
} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698