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

Side by Side Diff: remoting/client/chromoting_session.h

Issue 2753963002: Refactoring and rewriting the chromoting jni instance to be chromoting session. (Closed)
Patch Set: Pointer not obj. Created 3 years, 9 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_JNI_CHROMOTING_JNI_INSTANCE_H_ 5 #ifndef REMOTING_CLIENT_CHROMOTING_SESSION_H_
6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_INSTANCE_H_ 6 #define REMOTING_CLIENT_CHROMOTING_SESSION_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "remoting/client/chromoting_client.h" 15 #include "remoting/client/chromoting_client.h"
16 #include "remoting/client/client_context.h" 16 #include "remoting/client/client_context.h"
17 #include "remoting/client/client_telemetry_logger.h" 17 #include "remoting/client/client_telemetry_logger.h"
18 #include "remoting/client/client_user_interface.h" 18 #include "remoting/client/client_user_interface.h"
19 #include "remoting/client/jni/connect_to_host_info.h" 19 #include "remoting/client/connect_to_host_info.h"
20 #include "remoting/proto/control.pb.h" 20 #include "remoting/proto/control.pb.h"
21 #include "remoting/proto/event.pb.h" 21 #include "remoting/proto/event.pb.h"
22 #include "remoting/protocol/clipboard_stub.h" 22 #include "remoting/protocol/clipboard_stub.h"
23 #include "remoting/protocol/cursor_shape_stub.h" 23 #include "remoting/protocol/cursor_shape_stub.h"
24 #include "remoting/signaling/xmpp_signal_strategy.h" 24 #include "remoting/signaling/xmpp_signal_strategy.h"
25 25
26 namespace remoting { 26 namespace remoting {
27 27
28 namespace protocol { 28 namespace protocol {
29 class AudioStub;
29 class ClipboardEvent; 30 class ClipboardEvent;
30 class PerformanceTracker; 31 class PerformanceTracker;
31 class VideoRenderer; 32 class VideoRenderer;
32 } // namespace protocol 33 } // namespace protocol
33 34
34 class AudioPlayerAndroid;
35 class ChromotingClientRuntime; 35 class ChromotingClientRuntime;
36 class JniClient;
37 class JniPairingSecretFetcher;
38 36
39 // ChromotingJniInstance is scoped to the session. 37 // ChromotingSession is scoped to the session.
40 // This class is Created on the UI thread but thereafter it is used and 38 // 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 39 // destroyed on the network thread. Except where indicated, all methods are
42 // called on the network thread. 40 // called on the network thread.
43 class ChromotingJniInstance 41 class ChromotingSession : public ClientUserInterface,
44 : public ClientUserInterface, 42 public protocol::ClipboardStub {
45 public protocol::ClipboardStub {
46 public: 43 public:
44 class Delegate {
Yuwei 2017/03/21 20:40:29 Please comment that all functions will be called o
nicholss 2017/03/29 20:32:36 Done.
Yuwei 2017/03/29 21:52:15 Sorry. What I meant is all functions of the Delega
45 public:
46 virtual ~Delegate() {}
47
48 // Notifies Java code of the current connection status. Call on UI thread.
49 virtual void OnConnectionState(protocol::ConnectionToHost::State state,
50 protocol::ErrorCode error) = 0;
51
52 // Saves new pairing credentials to permanent storage. Call on UI thread.
53 virtual void CommitPairingCredentials(const std::string& host,
54 const std::string& id,
55 const std::string& secret) = 0;
56
57 // Pops up a third party login page to fetch token required for
58 // authentication. Called on UI thread.
59 virtual void FetchThirdPartyToken(const std::string& token_url,
60 const std::string& client_id,
61 const std::string& scope) = 0;
62
63 // Pass on the set of negotiated capabilities to the client.
64 virtual void SetCapabilities(const std::string& capabilities) = 0;
65
66 // Passes on the deconstructed ExtensionMessage to the client to handle
67 // appropriately.
68 virtual void HandleExtensionMessage(const std::string& type,
69 const std::string& message) = 0;
70 };
71
47 // Initiates a connection with the specified host. Call from the UI thread. 72 // Initiates a connection with the specified host. Call from the UI thread.
48 // The instance does not take ownership of |jni_runtime|. To connect with an 73 // The session does not take ownership of |delegate|.
49 // unpaired host, pass in |pairing_id| and |pairing_secret| as empty strings. 74 ChromotingSession(ChromotingSession::Delegate* delegate,
Yuwei 2017/03/21 20:40:29 I guess you need a WeakPtr of the Delegate? You ha
nicholss 2017/03/29 20:32:36 base::WeakPtr acts funny some times with polymorph
50 ChromotingJniInstance(base::WeakPtr<JniClient> jni_client, 75 std::unique_ptr<protocol::CursorShapeStub> cursor_stub,
51 base::WeakPtr<JniPairingSecretFetcher> secret_fetcher, 76 std::unique_ptr<protocol::VideoRenderer> video_renderer,
52 std::unique_ptr<protocol::CursorShapeStub> cursor_stub, 77 base::WeakPtr<protocol::AudioStub> audio_player,
53 std::unique_ptr<protocol::VideoRenderer> video_renderer, 78 const ConnectToHostInfo& info,
54 const ConnectToHostInfo& info); 79 protocol::ClientAuthenticationConfig& client_auth_config);
55 80
56 ~ChromotingJniInstance() override; 81 ~ChromotingSession() override;
57 82
58 // Starts the connection. Can be called on any thread. 83 // Starts the connection. Can be called on any thread.
59 void Connect(); 84 void Connect();
60 85
61 // Terminates the current connection (if it hasn't already failed) and cleans 86 // Terminates the current connection (if it hasn't already failed) and cleans
62 // up. The instance will no longer be valid after calling this function. 87 // up. The instance will no longer be valid after calling this function.
63 // Must be called before destruction. 88 // Must be called before destruction.
64 void Disconnect(); 89 void Disconnect();
65 90
66 // Requests the android app to fetch a third-party token. 91 // Requests the android app to fetch a third-party token.
67 void FetchThirdPartyToken( 92 void FetchThirdPartyToken(
68 const std::string& host_public_key, 93 const std::string& host_public_key,
69 const std::string& token_url, 94 const std::string& token_url,
70 const std::string& scope, 95 const std::string& scope,
71 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback); 96 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback);
72 97
73 // Called by the android app when the token is fetched. 98 // Called by the android app when the token is fetched.
74 void HandleOnThirdPartyTokenFetched(const std::string& token, 99 void HandleOnThirdPartyTokenFetched(const std::string& token,
75 const std::string& shared_secret); 100 const std::string& shared_secret);
76 101
77 // Provides the user's PIN and resumes the host authentication attempt. Call 102 // Provides the user's PIN and resumes the host authentication attempt. Call
78 // on the UI thread once the user has finished entering this PIN into the UI, 103 // on the UI thread once the user has finished entering this PIN into the UI,
79 // but only after the UI has been asked to provide a PIN (via FetchSecret()). 104 // but only after the UI has been asked to provide a PIN (via FetchSecret()).
80 void ProvideSecret(const std::string& pin, bool create_pair, 105 void ProvideSecret(const std::string& pin,
106 bool create_pair,
81 const std::string& device_name); 107 const std::string& device_name);
82 108
83 // Moves the host's cursor to the specified coordinates, optionally with some 109 // Moves the host's cursor to the specified coordinates, optionally with some
84 // mouse button depressed. If |button| is BUTTON_UNDEFINED, no click is made. 110 // mouse button depressed. If |button| is BUTTON_UNDEFINED, no click is made.
85 void SendMouseEvent(int x, int y, 111 void SendMouseEvent(int x,
112 int y,
86 protocol::MouseEvent_MouseButton button, 113 protocol::MouseEvent_MouseButton button,
87 bool button_down); 114 bool button_down);
88 void SendMouseWheelEvent(int delta_x, int delta_y); 115 void SendMouseWheelEvent(int delta_x, int delta_y);
89 116
90 // Sends the provided keyboard scan code to the host. 117 // Sends the provided keyboard scan code to the host.
91 bool SendKeyEvent(int scan_code, int key_code, bool key_down); 118 bool SendKeyEvent(int scan_code, int key_code, bool key_down);
92 119
93 void SendTextEvent(const std::string& text); 120 void SendTextEvent(const std::string& text);
94 121
95 // Sends the provided touch event payload to the host. 122 // Sends the provided touch event payload to the host.
(...skipping 16 matching lines...) Expand all
112 void SetDesktopSize(const webrtc::DesktopSize& size, 139 void SetDesktopSize(const webrtc::DesktopSize& size,
113 const webrtc::DesktopVector& dpi) override; 140 const webrtc::DesktopVector& dpi) override;
114 protocol::ClipboardStub* GetClipboardStub() override; 141 protocol::ClipboardStub* GetClipboardStub() override;
115 protocol::CursorShapeStub* GetCursorShapeStub() override; 142 protocol::CursorShapeStub* GetCursorShapeStub() override;
116 143
117 // CursorShapeStub implementation. 144 // CursorShapeStub implementation.
118 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override; 145 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override;
119 146
120 // Get the weak pointer of the instance. Please only use it on the network 147 // Get the weak pointer of the instance. Please only use it on the network
121 // thread. 148 // thread.
122 base::WeakPtr<ChromotingJniInstance> GetWeakPtr(); 149 base::WeakPtr<ChromotingSession> GetWeakPtr();
123 150
124 private: 151 private:
125 void ConnectToHostOnNetworkThread(); 152 void ConnectToHostOnNetworkThread();
126 153
127 // Sets the device name. Can be called on any thread. 154 // Sets the device name. Can be called on any thread.
128 void SetDeviceName(const std::string& device_name); 155 void SetDeviceName(const std::string& device_name);
129 156
130 void SendKeyEventInternal(int usb_key_code, bool key_down); 157 void SendKeyEventInternal(int usb_key_code, bool key_down);
131 158
132 // Enables or disables periodic logging of performance statistics. Called on 159 // Enables or disables periodic logging of performance statistics. Called on
133 // the network thread. 160 // the network thread.
134 void EnableStatsLogging(bool enabled); 161 void EnableStatsLogging(bool enabled);
135 162
136 // If logging is enabled, logs the current connection statistics, and 163 // If logging is enabled, logs the current connection statistics, and
137 // triggers another call to this function after the logging time interval. 164 // triggers another call to this function after the logging time interval.
138 // Called on the network thread. 165 // Called on the network thread.
139 void LogPerfStats(); 166 void LogPerfStats();
140 167
141 // Releases the resource in the right order. 168 // Releases the resource in the right order.
142 void ReleaseResources(); 169 void ReleaseResources();
143 170
144 // Used to obtain task runner references. 171 // Used to obtain task runner references.
145 ChromotingClientRuntime* runtime_; 172 ChromotingClientRuntime* runtime_;
146 173
147 base::WeakPtr<JniClient> jni_client_; 174 ChromotingSession::Delegate* delegate_;
Yuwei 2017/03/21 20:40:29 Why using raw pointer here? The delegate may have
nicholss 2017/03/29 20:32:36 Done.
148
149 base::WeakPtr<JniPairingSecretFetcher> secret_fetcher_;
150
151 ConnectToHostInfo connection_info_; 175 ConnectToHostInfo connection_info_;
152
153 protocol::ClientAuthenticationConfig client_auth_config_; 176 protocol::ClientAuthenticationConfig client_auth_config_;
154 177
155 // 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.
156 std::unique_ptr<ClientContext> client_context_; 179 std::unique_ptr<ClientContext> client_context_;
157 std::unique_ptr<protocol::PerformanceTracker> perf_tracker_; 180 std::unique_ptr<protocol::PerformanceTracker> perf_tracker_;
158 std::unique_ptr<protocol::CursorShapeStub> cursor_shape_stub_; 181 std::unique_ptr<protocol::CursorShapeStub> cursor_shape_stub_;
159 std::unique_ptr<protocol::VideoRenderer> video_renderer_; 182 std::unique_ptr<protocol::VideoRenderer> video_renderer_;
160 std::unique_ptr<ChromotingClient> client_; 183 std::unique_ptr<ChromotingClient> client_;
161 XmppSignalStrategy::XmppServerConfig xmpp_config_; 184 XmppSignalStrategy::XmppServerConfig xmpp_config_;
162 std::unique_ptr<XmppSignalStrategy> signaling_; // Must outlive client_ 185 std::unique_ptr<XmppSignalStrategy> signaling_; // Must outlive client_
163 protocol::ThirdPartyTokenFetchedCallback third_party_token_fetched_callback_; 186 protocol::ThirdPartyTokenFetchedCallback third_party_token_fetched_callback_;
164 187
165 std::unique_ptr<AudioPlayerAndroid> audio_player_; 188 base::WeakPtr<protocol::AudioStub> audio_player_;
166 189
167 // Indicates whether to establish a new pairing with this host. This is 190 // Indicates whether to establish a new pairing with this host. This is
168 // modified in ProvideSecret(), but thereafter to be used only from the 191 // modified in ProvideSecret(), but thereafter to be used only from the
169 // network thread. (This is safe because ProvideSecret() is invoked at most 192 // network thread. (This is safe because ProvideSecret() is invoked at most
170 // once per run, and always before any reference to this flag.) 193 // once per run, and always before any reference to this flag.)
171 bool create_pairing_ = false; 194 bool create_pairing_ = false;
172 195
173 // The device name to appear in the paired-clients list. Accessed on the 196 // The device name to appear in the paired-clients list. Accessed on the
174 // network thread. 197 // network thread.
175 std::string device_name_; 198 std::string device_name_;
176 199
177 // If this is true, performance statistics will be periodically written to 200 // If this is true, performance statistics will be periodically written to
178 // the Android log. Used on the network thread. 201 // the Android log. Used on the network thread.
179 bool stats_logging_enabled_ = false; 202 bool stats_logging_enabled_ = false;
180 203
181 // The set of capabilities supported by the client. Accessed on the network 204 // The set of capabilities supported by the client. Accessed on the network
182 // thread. Once SetCapabilities() is called, this will contain the negotiated 205 // thread. Once SetCapabilities() is called, this will contain the negotiated
183 // set of capabilities for this remoting session. 206 // set of capabilities for this remoting session.
184 std::string capabilities_; 207 std::string capabilities_;
185 208
186 // Indicates whether the client is connected to the host. Used on network 209 // Indicates whether the client is connected to the host. Used on network
187 // thread. 210 // thread.
188 bool connected_ = false; 211 bool connected_ = false;
189 212
190 std::unique_ptr<ClientTelemetryLogger> logger_; 213 std::unique_ptr<ClientTelemetryLogger> logger_;
191 214
192 base::WeakPtr<ChromotingJniInstance> weak_ptr_; 215 base::WeakPtr<ChromotingSession> weak_ptr_;
193 base::WeakPtrFactory<ChromotingJniInstance> weak_factory_; 216 base::WeakPtrFactory<ChromotingSession> weak_factory_;
194 217
195 DISALLOW_COPY_AND_ASSIGN(ChromotingJniInstance); 218 DISALLOW_COPY_AND_ASSIGN(ChromotingSession);
196 }; 219 };
197 220
198 } // namespace remoting 221 } // namespace remoting
199 222
200 #endif // REMOTING_CLIENT_JNI_CHROMOTING_JNI_INSTANCE_H_ 223 #endif // REMOTING_CLIENT_CHROMOTING_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698