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