| 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_RUNTIME_H_ | 5 #ifndef REMOTING_CLIENT_JNI_CHROMOTING_JNI_RUNTIME_H_ |
| 6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_RUNTIME_H_ | 6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_RUNTIME_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 52 } |
| 53 | 53 |
| 54 // The runtime handles authentication and the caller should not call SetAuth*. | 54 // The runtime handles authentication and the caller should not call SetAuth*. |
| 55 // The runtime itself will not send out any logs. Used on the network thread. | 55 // The runtime itself will not send out any logs. Used on the network thread. |
| 56 ClientTelemetryLogger* logger() { | 56 ClientTelemetryLogger* logger() { |
| 57 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); | 57 DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 58 DCHECK(logger_); | 58 DCHECK(logger_); |
| 59 return logger_.get(); | 59 return logger_.get(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Initiates a connection with the specified host. Only call when a host | |
| 63 // connection is active (i.e. between a call to Connect() and the | |
| 64 // corresponding call to Disconnect()). To skip the attempt at pair-based | |
| 65 // authentication, leave |pairing_id| and |pairing_secret| as empty strings. | |
| 66 void ConnectToHost(const std::string& username, | |
| 67 const std::string& auth_token, | |
| 68 const std::string& host_jid, | |
| 69 const std::string& host_id, | |
| 70 const std::string& host_pubkey, | |
| 71 const std::string& pairing_id, | |
| 72 const std::string& pairing_secret, | |
| 73 const std::string& capabilities, | |
| 74 const std::string& flags); | |
| 75 | |
| 76 // Terminates any ongoing connection attempt and cleans up by nullifying | |
| 77 // |session_|. This is a no-op unless |session| is currently non-null. | |
| 78 void DisconnectFromHost(); | |
| 79 | |
| 80 // Returns the client for the currently-active session. Do not call if | |
| 81 // |session| is null. | |
| 82 scoped_refptr<ChromotingJniInstance> session() { | |
| 83 DCHECK(session_.get()); | |
| 84 return session_; | |
| 85 } | |
| 86 | |
| 87 // Notifies Java code of the current connection status. Call on UI thread. | |
| 88 void OnConnectionState(protocol::ConnectionToHost::State state, | |
| 89 protocol::ErrorCode error); | |
| 90 | |
| 91 // Pops up a dialog box asking the user to enter a PIN. Call on UI thread. | |
| 92 void DisplayAuthenticationPrompt(bool pairing_supported); | |
| 93 | |
| 94 // Saves new pairing credentials to permanent storage. Call on UI thread. | |
| 95 void CommitPairingCredentials(const std::string& host, | |
| 96 const std::string& id, | |
| 97 const std::string& secret); | |
| 98 | |
| 99 // Fetch OAuth token for the telemetry logger. Call on UI thread. | 62 // Fetch OAuth token for the telemetry logger. Call on UI thread. |
| 100 void FetchAuthToken(); | 63 void FetchAuthToken(); |
| 101 | 64 |
| 102 // Pops up a third party login page to fetch token required for | |
| 103 // authentication. Call on UI thread. | |
| 104 void FetchThirdPartyToken(const std::string& token_url, | |
| 105 const std::string& client_id, | |
| 106 const std::string& scope); | |
| 107 | |
| 108 // Pass on the set of negotiated capabilities to the client. | |
| 109 void SetCapabilities(const std::string& capabilities); | |
| 110 | |
| 111 // Passes on the deconstructed ExtensionMessage to the client to handle | |
| 112 // appropriately. | |
| 113 void HandleExtensionMessage(const std::string& type, | |
| 114 const std::string& message); | |
| 115 | |
| 116 // Creates a new Bitmap object to store a video frame. | |
| 117 base::android::ScopedJavaLocalRef<jobject> NewBitmap(int width, int height); | |
| 118 | |
| 119 // Updates video frame bitmap. |bitmap| must be an instance of | |
| 120 // android.graphics.Bitmap. Call on the display thread. | |
| 121 void UpdateFrameBitmap(jobject bitmap); | |
| 122 | |
| 123 // Updates cursor shape. Call on display thread. | |
| 124 void UpdateCursorShape(const protocol::CursorShapeInfo& cursor_shape); | |
| 125 | |
| 126 // Draws the latest image buffer onto the canvas. Call on the display thread. | |
| 127 void RedrawCanvas(); | |
| 128 | |
| 129 private: | 65 private: |
| 130 ChromotingJniRuntime(); | 66 ChromotingJniRuntime(); |
| 131 | 67 |
| 132 // Forces a DisconnectFromHost() in case there is any active or failed | 68 // Forces a DisconnectFromHost() in case there is any active or failed |
| 133 // connection, then proceeds to tear down the Chromium dependencies on which | 69 // connection, then proceeds to tear down the Chromium dependencies on which |
| 134 // all sessions depended. Because destruction only occurs at application exit | 70 // all sessions depended. Because destruction only occurs at application exit |
| 135 // after all connections have terminated, it is safe to make unretained | 71 // after all connections have terminated, it is safe to make unretained |
| 136 // cross-thread calls on the class. | 72 // cross-thread calls on the class. |
| 137 virtual ~ChromotingJniRuntime(); | 73 virtual ~ChromotingJniRuntime(); |
| 138 | 74 |
| 139 // Detaches JVM from the current thread, then signals. Doesn't own |waiter|. | 75 // Detaches JVM from the current thread, then signals. Doesn't own |waiter|. |
| 140 void DetachFromVmAndSignal(base::WaitableEvent* waiter); | 76 void DetachFromVmAndSignal(base::WaitableEvent* waiter); |
| 141 | 77 |
| 142 // Starts the logger on the network thread. | 78 // Starts the logger on the network thread. |
| 143 void StartLoggerOnNetworkThread(); | 79 void StartLoggerOnNetworkThread(); |
| 144 | 80 |
| 145 // Chromium code's connection to the app message loop. Once created the | 81 // Chromium code's connection to the app message loop. Once created the |
| 146 // MessageLoop will live for the life of the program. | 82 // MessageLoop will live for the life of the program. |
| 147 std::unique_ptr<base::MessageLoopForUI> ui_loop_; | 83 std::unique_ptr<base::MessageLoopForUI> ui_loop_; |
| 148 | 84 |
| 149 // Contains threads. | 85 // Contains threads. |
| 150 // | 86 // |
| 151 std::unique_ptr<ChromotingClientRuntime> runtime_; | 87 std::unique_ptr<ChromotingClientRuntime> runtime_; |
| 152 | 88 |
| 153 // Contains all connection-specific state. | |
| 154 scoped_refptr<ChromotingJniInstance> session_; | |
| 155 | |
| 156 // For logging session stage changes and stats. | 89 // For logging session stage changes and stats. |
| 157 std::unique_ptr<ClientTelemetryLogger> logger_; | 90 std::unique_ptr<ClientTelemetryLogger> logger_; |
| 158 | 91 |
| 159 friend struct base::DefaultSingletonTraits<ChromotingJniRuntime>; | 92 friend struct base::DefaultSingletonTraits<ChromotingJniRuntime>; |
| 160 | 93 |
| 161 DISALLOW_COPY_AND_ASSIGN(ChromotingJniRuntime); | 94 DISALLOW_COPY_AND_ASSIGN(ChromotingJniRuntime); |
| 162 }; | 95 }; |
| 163 | 96 |
| 164 } // namespace remoting | 97 } // namespace remoting |
| 165 | 98 |
| 166 #endif | 99 #endif |
| OLD | NEW |