| OLD | NEW |
| 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 { |
| 45 public: |
| 46 virtual ~Delegate() {} |
| 47 |
| 48 // Notifies Java code of the current connection status. |
| 49 virtual void OnConnectionState(protocol::ConnectionToHost::State state, |
| 50 protocol::ErrorCode error) = 0; |
| 51 |
| 52 // Saves new pairing credentials to permanent storage. |
| 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. |
| 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 ChromotingSession(base::WeakPtr<ChromotingSession::Delegate> delegate, |
| 49 // unpaired host, pass in |pairing_id| and |pairing_secret| as empty strings. | 74 std::unique_ptr<protocol::CursorShapeStub> cursor_stub, |
| 50 ChromotingJniInstance(base::WeakPtr<JniClient> jni_client, | 75 std::unique_ptr<protocol::VideoRenderer> video_renderer, |
| 51 base::WeakPtr<JniPairingSecretFetcher> secret_fetcher, | 76 base::WeakPtr<protocol::AudioStub> audio_player, |
| 52 std::unique_ptr<protocol::CursorShapeStub> cursor_stub, | 77 const ConnectToHostInfo& info, |
| 53 std::unique_ptr<protocol::VideoRenderer> video_renderer, | 78 protocol::ClientAuthenticationConfig& client_auth_config); |
| 54 const ConnectToHostInfo& info); | |
| 55 | 79 |
| 56 ~ChromotingJniInstance() override; | 80 ~ChromotingSession() override; |
| 57 | 81 |
| 58 // Starts the connection. Can be called on any thread. | 82 // Starts the connection. Can be called on any thread. |
| 59 void Connect(); | 83 void Connect(); |
| 60 | 84 |
| 61 // Terminates the current connection (if it hasn't already failed) and cleans | 85 // 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. | 86 // up. The instance will no longer be valid after calling this function. |
| 63 // Must be called before destruction. | 87 // Must be called before destruction. |
| 64 void Disconnect(); | 88 void Disconnect(); |
| 65 | 89 |
| 66 // Requests the android app to fetch a third-party token. | 90 // Requests the android app to fetch a third-party token. |
| 67 void FetchThirdPartyToken( | 91 void FetchThirdPartyToken( |
| 68 const std::string& host_public_key, | 92 const std::string& host_public_key, |
| 69 const std::string& token_url, | 93 const std::string& token_url, |
| 70 const std::string& scope, | 94 const std::string& scope, |
| 71 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback); | 95 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback); |
| 72 | 96 |
| 73 // Called by the android app when the token is fetched. | 97 // Called by the android app when the token is fetched. |
| 74 void HandleOnThirdPartyTokenFetched(const std::string& token, | 98 void HandleOnThirdPartyTokenFetched(const std::string& token, |
| 75 const std::string& shared_secret); | 99 const std::string& shared_secret); |
| 76 | 100 |
| 77 // Provides the user's PIN and resumes the host authentication attempt. Call | 101 // 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, | 102 // 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()). | 103 // but only after the UI has been asked to provide a PIN (via FetchSecret()). |
| 80 void ProvideSecret(const std::string& pin, bool create_pair, | 104 void ProvideSecret(const std::string& pin, |
| 105 bool create_pair, |
| 81 const std::string& device_name); | 106 const std::string& device_name); |
| 82 | 107 |
| 83 // Moves the host's cursor to the specified coordinates, optionally with some | 108 // 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. | 109 // mouse button depressed. If |button| is BUTTON_UNDEFINED, no click is made. |
| 85 void SendMouseEvent(int x, int y, | 110 void SendMouseEvent(int x, |
| 111 int y, |
| 86 protocol::MouseEvent_MouseButton button, | 112 protocol::MouseEvent_MouseButton button, |
| 87 bool button_down); | 113 bool button_down); |
| 88 void SendMouseWheelEvent(int delta_x, int delta_y); | 114 void SendMouseWheelEvent(int delta_x, int delta_y); |
| 89 | 115 |
| 90 // Sends the provided keyboard scan code to the host. | 116 // Sends the provided keyboard scan code to the host. |
| 91 bool SendKeyEvent(int scan_code, int key_code, bool key_down); | 117 bool SendKeyEvent(int scan_code, int key_code, bool key_down); |
| 92 | 118 |
| 93 void SendTextEvent(const std::string& text); | 119 void SendTextEvent(const std::string& text); |
| 94 | 120 |
| 95 // Sends the provided touch event payload to the host. | 121 // Sends the provided touch event payload to the host. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 112 void SetDesktopSize(const webrtc::DesktopSize& size, | 138 void SetDesktopSize(const webrtc::DesktopSize& size, |
| 113 const webrtc::DesktopVector& dpi) override; | 139 const webrtc::DesktopVector& dpi) override; |
| 114 protocol::ClipboardStub* GetClipboardStub() override; | 140 protocol::ClipboardStub* GetClipboardStub() override; |
| 115 protocol::CursorShapeStub* GetCursorShapeStub() override; | 141 protocol::CursorShapeStub* GetCursorShapeStub() override; |
| 116 | 142 |
| 117 // CursorShapeStub implementation. | 143 // CursorShapeStub implementation. |
| 118 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override; | 144 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override; |
| 119 | 145 |
| 120 // Get the weak pointer of the instance. Please only use it on the network | 146 // Get the weak pointer of the instance. Please only use it on the network |
| 121 // thread. | 147 // thread. |
| 122 base::WeakPtr<ChromotingJniInstance> GetWeakPtr(); | 148 base::WeakPtr<ChromotingSession> GetWeakPtr(); |
| 123 | 149 |
| 124 private: | 150 private: |
| 125 void ConnectToHostOnNetworkThread(); | 151 void ConnectToHostOnNetworkThread(); |
| 126 | 152 |
| 127 // Sets the device name. Can be called on any thread. | 153 // Sets the device name. Can be called on any thread. |
| 128 void SetDeviceName(const std::string& device_name); | 154 void SetDeviceName(const std::string& device_name); |
| 129 | 155 |
| 130 void SendKeyEventInternal(int usb_key_code, bool key_down); | 156 void SendKeyEventInternal(int usb_key_code, bool key_down); |
| 131 | 157 |
| 132 // Enables or disables periodic logging of performance statistics. Called on | 158 // Enables or disables periodic logging of performance statistics. Called on |
| 133 // the network thread. | 159 // the network thread. |
| 134 void EnableStatsLogging(bool enabled); | 160 void EnableStatsLogging(bool enabled); |
| 135 | 161 |
| 136 // If logging is enabled, logs the current connection statistics, and | 162 // If logging is enabled, logs the current connection statistics, and |
| 137 // triggers another call to this function after the logging time interval. | 163 // triggers another call to this function after the logging time interval. |
| 138 // Called on the network thread. | 164 // Called on the network thread. |
| 139 void LogPerfStats(); | 165 void LogPerfStats(); |
| 140 | 166 |
| 141 // Releases the resource in the right order. | 167 // Releases the resource in the right order. |
| 142 void ReleaseResources(); | 168 void ReleaseResources(); |
| 143 | 169 |
| 144 // Used to obtain task runner references. | 170 // Used to obtain task runner references. |
| 145 ChromotingClientRuntime* runtime_; | 171 ChromotingClientRuntime* runtime_; |
| 146 | 172 |
| 147 base::WeakPtr<JniClient> jni_client_; | 173 // Called on UI thread. |
| 148 | 174 base::WeakPtr<ChromotingSession::Delegate> delegate_; |
| 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 // Called on UI Thread. |
| 189 base::WeakPtr<protocol::AudioStub> audio_player_; |
| 166 | 190 |
| 167 // Indicates whether to establish a new pairing with this host. This is | 191 // Indicates whether to establish a new pairing with this host. This is |
| 168 // modified in ProvideSecret(), but thereafter to be used only from the | 192 // modified in ProvideSecret(), but thereafter to be used only from the |
| 169 // network thread. (This is safe because ProvideSecret() is invoked at most | 193 // network thread. (This is safe because ProvideSecret() is invoked at most |
| 170 // once per run, and always before any reference to this flag.) | 194 // once per run, and always before any reference to this flag.) |
| 171 bool create_pairing_ = false; | 195 bool create_pairing_ = false; |
| 172 | 196 |
| 173 // The device name to appear in the paired-clients list. Accessed on the | 197 // The device name to appear in the paired-clients list. Accessed on the |
| 174 // network thread. | 198 // network thread. |
| 175 std::string device_name_; | 199 std::string device_name_; |
| 176 | 200 |
| 177 // If this is true, performance statistics will be periodically written to | 201 // If this is true, performance statistics will be periodically written to |
| 178 // the Android log. Used on the network thread. | 202 // the Android log. Used on the network thread. |
| 179 bool stats_logging_enabled_ = false; | 203 bool stats_logging_enabled_ = false; |
| 180 | 204 |
| 181 // The set of capabilities supported by the client. Accessed on the network | 205 // The set of capabilities supported by the client. Accessed on the network |
| 182 // thread. Once SetCapabilities() is called, this will contain the negotiated | 206 // thread. Once SetCapabilities() is called, this will contain the negotiated |
| 183 // set of capabilities for this remoting session. | 207 // set of capabilities for this remoting session. |
| 184 std::string capabilities_; | 208 std::string capabilities_; |
| 185 | 209 |
| 186 // Indicates whether the client is connected to the host. Used on network | 210 // Indicates whether the client is connected to the host. Used on network |
| 187 // thread. | 211 // thread. |
| 188 bool connected_ = false; | 212 bool connected_ = false; |
| 189 | 213 |
| 190 std::unique_ptr<ClientTelemetryLogger> logger_; | 214 std::unique_ptr<ClientTelemetryLogger> logger_; |
| 191 | 215 |
| 192 base::WeakPtr<ChromotingJniInstance> weak_ptr_; | 216 base::WeakPtr<ChromotingSession> weak_ptr_; |
| 193 base::WeakPtrFactory<ChromotingJniInstance> weak_factory_; | 217 base::WeakPtrFactory<ChromotingSession> weak_factory_; |
| 194 | 218 |
| 195 DISALLOW_COPY_AND_ASSIGN(ChromotingJniInstance); | 219 DISALLOW_COPY_AND_ASSIGN(ChromotingSession); |
| 196 }; | 220 }; |
| 197 | 221 |
| 198 } // namespace remoting | 222 } // namespace remoting |
| 199 | 223 |
| 200 #endif // REMOTING_CLIENT_JNI_CHROMOTING_JNI_INSTANCE_H_ | 224 #endif // REMOTING_CLIENT_CHROMOTING_SESSION_H_ |
| OLD | NEW |