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

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

Issue 18856012: Create new remoting_client_jni target (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Gary's recommendations 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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.
Wez 2013/07/11 00:56:23 Remove this comment; it should be clear from the N
solb 2013/07/11 04:29:05 Done.
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.
Wez 2013/07/11 00:56:23 NOTIMPLEMENTED() here.
solb 2013/07/11 04:29:05 Done.
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) {}
Wez 2013/07/11 00:56:23 nit: This is a multi-line definition, so braces go
solb 2013/07/11 04:29:05 Done.
71
72 void ChromotingJNIInstance::OnConnectionReady(bool ready) {}
Wez 2013/07/11 00:56:23 Why are this and the next three methods not NOTIMP
solb 2013/07/11 04:29:05 Although I am required (by ClientUserInterface's c
73
74 void ChromotingJNIInstance::SetCapabilities(const std::string& capabilities) {}
75
76 void ChromotingJNIInstance::SetPairingResponse(
77 const protocol::PairingResponse& response) {}
Wez 2013/07/11 00:56:23 nit: See above re braces
solb 2013/07/11 04:29:05 Done.
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.
Wez 2013/07/11 00:56:23 This doesn't make sense - if it's going to be impl
solb 2013/07/11 04:29:05 Done (for the latter case). Since scoped_ptr has n
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);
Wez 2013/07/11 00:56:23 nit: Comment before this blobk to explain why we n
solb 2013/07/11 04:29:05 Done.
111
112 LOG(INFO) << "starting main message loop";
Wez 2013/07/11 00:56:23 nit: Capital at beginning of sentence, please.
solb 2013/07/11 04:29:05 Done.
113 ui_loop_.reset(new base::MessageLoopForUI());
114 ui_loop_->Start();
Wez 2013/07/11 00:56:23 Add a comment to explain this, since it differs fr
solb 2013/07/11 04:29:05 Done.
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_);
134 // TODO(solb) detach all threads from JVM
Wez 2013/07/11 00:56:23 Why not just add the detaching here in this CL?
solb 2013/07/11 04:29:05 I just don't have an implementation ready at this
135 }
136
137 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698