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

Side by Side Diff: remoting/client/jni/chromoting_jni_instance.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: Rename JniSecretFetcher to JniPairingSecretFetcher 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_CHROMOTING_JNI_INSTANCE_H_ 5 #ifndef REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_
6 #define REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_ 6 #define REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 14 matching lines...) Expand all
25 25
26 namespace protocol { 26 namespace protocol {
27 class ClipboardEvent; 27 class ClipboardEvent;
28 class CursorShapeInfo; 28 class CursorShapeInfo;
29 class PerformanceTracker; 29 class PerformanceTracker;
30 class VideoRenderer; 30 class VideoRenderer;
31 } // namespace protocol 31 } // namespace protocol
32 32
33 class ChromotingJniRuntime; 33 class ChromotingJniRuntime;
34 class JniClient; 34 class JniClient;
35 class JniDisplayHandler;
35 class JniFrameConsumer; 36 class JniFrameConsumer;
37 class JniPairingSecretFetcher;
36 38
37 // ClientUserInterface that indirectly makes and receives JNI calls. 39 // ChromotingJniInstance is scoped to the session.
40 // This class is Created on the UI thread but thereafter it is used and
41 // destroyed on the network thread. Except where indicated, all methods are
42 // called on the network thread.
38 class ChromotingJniInstance 43 class ChromotingJniInstance
39 : public ClientUserInterface, 44 : public ClientUserInterface,
40 public protocol::ClipboardStub, 45 public protocol::ClipboardStub,
41 public protocol::CursorShapeStub, 46 public protocol::CursorShapeStub {
42 public base::RefCountedThreadSafe<ChromotingJniInstance> {
43 public: 47 public:
44 // Initiates a connection with the specified host. Call from the UI thread. 48 // Initiates a connection with the specified host. Call from the UI thread.
45 // The instance does not take ownership of |jni_runtime|. To connect with an 49 // The instance does not take ownership of |jni_runtime|. To connect with an
46 // unpaired host, pass in |pairing_id| and |pairing_secret| as empty strings. 50 // unpaired host, pass in |pairing_id| and |pairing_secret| as empty strings.
47 ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, 51 ChromotingJniInstance(ChromotingJniRuntime* jni_runtime,
48 JniClient* jni_client, 52 base::WeakPtr<JniClient> jni_client,
53 base::WeakPtr<JniDisplayHandler> display,
54 base::WeakPtr<JniPairingSecretFetcher> secret_fetcher,
49 const std::string& username, 55 const std::string& username,
50 const std::string& auth_token, 56 const std::string& auth_token,
51 const std::string& host_jid, 57 const std::string& host_jid,
52 const std::string& host_id, 58 const std::string& host_id,
53 const std::string& host_pubkey, 59 const std::string& host_pubkey,
54 const std::string& pairing_id, 60 const std::string& pairing_id,
55 const std::string& pairing_secret, 61 const std::string& pairing_secret,
56 const std::string& capabilities, 62 const std::string& capabilities,
57 const std::string& flags); 63 const std::string& flags);
58 64
65 ~ChromotingJniInstance() override;
66
59 // Starts the connection. Can be called on any thread. 67 // Starts the connection. Can be called on any thread.
60 void Connect(); 68 void Connect();
61 69
62 // Terminates the current connection (if it hasn't already failed) and cleans 70 // Terminates the current connection (if it hasn't already failed) and cleans
63 // up. The instance will no longer be valid after calling this function. 71 // up. The instance will no longer be valid after calling this function.
64 // Must be called before destruction. 72 // Must be called before destruction.
65 void Disconnect(); 73 void Disconnect();
66 74
67 // Requests the android app to fetch a third-party token. 75 // Requests the android app to fetch a third-party token.
68 void FetchThirdPartyToken( 76 void FetchThirdPartyToken(
69 const std::string& host_public_key, 77 const std::string& host_public_key,
70 const std::string& token_url, 78 const std::string& token_url,
71 const std::string& scope, 79 const std::string& scope,
72 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback); 80 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback);
73 81
74 // Called by the android app when the token is fetched. 82 // Called by the android app when the token is fetched.
75 void HandleOnThirdPartyTokenFetched(const std::string& token, 83 void HandleOnThirdPartyTokenFetched(const std::string& token,
76 const std::string& shared_secret); 84 const std::string& shared_secret);
77 85
78 // Provides the user's PIN and resumes the host authentication attempt. Call 86 // Provides the user's PIN and resumes the host authentication attempt. Call
79 // on the UI thread once the user has finished entering this PIN into the UI, 87 // on the UI thread once the user has finished entering this PIN into the UI,
80 // but only after the UI has been asked to provide a PIN (via FetchSecret()). 88 // but only after the UI has been asked to provide a PIN (via FetchSecret()).
81 void ProvideSecret(const std::string& pin, bool create_pair, 89 void ProvideSecret(const std::string& pin, bool create_pair,
82 const std::string& device_name); 90 const std::string& device_name);
83 91
84 // Schedules a redraw on the display thread. May be called from any thread.
85 void RedrawDesktop();
86
87 // Moves the host's cursor to the specified coordinates, optionally with some 92 // Moves the host's cursor to the specified coordinates, optionally with some
88 // mouse button depressed. If |button| is BUTTON_UNDEFINED, no click is made. 93 // mouse button depressed. If |button| is BUTTON_UNDEFINED, no click is made.
89 void SendMouseEvent(int x, int y, 94 void SendMouseEvent(int x, int y,
90 protocol::MouseEvent_MouseButton button, 95 protocol::MouseEvent_MouseButton button,
91 bool button_down); 96 bool button_down);
92 void SendMouseWheelEvent(int delta_x, int delta_y); 97 void SendMouseWheelEvent(int delta_x, int delta_y);
93 98
94 // Sends the provided keyboard scan code to the host. 99 // Sends the provided keyboard scan code to the host.
95 bool SendKeyEvent(int scan_code, int key_code, bool key_down); 100 bool SendKeyEvent(int scan_code, int key_code, bool key_down);
96 101
(...skipping 20 matching lines...) Expand all
117 const webrtc::DesktopVector& dpi) override; 122 const webrtc::DesktopVector& dpi) override;
118 protocol::ClipboardStub* GetClipboardStub() override; 123 protocol::ClipboardStub* GetClipboardStub() override;
119 protocol::CursorShapeStub* GetCursorShapeStub() override; 124 protocol::CursorShapeStub* GetCursorShapeStub() override;
120 125
121 // CursorShapeStub implementation. 126 // CursorShapeStub implementation.
122 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override; 127 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override;
123 128
124 // ClipboardStub implementation. 129 // ClipboardStub implementation.
125 void SetCursorShape(const protocol::CursorShapeInfo& shape) override; 130 void SetCursorShape(const protocol::CursorShapeInfo& shape) override;
126 131
132 // Get the weak pointer of the instance. Please only use it on the network
133 // thread.
134 base::WeakPtr<ChromotingJniInstance> GetWeakPtr();
135
127 private: 136 private:
128 // This object is ref-counted, so it cleans itself up.
129 ~ChromotingJniInstance() override;
130
131 void ConnectToHostOnNetworkThread(); 137 void ConnectToHostOnNetworkThread();
132 138
133 // Notifies the user interface that the user needs to enter a PIN. The 139 // Notifies the user interface that the user needs to enter a PIN. The
134 // current authentication attempt is put on hold until |callback| is invoked. 140 // current authentication attempt is put on hold until |callback| is invoked.
135 // May be called on any thread. 141 // May be called on any thread.
136 void FetchSecret(bool pairable, 142 void FetchSecret(bool pairable,
137 const protocol::SecretFetchedCallback& callback); 143 const protocol::SecretFetchedCallback& callback);
138 144
139 // Sets the device name. Can be called on any thread. 145 // Sets the device name. Can be called on any thread.
140 void SetDeviceName(const std::string& device_name); 146 void SetDeviceName(const std::string& device_name);
141 147
142 void SendKeyEventInternal(int usb_key_code, bool key_down); 148 void SendKeyEventInternal(int usb_key_code, bool key_down);
143 149
144 // Enables or disables periodic logging of performance statistics. Called on 150 // Enables or disables periodic logging of performance statistics. Called on
145 // the network thread. 151 // the network thread.
146 void EnableStatsLogging(bool enabled); 152 void EnableStatsLogging(bool enabled);
147 153
148 // If logging is enabled, logs the current connection statistics, and 154 // If logging is enabled, logs the current connection statistics, and
149 // triggers another call to this function after the logging time interval. 155 // triggers another call to this function after the logging time interval.
150 // Called on the network thread. 156 // Called on the network thread.
151 void LogPerfStats(); 157 void LogPerfStats();
152 158
159 // Releases the resource in the right order.
160 void ReleaseResources();
161
153 // Used to obtain task runner references and make calls to Java methods. 162 // Used to obtain task runner references and make calls to Java methods.
154 ChromotingJniRuntime* jni_runtime_; 163 ChromotingJniRuntime* jni_runtime_;
155 164
156 JniClient* jni_client_; 165 base::WeakPtr<JniClient> jni_client_;
166
167 base::WeakPtr<JniDisplayHandler> display_handler_;
168
169 base::WeakPtr<JniPairingSecretFetcher> secret_fetcher_;
157 170
158 // ID of the host we are connecting to. 171 // ID of the host we are connecting to.
159 std::string host_jid_; 172 std::string host_jid_;
160 173
161 protocol::ClientAuthenticationConfig client_auth_config_; 174 protocol::ClientAuthenticationConfig client_auth_config_;
162 175
163 std::string flags_; 176 std::string flags_;
164 177
165 // This group of variables is to be used on the network thread. 178 // This group of variables is to be used on the network thread.
166 std::unique_ptr<ClientContext> client_context_; 179 std::unique_ptr<ClientContext> client_context_;
167 std::unique_ptr<protocol::PerformanceTracker> perf_tracker_; 180 std::unique_ptr<protocol::PerformanceTracker> perf_tracker_;
168 std::unique_ptr<JniFrameConsumer> view_; 181 std::unique_ptr<JniFrameConsumer> view_;
169 std::unique_ptr<protocol::VideoRenderer> video_renderer_; 182 std::unique_ptr<protocol::VideoRenderer> video_renderer_;
170 std::unique_ptr<ChromotingClient> client_; 183 std::unique_ptr<ChromotingClient> client_;
171 XmppSignalStrategy::XmppServerConfig xmpp_config_; 184 XmppSignalStrategy::XmppServerConfig xmpp_config_;
172 std::unique_ptr<XmppSignalStrategy> signaling_; // Must outlive client_ 185 std::unique_ptr<XmppSignalStrategy> signaling_; // Must outlive client_
173 protocol::ThirdPartyTokenFetchedCallback third_party_token_fetched_callback_; 186 protocol::ThirdPartyTokenFetchedCallback third_party_token_fetched_callback_;
174 187
175 // Pass this the user's PIN once we have it. To be assigned and accessed on
176 // the UI thread, but must be posted to the network thread to call it.
177 protocol::SecretFetchedCallback pin_callback_;
178
179 // Indicates whether to establish a new pairing with this host. This is 188 // Indicates whether to establish a new pairing with this host. This is
180 // modified in ProvideSecret(), but thereafter to be used only from the 189 // modified in ProvideSecret(), but thereafter to be used only from the
181 // network thread. (This is safe because ProvideSecret() is invoked at most 190 // network thread. (This is safe because ProvideSecret() is invoked at most
182 // once per run, and always before any reference to this flag.) 191 // once per run, and always before any reference to this flag.)
183 bool create_pairing_ = false; 192 bool create_pairing_ = false;
184 193
185 // The device name to appear in the paired-clients list. Accessed on the 194 // The device name to appear in the paired-clients list. Accessed on the
186 // network thread. 195 // network thread.
187 std::string device_name_; 196 std::string device_name_;
188 197
189 // If this is true, performance statistics will be periodically written to 198 // If this is true, performance statistics will be periodically written to
190 // the Android log. Used on the network thread. 199 // the Android log. Used on the network thread.
191 bool stats_logging_enabled_ = false; 200 bool stats_logging_enabled_ = false;
192 201
193 // The set of capabilities supported by the client. Accessed on the network 202 // The set of capabilities supported by the client. Accessed on the network
194 // thread. Once SetCapabilities() is called, this will contain the negotiated 203 // thread. Once SetCapabilities() is called, this will contain the negotiated
195 // set of capabilities for this remoting session. 204 // set of capabilities for this remoting session.
196 std::string capabilities_; 205 std::string capabilities_;
197 206
198 // Indicates whether the client is connected to the host. Used on network 207 // Indicates whether the client is connected to the host. Used on network
199 // thread. 208 // thread.
200 bool connected_ = false; 209 bool connected_ = false;
201 210
202 friend class base::RefCountedThreadSafe<ChromotingJniInstance>;
203
204 base::WeakPtrFactory<ChromotingJniInstance> weak_factory_; 211 base::WeakPtrFactory<ChromotingJniInstance> weak_factory_;
205 212
206 DISALLOW_COPY_AND_ASSIGN(ChromotingJniInstance); 213 DISALLOW_COPY_AND_ASSIGN(ChromotingJniInstance);
207 }; 214 };
208 215
209 } // namespace remoting 216 } // namespace remoting
210 217
211 #endif 218 #endif
OLDNEW
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/jni/Display.java ('k') | remoting/client/jni/chromoting_jni_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698