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

Side by Side Diff: remoting/client/jni/jni_client.h

Issue 2007123003: [Android Client] Break down multi-threaded classes by thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
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/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
14 #include "remoting/protocol/connection_to_host.h" 13 #include "remoting/protocol/connection_to_host.h"
15 #include "remoting/protocol/cursor_shape_stub.h" 14 #include "remoting/protocol/cursor_shape_stub.h"
16 15
17 namespace remoting { 16 namespace remoting {
18 17
19 class ChromotingJniRuntime; 18 class ChromotingJniRuntime;
20 class ChromotingJniInstance; 19 class ChromotingJniInstance;
20 class JniDisplayHandler;
21 class JniSecretFetcher;
21 22
22 // Houses resources scoped to a session and exposes JNI interface to the 23 // Houses resources scoped to a session and exposes JNI interface to the
23 // Java client during a session. All its methods should be invoked exclusively 24 // Java client during a session. All its methods should be invoked exclusively
24 // from the UI thread unless otherwise noted. 25 // from the UI thread unless otherwise noted.
25 class JniClient { 26 class JniClient {
26 public: 27 public:
27 JniClient(jobject java_client); 28 JniClient(ChromotingJniRuntime* runtime,
29 base::android::ScopedJavaGlobalRef<jobject> java_client);
30 virtual ~JniClient();
28 31
29 // Initiates a connection with the specified host. Only call when a host 32 // Initiates a connection with the specified host. Only call when a host
30 // connection is active (i.e. between a call to Connect() and the 33 // connection is active (i.e. between a call to Connect() and the
Lambros 2016/05/28 00:43:05 This sentence looks out-dated; remove it?
Yuwei 2016/06/01 21:30:10 Done.
31 // corresponding call to Disconnect()). To skip the attempt at pair-based 34 // corresponding call to Disconnect()). To skip the attempt at pair-based
32 // authentication, leave |pairing_id| and |pairing_secret| as empty strings. 35 // authentication, leave |pairing_id| and |pairing_secret| as empty strings.
33 void ConnectToHost(const std::string& username, 36 void ConnectToHost(base::WeakPtr<JniDisplayHandler> handler,
37 const std::string& username,
34 const std::string& auth_token, 38 const std::string& auth_token,
35 const std::string& host_jid, 39 const std::string& host_jid,
36 const std::string& host_id, 40 const std::string& host_id,
37 const std::string& host_pubkey, 41 const std::string& host_pubkey,
38 const std::string& pairing_id, 42 const std::string& pairing_id,
39 const std::string& pairing_secret, 43 const std::string& pairing_secret,
40 const std::string& capabilities, 44 const std::string& capabilities,
41 const std::string& flags); 45 const std::string& flags);
42 46
43 // Terminates any ongoing connection attempt and cleans up by nullifying 47 // Terminates any ongoing connection attempt and cleans up by nullifying
(...skipping 19 matching lines...) Expand all
63 const std::string& scope); 67 const std::string& scope);
64 68
65 // Pass on the set of negotiated capabilities to the client. 69 // Pass on the set of negotiated capabilities to the client.
66 void SetCapabilities(const std::string& capabilities); 70 void SetCapabilities(const std::string& capabilities);
67 71
68 // Passes on the deconstructed ExtensionMessage to the client to handle 72 // Passes on the deconstructed ExtensionMessage to the client to handle
69 // appropriately. 73 // appropriately.
70 void HandleExtensionMessage(const std::string& type, 74 void HandleExtensionMessage(const std::string& type,
71 const std::string& message); 75 const std::string& message);
72 76
73 // Creates a new Bitmap object to store a video frame.
74 base::android::ScopedJavaLocalRef<jobject> NewBitmap(int width, int height);
75
76 // Updates video frame bitmap. |bitmap| must be an instance of
77 // android.graphics.Bitmap. Call on the display thread.
78 void UpdateFrameBitmap(jobject bitmap);
79
80 // Updates cursor shape. Call on display thread.
81 void UpdateCursorShape(const protocol::CursorShapeInfo& cursor_shape);
82
83 // Draws the latest image buffer onto the canvas. Call on the display thread.
84 void RedrawCanvas();
85
86 // Register C++ methods exposed to Java using JNI. 77 // Register C++ methods exposed to Java using JNI.
87 static bool RegisterJni(JNIEnv* env); 78 static bool RegisterJni(JNIEnv* env);
88 79
89 // The following methods are exposed to Java via JNI. 80 // The following methods are exposed to Java via JNI.
90 81
91 void Connect(JNIEnv* env, 82 void Connect(JNIEnv* env,
92 const base::android::JavaParamRef<jobject>& caller, 83 const base::android::JavaParamRef<jobject>& caller,
84 jlong display_handler_ptr,
93 const base::android::JavaParamRef<jstring>& username, 85 const base::android::JavaParamRef<jstring>& username,
94 const base::android::JavaParamRef<jstring>& authToken, 86 const base::android::JavaParamRef<jstring>& authToken,
95 const base::android::JavaParamRef<jstring>& hostJid, 87 const base::android::JavaParamRef<jstring>& hostJid,
96 const base::android::JavaParamRef<jstring>& hostId, 88 const base::android::JavaParamRef<jstring>& hostId,
97 const base::android::JavaParamRef<jstring>& hostPubkey, 89 const base::android::JavaParamRef<jstring>& hostPubkey,
98 const base::android::JavaParamRef<jstring>& pairId, 90 const base::android::JavaParamRef<jstring>& pairId,
99 const base::android::JavaParamRef<jstring>& pairSecret, 91 const base::android::JavaParamRef<jstring>& pairSecret,
100 const base::android::JavaParamRef<jstring>& capabilities, 92 const base::android::JavaParamRef<jstring>& capabilities,
101 const base::android::JavaParamRef<jstring>& flags); 93 const base::android::JavaParamRef<jstring>& flags);
102 94
103 void Disconnect(JNIEnv* env, 95 void Disconnect(JNIEnv* env,
104 const base::android::JavaParamRef<jobject>& caller); 96 const base::android::JavaParamRef<jobject>& caller);
105 97
106 void AuthenticationResponse( 98 void AuthenticationResponse(
107 JNIEnv* env, 99 JNIEnv* env,
108 const base::android::JavaParamRef<jobject>& caller, 100 const base::android::JavaParamRef<jobject>& caller,
109 const base::android::JavaParamRef<jstring>& pin, 101 const base::android::JavaParamRef<jstring>& pin,
110 jboolean createPair, 102 jboolean createPair,
111 const base::android::JavaParamRef<jstring>& deviceName); 103 const base::android::JavaParamRef<jstring>& deviceName);
112 104
113 void ScheduleRedraw(JNIEnv* env,
114 const base::android::JavaParamRef<jobject>& caller);
115
116 void SendMouseEvent(JNIEnv* env, 105 void SendMouseEvent(JNIEnv* env,
117 const base::android::JavaParamRef<jobject>& caller, 106 const base::android::JavaParamRef<jobject>& caller,
118 jint x, 107 jint x,
119 jint y, 108 jint y,
120 jint whichButton, 109 jint whichButton,
121 jboolean buttonDown); 110 jboolean buttonDown);
122 111
123 void SendMouseWheelEvent(JNIEnv* env, 112 void SendMouseWheelEvent(JNIEnv* env,
124 const base::android::JavaParamRef<jobject>& caller, 113 const base::android::JavaParamRef<jobject>& caller,
125 jint delta_x, 114 jint delta_x,
(...skipping 23 matching lines...) Expand all
149 JNIEnv* env, 138 JNIEnv* env,
150 const base::android::JavaParamRef<jobject>& caller, 139 const base::android::JavaParamRef<jobject>& caller,
151 const base::android::JavaParamRef<jstring>& token, 140 const base::android::JavaParamRef<jstring>& token,
152 const base::android::JavaParamRef<jstring>& shared_secret); 141 const base::android::JavaParamRef<jstring>& shared_secret);
153 142
154 void SendExtensionMessage(JNIEnv* env, 143 void SendExtensionMessage(JNIEnv* env,
155 const base::android::JavaParamRef<jobject>& caller, 144 const base::android::JavaParamRef<jobject>& caller,
156 const base::android::JavaParamRef<jstring>& type, 145 const base::android::JavaParamRef<jstring>& type,
157 const base::android::JavaParamRef<jstring>& data); 146 const base::android::JavaParamRef<jstring>& data);
158 147
159 // Destroys this object. Called on UI thread. This function will delete the 148 // Deletes this object.
160 // |java_client_| reference and delete |this|.
161 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& caller); 149 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& caller);
Yuwei 2016/05/27 19:14:13 No longer need env to manually delete the referenc
162 150
163 // Get the weak pointer of the object. Should be used on the UI thread. 151 // Get the weak pointer of the object. Should be used on the UI thread.
164 // TODO(yuweih): Instead of exposing a weak pointer in the public API, 152 // TODO(yuweih): Instead of exposing a weak pointer in the public API,
165 // consider handling task posting inside the client. 153 // consider handling task posting inside the client.
166 base::WeakPtr<JniClient> GetWeakPtr(); 154 base::WeakPtr<JniClient> GetWeakPtr();
167 155
168 private: 156 private:
169 // Please use Destroy() to delete this object. 157 ChromotingJniRuntime* runtime_;
Yuwei 2016/05/27 19:14:13 Feels cleaner and easier to test to pass in the ru
170 ~JniClient();
171
172 // Helper function for getting the runtime instance.
173 static ChromotingJniRuntime* runtime();
174 158
175 // Reference to the Java client object. 159 // Reference to the Java client object.
176 jobject java_client_; 160 base::android::ScopedJavaGlobalRef<jobject> java_client_;
177 161
178 scoped_refptr<ChromotingJniInstance> session_; 162 base::WeakPtr<JniDisplayHandler> display_handler_;
163
164 // Deleted on UI thread.
165 std::unique_ptr<JniSecretFetcher> secret_fetcher_;
166
167 // Deleted on Network thread.
168 std::unique_ptr<ChromotingJniInstance> session_;
179 169
180 // Holds pointer for the UI thread. 170 // Holds pointer for the UI thread.
181 base::WeakPtrFactory<JniClient> weak_factory_; 171 base::WeakPtrFactory<JniClient> weak_factory_;
182 172
183 DISALLOW_COPY_AND_ASSIGN(JniClient); 173 DISALLOW_COPY_AND_ASSIGN(JniClient);
184 }; 174 };
185 175
186 } // namespace remoting 176 } // namespace remoting
187 177
188 #endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_ 178 #endif // REMOTING_CLIENT_JNI_JNI_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698