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

Side by Side Diff: remoting/host/android/jni_host.cc

Issue 1913023002: Revert of [remoting android] Initialize It2Me host and implement Connect() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « remoting/host/android/jni_host.h ('k') | remoting/host/it2me/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/host/android/jni_host.h" 5 #include "remoting/host/android/jni_host.h"
6 6
7 #include "base/android/jni_string.h"
8 #include "base/command_line.h"
9 #include "base/strings/string_util.h"
10 #include "jni/Host_jni.h" 7 #include "jni/Host_jni.h"
11 #include "net/base/url_util.h"
12 #include "net/socket/ssl_server_socket.h"
13 #include "remoting/base/auto_thread_task_runner.h"
14 #include "remoting/base/logging.h"
15 #include "remoting/host/chromoting_host_context.h"
16 #include "remoting/host/it2me/it2me_host.h"
17 #include "remoting/host/service_urls.h"
18 #include "remoting/signaling/xmpp_signal_strategy.h"
19
20 using base::android::ConvertJavaStringToUTF8;
21 8
22 namespace remoting { 9 namespace remoting {
23 10
24 JniHost::JniHost() : weak_factory_(this) { 11 JniHost::JniHost() {}
25 weak_ptr_ = weak_factory_.GetWeakPtr();
26
27 base::CommandLine::Init(0, nullptr);
28
29 // Enable support for SSL server sockets, which must be done while still
30 // single-threaded.
31 net::EnableSSLServerSockets();
32
33 if (!base::MessageLoop::current()) {
34 HOST_LOG << "Starting main message loop";
35
36 // On Android, the UI thread is managed by Java, so we need to attach and
37 // start a special type of message loop to allow Chromium code to run tasks.
38 ui_loop_.reset(new base::MessageLoopForUI());
39 ui_loop_->Start();
40 } else {
41 HOST_LOG << "Using existing main message loop";
42 ui_loop_.reset(base::MessageLoopForUI::current());
43 }
44
45 factory_.reset(new It2MeHostFactory());
46 host_context_ =
47 ChromotingHostContext::Create(new remoting::AutoThreadTaskRunner(
48 ui_loop_->task_runner(), base::Bind(&base::DoNothing)));
49
50 const ServiceUrls* service_urls = ServiceUrls::GetInstance();
51 const bool xmpp_server_valid = net::ParseHostAndPort(
52 service_urls->xmpp_server_address(), &xmpp_server_config_.host,
53 &xmpp_server_config_.port);
54 DCHECK(xmpp_server_valid);
55
56 xmpp_server_config_.use_tls = service_urls->xmpp_server_use_tls();
57 }
58 12
59 JniHost::~JniHost() {} 13 JniHost::~JniHost() {}
60 14
61 // static 15 // static
62 bool JniHost::RegisterJni(JNIEnv* env) { 16 bool JniHost::RegisterJni(JNIEnv* env) {
63 return RegisterNativesImpl(env); 17 return RegisterNativesImpl(env);
64 } 18 }
65 19
66 void JniHost::Destroy(JNIEnv* env, const JavaParamRef<jobject>& caller) { 20 void JniHost::Destroy(JNIEnv* env, const JavaParamRef<jobject>& caller) {
67 delete this; 21 delete this;
68 } 22 }
69 23
70 void JniHost::Connect(JNIEnv* env,
71 const base::android::JavaParamRef<jobject>& caller,
72 const JavaParamRef<jstring>& user_name,
73 const JavaParamRef<jstring>& auth_token) {
74 if (it2me_host_) {
75 LOG(ERROR) << "Connect: already connected.";
76 return;
77 }
78
79 XmppSignalStrategy::XmppServerConfig xmpp_config = xmpp_server_config_;
80 xmpp_config.username = ConvertJavaStringToUTF8(user_name);
81 xmpp_config.auth_token = ConvertJavaStringToUTF8(auth_token);
82
83 std::string directory_bot_jid =
84 ServiceUrls::GetInstance()->directory_bot_jid();
85
86 // Create the It2Me host and start connecting.
87 it2me_host_ = factory_->CreateIt2MeHost(host_context_->Copy(), weak_ptr_,
88 xmpp_config, directory_bot_jid);
89 it2me_host_->Connect();
90 }
91
92 void JniHost::Disconnect(JNIEnv* env,
93 const base::android::JavaParamRef<jobject>& caller) {}
94
95 void JniHost::OnClientAuthenticated(const std::string& client_username) {
96 HOST_LOG << "OnClientAuthenticated: " << client_username;
97 }
98
99 void JniHost::OnStoreAccessCode(const std::string& access_code,
100 base::TimeDelta access_code_lifetime) {
101 HOST_LOG << "OnStoreAccessCode: " << access_code << ", "
102 << access_code_lifetime.InSeconds();
103 }
104
105 void JniHost::OnNatPolicyChanged(bool nat_traversal_enabled) {
106 HOST_LOG << "OnNatPolicyChanged: " << nat_traversal_enabled;
107 }
108
109 void JniHost::OnStateChanged(It2MeHostState state,
110 const std::string& error_message) {
111 HOST_LOG << "OnStateChanged: " << state;
112 }
113
114 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& caller) { 24 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& caller) {
115 return reinterpret_cast<intptr_t>(new JniHost()); 25 return reinterpret_cast<intptr_t>(new JniHost());
116 } 26 }
117 27
118 } // namespace remoting 28 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/android/jni_host.h ('k') | remoting/host/it2me/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698