OLD | NEW |
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" | 7 #include "base/android/jni_string.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "jni/Host_jni.h" | 10 #include "jni/Host_jni.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 std::string directory_bot_jid = | 85 std::string directory_bot_jid = |
86 ServiceUrls::GetInstance()->directory_bot_jid(); | 86 ServiceUrls::GetInstance()->directory_bot_jid(); |
87 | 87 |
88 // Create the It2Me host and start connecting. | 88 // Create the It2Me host and start connecting. |
89 it2me_host_ = factory_->CreateIt2MeHost(host_context_->Copy(), weak_ptr_, | 89 it2me_host_ = factory_->CreateIt2MeHost(host_context_->Copy(), weak_ptr_, |
90 xmpp_config, directory_bot_jid); | 90 xmpp_config, directory_bot_jid); |
91 it2me_host_->Connect(); | 91 it2me_host_->Connect(); |
92 } | 92 } |
93 | 93 |
94 void JniHost::Disconnect(JNIEnv* env, | 94 void JniHost::Disconnect(JNIEnv* env, |
95 const base::android::JavaParamRef<jobject>& caller) {} | 95 const base::android::JavaParamRef<jobject>& caller) { |
| 96 if (it2me_host_) { |
| 97 it2me_host_->Disconnect(); |
| 98 it2me_host_ = nullptr; |
| 99 } |
| 100 } |
96 | 101 |
97 void JniHost::OnClientAuthenticated(const std::string& client_username) { | 102 void JniHost::OnClientAuthenticated(const std::string& client_username) { |
98 HOST_LOG << "OnClientAuthenticated: " << client_username; | 103 HOST_LOG << "OnClientAuthenticated: " << client_username; |
99 } | 104 } |
100 | 105 |
101 void JniHost::OnStoreAccessCode(const std::string& access_code, | 106 void JniHost::OnStoreAccessCode(const std::string& access_code, |
102 base::TimeDelta access_code_lifetime) { | 107 base::TimeDelta access_code_lifetime) { |
103 JNIEnv* env = base::android::AttachCurrentThread(); | 108 JNIEnv* env = base::android::AttachCurrentThread(); |
104 Java_Host_onAccessCodeReceived( | 109 Java_Host_onAccessCodeReceived( |
105 env, java_host_.obj(), ConvertUTF8ToJavaString(env, access_code).obj(), | 110 env, java_host_.obj(), ConvertUTF8ToJavaString(env, access_code).obj(), |
106 static_cast<int>(access_code_lifetime.InSeconds())); | 111 static_cast<int>(access_code_lifetime.InSeconds())); |
107 } | 112 } |
108 | 113 |
109 void JniHost::OnNatPolicyChanged(bool nat_traversal_enabled) { | 114 void JniHost::OnNatPolicyChanged(bool nat_traversal_enabled) { |
110 HOST_LOG << "OnNatPolicyChanged: " << nat_traversal_enabled; | 115 HOST_LOG << "OnNatPolicyChanged: " << nat_traversal_enabled; |
111 } | 116 } |
112 | 117 |
113 void JniHost::OnStateChanged(It2MeHostState state, | 118 void JniHost::OnStateChanged(It2MeHostState state, |
114 const std::string& error_message) { | 119 const std::string& error_message) { |
| 120 if (state == kDisconnected) { |
| 121 it2me_host_ = nullptr; |
| 122 } |
| 123 |
115 JNIEnv* env = base::android::AttachCurrentThread(); | 124 JNIEnv* env = base::android::AttachCurrentThread(); |
116 Java_Host_onStateChanged(env, java_host_.obj(), state, | 125 Java_Host_onStateChanged(env, java_host_.obj(), state, |
117 ConvertUTF8ToJavaString(env, error_message).obj()); | 126 ConvertUTF8ToJavaString(env, error_message).obj()); |
118 } | 127 } |
119 | 128 |
120 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& caller) { | 129 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& caller) { |
121 return reinterpret_cast<intptr_t>(new JniHost(env, caller)); | 130 return reinterpret_cast<intptr_t>(new JniHost(env, caller)); |
122 } | 131 } |
123 | 132 |
124 } // namespace remoting | 133 } // namespace remoting |
OLD | NEW |