OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_CLIENT_JNI_JNI_CLIENT_H_ | 5 #ifndef REMOTING_CLIENT_JNI_JNI_CLIENT_H_ |
6 #define REMOTING_CLIENT_JNI_JNI_CLIENT_H_ | 6 #define REMOTING_CLIENT_JNI_JNI_CLIENT_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "remoting/protocol/connection_to_host.h" | 13 #include "remoting/protocol/connection_to_host.h" |
14 #include "remoting/protocol/cursor_shape_stub.h" | 14 #include "remoting/protocol/cursor_shape_stub.h" |
15 | 15 |
16 namespace remoting { | 16 namespace remoting { |
17 | 17 |
18 class ChromotingJniRuntime; | 18 class ChromotingClientRuntime; |
19 class ChromotingJniInstance; | 19 class ChromotingJniInstance; |
20 class JniGlDisplayHandler; | 20 class JniGlDisplayHandler; |
21 class JniPairingSecretFetcher; | 21 class JniPairingSecretFetcher; |
22 | 22 |
23 struct ConnectToHostInfo; | 23 struct ConnectToHostInfo; |
24 | 24 |
25 // Houses resources scoped to a session and exposes JNI interface to the | 25 // Houses resources scoped to a session and exposes JNI interface to the |
26 // Java client during a session. All its methods should be invoked exclusively | 26 // Java client during a session. All its methods should be invoked exclusively |
27 // from the UI thread unless otherwise noted. | 27 // from the UI thread unless otherwise noted. |
28 class JniClient { | 28 class JniClient { |
29 public: | 29 public: |
30 JniClient(ChromotingJniRuntime* runtime, | 30 JniClient(base::android::ScopedJavaGlobalRef<jobject> java_client); |
31 base::android::ScopedJavaGlobalRef<jobject> java_client); | |
32 virtual ~JniClient(); | 31 virtual ~JniClient(); |
33 | 32 |
34 // Initiates a connection with the specified host. To skip the attempt at | 33 // Initiates a connection with the specified host. To skip the attempt at |
35 // pair-based authentication, leave |pairing_id| and |pairing_secret| as | 34 // pair-based authentication, leave |pairing_id| and |pairing_secret| as |
36 // empty strings. | 35 // empty strings. |
37 void ConnectToHost(const ConnectToHostInfo& info); | 36 void ConnectToHost(const ConnectToHostInfo& info); |
38 | 37 |
39 // Terminates any ongoing connection attempt and cleans up by nullifying | 38 // Terminates any ongoing connection attempt and cleans up by nullifying |
40 // |session_|. This is a no-op unless |session| is currently non-null. | 39 // |session_|. This is a no-op unless |session| is currently non-null. |
41 void DisconnectFromHost(); | 40 void DisconnectFromHost(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 141 |
143 // Deletes this object. | 142 // Deletes this object. |
144 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& caller); | 143 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& caller); |
145 | 144 |
146 // Get the weak pointer of the object. Should be used on the UI thread. | 145 // Get the weak pointer of the object. Should be used on the UI thread. |
147 // TODO(yuweih): Instead of exposing a weak pointer in the public API, | 146 // TODO(yuweih): Instead of exposing a weak pointer in the public API, |
148 // consider handling task posting inside the client. | 147 // consider handling task posting inside the client. |
149 base::WeakPtr<JniClient> GetWeakPtr(); | 148 base::WeakPtr<JniClient> GetWeakPtr(); |
150 | 149 |
151 private: | 150 private: |
152 ChromotingJniRuntime* runtime_; | 151 ChromotingClientRuntime* runtime_; |
153 | 152 |
154 // Reference to the Java client object. | 153 // Reference to the Java client object. |
155 base::android::ScopedJavaGlobalRef<jobject> java_client_; | 154 base::android::ScopedJavaGlobalRef<jobject> java_client_; |
156 | 155 |
157 std::unique_ptr<JniGlDisplayHandler> display_handler_; | 156 std::unique_ptr<JniGlDisplayHandler> display_handler_; |
158 | 157 |
159 // Deleted on UI thread. | 158 // Deleted on UI thread. |
160 std::unique_ptr<JniPairingSecretFetcher> secret_fetcher_; | 159 std::unique_ptr<JniPairingSecretFetcher> secret_fetcher_; |
161 | 160 |
162 // Deleted on Network thread. | 161 // Deleted on Network thread. |
163 std::unique_ptr<ChromotingJniInstance> session_; | 162 std::unique_ptr<ChromotingJniInstance> session_; |
164 | 163 |
165 // Holds pointer for the UI thread. | 164 // Holds pointer for the UI thread. |
166 base::WeakPtr<JniClient> weak_ptr_; | 165 base::WeakPtr<JniClient> weak_ptr_; |
167 base::WeakPtrFactory<JniClient> weak_factory_; | 166 base::WeakPtrFactory<JniClient> weak_factory_; |
168 | 167 |
169 DISALLOW_COPY_AND_ASSIGN(JniClient); | 168 DISALLOW_COPY_AND_ASSIGN(JniClient); |
170 }; | 169 }; |
171 | 170 |
172 } // namespace remoting | 171 } // namespace remoting |
173 | 172 |
174 #endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_ | 173 #endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_ |
OLD | NEW |