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 #ifndef REMOTING_HOST_ANDROID_JNI_HOST_H_ | 5 #ifndef REMOTING_HOST_ANDROID_JNI_HOST_H_ |
6 #define REMOTING_HOST_ANDROID_JNI_HOST_H_ | 6 #define REMOTING_HOST_ANDROID_JNI_HOST_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "remoting/host/it2me/it2me_host.h" | 17 #include "remoting/host/it2me/it2me_host.h" |
18 | 18 |
19 namespace remoting { | 19 namespace remoting { |
20 | 20 |
21 class ChromotingHostContext; | 21 class ChromotingHostContext; |
22 class It2MeHostFactory; | 22 class It2MeHostFactory; |
23 | 23 |
24 class JniHost : public It2MeHost::Observer { | 24 class JniHost : public It2MeHost::Observer { |
25 public: | 25 public: |
26 JniHost(); | 26 JniHost(JNIEnv* env, jobject java_host); |
27 virtual ~JniHost(); | 27 virtual ~JniHost(); |
28 | 28 |
29 // Register C++ methods exposed to Java using JNI. | 29 // Register C++ methods exposed to Java using JNI. |
30 static bool RegisterJni(JNIEnv* env); | 30 static bool RegisterJni(JNIEnv* env); |
31 | 31 |
32 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& caller); | 32 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& caller); |
33 | 33 |
34 void Connect(JNIEnv* env, | 34 void Connect(JNIEnv* env, |
35 const base::android::JavaParamRef<jobject>& caller, | 35 const base::android::JavaParamRef<jobject>& caller, |
36 const base::android::JavaParamRef<jstring>& user_name, | 36 const base::android::JavaParamRef<jstring>& user_name, |
37 const base::android::JavaParamRef<jstring>& auth_token); | 37 const base::android::JavaParamRef<jstring>& auth_token); |
38 | 38 |
39 void Disconnect(JNIEnv* env, | 39 void Disconnect(JNIEnv* env, |
40 const base::android::JavaParamRef<jobject>& caller); | 40 const base::android::JavaParamRef<jobject>& caller); |
41 | 41 |
42 // It2MeHost::Observer implementation. | 42 // It2MeHost::Observer implementation. |
43 void OnClientAuthenticated(const std::string& client_username) override; | 43 void OnClientAuthenticated(const std::string& client_username) override; |
44 void OnStoreAccessCode(const std::string& access_code, | 44 void OnStoreAccessCode(const std::string& access_code, |
45 base::TimeDelta access_code_lifetime) override; | 45 base::TimeDelta access_code_lifetime) override; |
46 void OnNatPolicyChanged(bool nat_traversal_enabled) override; | 46 void OnNatPolicyChanged(bool nat_traversal_enabled) override; |
47 void OnStateChanged(It2MeHostState state, | 47 void OnStateChanged(It2MeHostState state, |
48 const std::string& error_message) override; | 48 const std::string& error_message) override; |
49 | 49 |
50 private: | 50 private: |
| 51 base::android::ScopedJavaGlobalRef<jobject> java_host_; |
| 52 |
51 std::unique_ptr<base::MessageLoopForUI> ui_loop_; | 53 std::unique_ptr<base::MessageLoopForUI> ui_loop_; |
52 std::unique_ptr<ChromotingHostContext> host_context_; | 54 std::unique_ptr<ChromotingHostContext> host_context_; |
53 std::unique_ptr<It2MeHostFactory> factory_; | 55 std::unique_ptr<It2MeHostFactory> factory_; |
54 scoped_refptr<It2MeHost> it2me_host_; | 56 scoped_refptr<It2MeHost> it2me_host_; |
55 | 57 |
56 // IT2Me Talk server configuration used by |it2me_host_| to connect. | 58 // IT2Me Talk server configuration used by |it2me_host_| to connect. |
57 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 59 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
58 | 60 |
59 base::WeakPtr<JniHost> weak_ptr_; | 61 base::WeakPtr<JniHost> weak_ptr_; |
60 base::WeakPtrFactory<JniHost> weak_factory_; | 62 base::WeakPtrFactory<JniHost> weak_factory_; |
61 | 63 |
62 DISALLOW_COPY_AND_ASSIGN(JniHost); | 64 DISALLOW_COPY_AND_ASSIGN(JniHost); |
63 }; | 65 }; |
64 | 66 |
65 } // namespace remoting | 67 } // namespace remoting |
66 | 68 |
67 #endif // REMOTING_HOST_ANDROID_JNI_HOST_H_ | 69 #endif // REMOTING_HOST_ANDROID_JNI_HOST_H_ |
OLD | NEW |