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

Side by Side Diff: remoting/client/jni/chromoting_jni_instance.cc

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
« no previous file with comments | « remoting/client/jni/chromoting_jni_instance.h ('k') | remoting/client/jni/jni_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "remoting/client/jni/chromoting_jni_instance.h" 5 #include "remoting/client/jni/chromoting_jni_instance.h"
6 6
7 #include <android/log.h> 7 #include <android/log.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility>
11
12 #include "base/bind.h" 10 #include "base/bind.h"
13 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
14 #include "base/format_macros.h" 12 #include "base/format_macros.h"
15 #include "base/logging.h" 13 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
17 #include "jingle/glue/thread_wrapper.h" 15 #include "jingle/glue/thread_wrapper.h"
18 #include "net/socket/client_socket_factory.h" 16 #include "net/socket/client_socket_factory.h"
19 #include "remoting/base/chromium_url_request.h" 17 #include "remoting/base/chromium_url_request.h"
20 #include "remoting/client/audio_player_android.h" 18 #include "remoting/client/audio_player_android.h"
21 #include "remoting/client/client_telemetry_logger.h" 19 #include "remoting/client/client_telemetry_logger.h"
22 #include "remoting/client/jni/android_keymap.h" 20 #include "remoting/client/jni/android_keymap.h"
23 #include "remoting/client/jni/chromoting_jni_runtime.h" 21 #include "remoting/client/jni/chromoting_jni_runtime.h"
24 #include "remoting/client/jni/jni_client.h" 22 #include "remoting/client/jni/jni_client.h"
23 #include "remoting/client/jni/jni_display_handler.h"
25 #include "remoting/client/jni/jni_frame_consumer.h" 24 #include "remoting/client/jni/jni_frame_consumer.h"
25 #include "remoting/client/jni/jni_pairing_secret_fetcher.h"
26 #include "remoting/client/software_video_renderer.h" 26 #include "remoting/client/software_video_renderer.h"
27 #include "remoting/protocol/chromium_port_allocator_factory.h" 27 #include "remoting/protocol/chromium_port_allocator_factory.h"
28 #include "remoting/protocol/chromium_socket_factory.h" 28 #include "remoting/protocol/chromium_socket_factory.h"
29 #include "remoting/protocol/client_authentication_config.h" 29 #include "remoting/protocol/client_authentication_config.h"
30 #include "remoting/protocol/host_stub.h" 30 #include "remoting/protocol/host_stub.h"
31 #include "remoting/protocol/network_settings.h" 31 #include "remoting/protocol/network_settings.h"
32 #include "remoting/protocol/performance_tracker.h" 32 #include "remoting/protocol/performance_tracker.h"
33 #include "remoting/protocol/transport_context.h" 33 #include "remoting/protocol/transport_context.h"
34 #include "remoting/signaling/server_log_entry.h" 34 #include "remoting/signaling/server_log_entry.h"
35 #include "ui/events/keycodes/dom/keycode_converter.h" 35 #include "ui/events/keycodes/dom/keycode_converter.h"
36 36
37 namespace remoting { 37 namespace remoting {
38 38
39 namespace { 39 namespace {
40 40
41 // TODO(solb) Move into location shared with client plugin. 41 // TODO(solb) Move into location shared with client plugin.
42 const char* const kXmppServer = "talk.google.com"; 42 const char* const kXmppServer = "talk.google.com";
43 const int kXmppPort = 5222; 43 const int kXmppPort = 5222;
44 const bool kXmppUseTls = true; 44 const bool kXmppUseTls = true;
45 45
46 // Interval at which to log performance statistics, if enabled. 46 // Interval at which to log performance statistics, if enabled.
47 const int kPerfStatsIntervalMs = 60000; 47 const int kPerfStatsIntervalMs = 60000;
48 48
49 } 49 }
50 50
51 ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, 51 ChromotingJniInstance::ChromotingJniInstance(
52 JniClient* jni_client, 52 ChromotingJniRuntime* jni_runtime,
53 const std::string& username, 53 base::WeakPtr<JniClient> jni_client,
54 const std::string& auth_token, 54 base::WeakPtr<JniDisplayHandler> display,
55 const std::string& host_jid, 55 base::WeakPtr<JniPairingSecretFetcher> secret_fetcher,
56 const std::string& host_id, 56 const std::string& username,
57 const std::string& host_pubkey, 57 const std::string& auth_token,
58 const std::string& pairing_id, 58 const std::string& host_jid,
59 const std::string& pairing_secret, 59 const std::string& host_id,
60 const std::string& capabilities, 60 const std::string& host_pubkey,
61 const std::string& flags) 61 const std::string& pairing_id,
62 const std::string& pairing_secret,
63 const std::string& capabilities,
64 const std::string& flags)
62 : jni_runtime_(jni_runtime), 65 : jni_runtime_(jni_runtime),
63 jni_client_(jni_client), 66 jni_client_(jni_client),
67 display_handler_(display),
68 secret_fetcher_(secret_fetcher),
64 host_jid_(host_jid), 69 host_jid_(host_jid),
65 flags_(flags), 70 flags_(flags),
66 capabilities_(capabilities), 71 capabilities_(capabilities),
67 weak_factory_(this) { 72 weak_factory_(this) {
68 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); 73 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread());
69 74
70 // Initialize XMPP config. 75 // Initialize XMPP config.
71 xmpp_config_.host = kXmppServer; 76 xmpp_config_.host = kXmppServer;
72 xmpp_config_.port = kXmppPort; 77 xmpp_config_.port = kXmppPort;
73 xmpp_config_.use_tls = kXmppUseTls; 78 xmpp_config_.use_tls = kXmppUseTls;
74 xmpp_config_.username = username; 79 xmpp_config_.username = username;
75 xmpp_config_.auth_token = auth_token; 80 xmpp_config_.auth_token = auth_token;
76 81
77 client_auth_config_.host_id = host_id; 82 client_auth_config_.host_id = host_id;
78 client_auth_config_.pairing_client_id = pairing_id; 83 client_auth_config_.pairing_client_id = pairing_id;
79 client_auth_config_.pairing_secret = pairing_secret; 84 client_auth_config_.pairing_secret = pairing_secret;
80 client_auth_config_.fetch_secret_callback = base::Bind( 85 client_auth_config_.fetch_secret_callback =
81 &ChromotingJniInstance::FetchSecret, weak_factory_.GetWeakPtr()); 86 base::Bind(&ChromotingJniInstance::FetchSecret, GetWeakPtr());
82 client_auth_config_.fetch_third_party_token_callback = 87 client_auth_config_.fetch_third_party_token_callback = base::Bind(
83 base::Bind(&ChromotingJniInstance::FetchThirdPartyToken, 88 &ChromotingJniInstance::FetchThirdPartyToken, GetWeakPtr(), host_pubkey);
84 weak_factory_.GetWeakPtr(), host_pubkey); 89
90 // Post a task to start connection
91 jni_runtime_->network_task_runner()->PostTask(
92 FROM_HERE,
93 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread,
94 GetWeakPtr()));
85 } 95 }
86 96
87 ChromotingJniInstance::~ChromotingJniInstance() { 97 ChromotingJniInstance::~ChromotingJniInstance() {
88 // This object is ref-counted, so this dtor can execute on any thread. 98 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
89 // Ensure that all these objects have been freed already, so they are not 99 if (client_) {
90 // destroyed on some random thread. 100 ReleaseResources();
91 DCHECK(!view_); 101 }
92 DCHECK(!client_context_);
93 DCHECK(!video_renderer_);
94 DCHECK(!client_);
95 DCHECK(!signaling_);
96 } 102 }
97 103
98 void ChromotingJniInstance::Connect() { 104 void ChromotingJniInstance::Connect() {
99 if (jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 105 if (jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
100 ConnectToHostOnNetworkThread(); 106 ConnectToHostOnNetworkThread();
101 } else { 107 } else {
102 jni_runtime_->network_task_runner()->PostTask( 108 jni_runtime_->network_task_runner()->PostTask(
103 FROM_HERE, 109 FROM_HERE,
104 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, this)); 110 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread,
111 GetWeakPtr()));
105 } 112 }
106 } 113 }
107 114
108 void ChromotingJniInstance::Disconnect() { 115 void ChromotingJniInstance::Disconnect() {
109 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 116 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
110 jni_runtime_->network_task_runner()->PostTask( 117 jni_runtime_->network_task_runner()->PostTask(
111 FROM_HERE, 118 FROM_HERE,
112 base::Bind(&ChromotingJniInstance::Disconnect, this)); 119 base::Bind(&ChromotingJniInstance::Disconnect, GetWeakPtr()));
113 return; 120 return;
114 } 121 }
115 122
116 stats_logging_enabled_ = false; 123 stats_logging_enabled_ = false;
117 124
118 // User disconnection will not trigger OnConnectionState(Closed, OK). 125 // User disconnection will not trigger OnConnectionState(Closed, OK).
119 // Remote disconnection will trigger OnConnectionState(...) and later trigger 126 // Remote disconnection will trigger OnConnectionState(...) and later trigger
120 // Disconnect(). 127 // Disconnect().
121 if (connected_) { 128 if (connected_) {
122 jni_runtime_->logger()->LogSessionStateChange( 129 jni_runtime_->logger()->LogSessionStateChange(
123 ChromotingEvent::SessionState::CLOSED, 130 ChromotingEvent::SessionState::CLOSED,
124 ChromotingEvent::ConnectionError::NONE); 131 ChromotingEvent::ConnectionError::NONE);
125 connected_ = false; 132 connected_ = false;
126 } 133 }
127 134
128 // |client_| must be torn down before |signaling_|. 135 ReleaseResources();
129 client_.reset();
130 video_renderer_.reset();
131 view_.reset();
132 signaling_.reset();
133 perf_tracker_.reset();
134 client_context_.reset();
135
136 weak_factory_.InvalidateWeakPtrs();
137 } 136 }
138 137
139 void ChromotingJniInstance::FetchThirdPartyToken( 138 void ChromotingJniInstance::FetchThirdPartyToken(
140 const std::string& host_public_key, 139 const std::string& host_public_key,
141 const std::string& token_url, 140 const std::string& token_url,
142 const std::string& scope, 141 const std::string& scope,
143 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) { 142 const protocol::ThirdPartyTokenFetchedCallback& token_fetched_callback) {
144 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); 143 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
145 DCHECK(third_party_token_fetched_callback_.is_null()); 144 DCHECK(third_party_token_fetched_callback_.is_null());
146 145
147 __android_log_print(ANDROID_LOG_INFO, 146 __android_log_print(ANDROID_LOG_INFO,
148 "ThirdPartyAuth", 147 "ThirdPartyAuth",
149 "Fetching Third Party Token from user."); 148 "Fetching Third Party Token from user.");
150 149
151 third_party_token_fetched_callback_ = token_fetched_callback; 150 third_party_token_fetched_callback_ = token_fetched_callback;
152 jni_runtime_->ui_task_runner()->PostTask( 151 jni_runtime_->ui_task_runner()->PostTask(
153 FROM_HERE, base::Bind(&JniClient::FetchThirdPartyToken, 152 FROM_HERE, base::Bind(&JniClient::FetchThirdPartyToken, jni_client_,
154 jni_client_->GetWeakPtr(), token_url, 153 token_url, host_public_key, scope));
155 host_public_key, scope));
156 } 154 }
157 155
158 void ChromotingJniInstance::HandleOnThirdPartyTokenFetched( 156 void ChromotingJniInstance::HandleOnThirdPartyTokenFetched(
159 const std::string& token, 157 const std::string& token,
160 const std::string& shared_secret) { 158 const std::string& shared_secret) {
161 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); 159 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
162 160
163 __android_log_print( 161 __android_log_print(
164 ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched."); 162 ANDROID_LOG_INFO, "ThirdPartyAuth", "Third Party Token Fetched.");
165 163
166 if (!third_party_token_fetched_callback_.is_null()) { 164 if (!third_party_token_fetched_callback_.is_null()) {
167 base::ResetAndReturn(&third_party_token_fetched_callback_) 165 base::ResetAndReturn(&third_party_token_fetched_callback_)
168 .Run(token, shared_secret); 166 .Run(token, shared_secret);
169 } else { 167 } else {
170 __android_log_print( 168 __android_log_print(
171 ANDROID_LOG_WARN, 169 ANDROID_LOG_WARN,
172 "ThirdPartyAuth", 170 "ThirdPartyAuth",
173 "Ignored OnThirdPartyTokenFetched() without a pending fetch."); 171 "Ignored OnThirdPartyTokenFetched() without a pending fetch.");
174 } 172 }
175 } 173 }
176 174
177 void ChromotingJniInstance::ProvideSecret(const std::string& pin, 175 void ChromotingJniInstance::ProvideSecret(const std::string& pin,
178 bool create_pairing, 176 bool create_pairing,
179 const std::string& device_name) { 177 const std::string& device_name) {
180 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); 178 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread());
181 DCHECK(!pin_callback_.is_null()); 179
180 if (!secret_fetcher_) {
181 return;
182 }
182 183
183 create_pairing_ = create_pairing; 184 create_pairing_ = create_pairing;
184 185
185 if (create_pairing) 186 if (create_pairing)
186 SetDeviceName(device_name); 187 SetDeviceName(device_name);
187 188
188 jni_runtime_->network_task_runner()->PostTask(FROM_HERE, 189 secret_fetcher_->ProvideSecret(pin);
189 base::Bind(pin_callback_, pin));
190 }
191
192 void ChromotingJniInstance::RedrawDesktop() {
193 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) {
194 jni_runtime_->display_task_runner()->PostTask(
195 FROM_HERE,
196 base::Bind(&ChromotingJniInstance::RedrawDesktop, this));
197 return;
198 }
199
200 jni_client_->RedrawCanvas();
201 } 190 }
202 191
203 void ChromotingJniInstance::SendMouseEvent( 192 void ChromotingJniInstance::SendMouseEvent(
204 int x, int y, 193 int x, int y,
205 protocol::MouseEvent_MouseButton button, 194 protocol::MouseEvent_MouseButton button,
206 bool button_down) { 195 bool button_down) {
207 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 196 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
208 jni_runtime_->network_task_runner()->PostTask( 197 jni_runtime_->network_task_runner()->PostTask(
209 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseEvent, 198 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseEvent,
210 this, x, y, button, button_down)); 199 GetWeakPtr(), x, y, button, button_down));
211 return; 200 return;
212 } 201 }
213 202
214 protocol::MouseEvent event; 203 protocol::MouseEvent event;
215 event.set_x(x); 204 event.set_x(x);
216 event.set_y(y); 205 event.set_y(y);
217 event.set_button(button); 206 event.set_button(button);
218 if (button != protocol::MouseEvent::BUTTON_UNDEFINED) 207 if (button != protocol::MouseEvent::BUTTON_UNDEFINED)
219 event.set_button_down(button_down); 208 event.set_button_down(button_down);
220 209
221 client_->input_stub()->InjectMouseEvent(event); 210 client_->input_stub()->InjectMouseEvent(event);
222 } 211 }
223 212
224 void ChromotingJniInstance::SendMouseWheelEvent(int delta_x, int delta_y) { 213 void ChromotingJniInstance::SendMouseWheelEvent(int delta_x, int delta_y) {
225 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 214 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
226 jni_runtime_->network_task_runner()->PostTask( 215 jni_runtime_->network_task_runner()->PostTask(
227 FROM_HERE, 216 FROM_HERE, base::Bind(&ChromotingJniInstance::SendMouseWheelEvent,
228 base::Bind(&ChromotingJniInstance::SendMouseWheelEvent, this, 217 GetWeakPtr(), delta_x, delta_y));
229 delta_x, delta_y));
230 return; 218 return;
231 } 219 }
232 220
233 protocol::MouseEvent event; 221 protocol::MouseEvent event;
234 event.set_wheel_delta_x(delta_x); 222 event.set_wheel_delta_x(delta_x);
235 event.set_wheel_delta_y(delta_y); 223 event.set_wheel_delta_y(delta_y);
236 client_->input_stub()->InjectMouseEvent(event); 224 client_->input_stub()->InjectMouseEvent(event);
237 } 225 }
238 226
239 bool ChromotingJniInstance::SendKeyEvent(int scan_code, 227 bool ChromotingJniInstance::SendKeyEvent(int scan_code,
(...skipping 11 matching lines...) Expand all
251 } 239 }
252 240
253 SendKeyEventInternal(usb_key_code, key_down); 241 SendKeyEventInternal(usb_key_code, key_down);
254 return true; 242 return true;
255 } 243 }
256 244
257 void ChromotingJniInstance::SendTextEvent(const std::string& text) { 245 void ChromotingJniInstance::SendTextEvent(const std::string& text) {
258 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 246 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
259 jni_runtime_->network_task_runner()->PostTask( 247 jni_runtime_->network_task_runner()->PostTask(
260 FROM_HERE, 248 FROM_HERE,
261 base::Bind(&ChromotingJniInstance::SendTextEvent, this, text)); 249 base::Bind(&ChromotingJniInstance::SendTextEvent, GetWeakPtr(), text));
262 return; 250 return;
263 } 251 }
264 252
265 protocol::TextEvent event; 253 protocol::TextEvent event;
266 event.set_text(text); 254 event.set_text(text);
267 client_->input_stub()->InjectTextEvent(event); 255 client_->input_stub()->InjectTextEvent(event);
268 } 256 }
269 257
270 void ChromotingJniInstance::SendTouchEvent( 258 void ChromotingJniInstance::SendTouchEvent(
271 const protocol::TouchEvent& touch_event) { 259 const protocol::TouchEvent& touch_event) {
272 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 260 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
273 jni_runtime_->network_task_runner()->PostTask( 261 jni_runtime_->network_task_runner()->PostTask(
274 FROM_HERE, 262 FROM_HERE, base::Bind(&ChromotingJniInstance::SendTouchEvent,
275 base::Bind(&ChromotingJniInstance::SendTouchEvent, this, touch_event)); 263 GetWeakPtr(), touch_event));
276 return; 264 return;
277 } 265 }
278 266
279 client_->input_stub()->InjectTouchEvent(touch_event); 267 client_->input_stub()->InjectTouchEvent(touch_event);
280 } 268 }
281 269
282 void ChromotingJniInstance::EnableVideoChannel(bool enable) { 270 void ChromotingJniInstance::EnableVideoChannel(bool enable) {
283 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 271 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
284 jni_runtime_->network_task_runner()->PostTask( 272 jni_runtime_->network_task_runner()->PostTask(
285 FROM_HERE, 273 FROM_HERE, base::Bind(&ChromotingJniInstance::EnableVideoChannel,
286 base::Bind(&ChromotingJniInstance::EnableVideoChannel, this, enable)); 274 GetWeakPtr(), enable));
287 return; 275 return;
288 } 276 }
289 277
290 protocol::VideoControl video_control; 278 protocol::VideoControl video_control;
291 video_control.set_enable(enable); 279 video_control.set_enable(enable);
292 client_->host_stub()->ControlVideo(video_control); 280 client_->host_stub()->ControlVideo(video_control);
293 } 281 }
294 282
295 void ChromotingJniInstance::SendClientMessage(const std::string& type, 283 void ChromotingJniInstance::SendClientMessage(const std::string& type,
296 const std::string& data) { 284 const std::string& data) {
297 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 285 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
298 jni_runtime_->network_task_runner()->PostTask( 286 jni_runtime_->network_task_runner()->PostTask(
299 FROM_HERE, 287 FROM_HERE, base::Bind(&ChromotingJniInstance::SendClientMessage,
300 base::Bind( 288 GetWeakPtr(), type, data));
301 &ChromotingJniInstance::SendClientMessage, this, type, data));
302 return; 289 return;
303 } 290 }
304 291
305 protocol::ExtensionMessage extension_message; 292 protocol::ExtensionMessage extension_message;
306 extension_message.set_type(type); 293 extension_message.set_type(type);
307 extension_message.set_data(data); 294 extension_message.set_data(data);
308 client_->host_stub()->DeliverClientMessage(extension_message); 295 client_->host_stub()->DeliverClientMessage(extension_message);
309 } 296 }
310 297
311 void ChromotingJniInstance::OnConnectionState( 298 void ChromotingJniInstance::OnConnectionState(
(...skipping 12 matching lines...) Expand all
324 311
325 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { 312 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) {
326 protocol::PairingRequest request; 313 protocol::PairingRequest request;
327 DCHECK(!device_name_.empty()); 314 DCHECK(!device_name_.empty());
328 request.set_client_name(device_name_); 315 request.set_client_name(device_name_);
329 client_->host_stub()->RequestPairing(request); 316 client_->host_stub()->RequestPairing(request);
330 } 317 }
331 318
332 jni_runtime_->ui_task_runner()->PostTask( 319 jni_runtime_->ui_task_runner()->PostTask(
333 FROM_HERE, 320 FROM_HERE,
334 base::Bind(&JniClient::OnConnectionState, 321 base::Bind(&JniClient::OnConnectionState, jni_client_, state, error));
335 jni_client_->GetWeakPtr(),
336 state,
337 error));
338 } 322 }
339 323
340 void ChromotingJniInstance::OnConnectionReady(bool ready) { 324 void ChromotingJniInstance::OnConnectionReady(bool ready) {
341 // We ignore this message, since OnConnectionState tells us the same thing. 325 // We ignore this message, since OnConnectionState tells us the same thing.
342 } 326 }
343 327
344 void ChromotingJniInstance::OnRouteChanged( 328 void ChromotingJniInstance::OnRouteChanged(
345 const std::string& channel_name, 329 const std::string& channel_name,
346 const protocol::TransportRoute& route) { 330 const protocol::TransportRoute& route) {
347 std::string message = "Channel " + channel_name + " using " + 331 std::string message = "Channel " + channel_name + " using " +
348 protocol::TransportRoute::GetTypeString(route.type) + " connection."; 332 protocol::TransportRoute::GetTypeString(route.type) + " connection.";
349 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str()); 333 __android_log_print(ANDROID_LOG_INFO, "route", "%s", message.c_str());
350 } 334 }
351 335
352 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { 336 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) {
353 jni_runtime_->ui_task_runner()->PostTask( 337 jni_runtime_->ui_task_runner()->PostTask(
354 FROM_HERE, base::Bind(&JniClient::SetCapabilities, 338 FROM_HERE,
355 jni_client_->GetWeakPtr(), capabilities)); 339 base::Bind(&JniClient::SetCapabilities, jni_client_, capabilities));
356 } 340 }
357 341
358 void ChromotingJniInstance::SetPairingResponse( 342 void ChromotingJniInstance::SetPairingResponse(
359 const protocol::PairingResponse& response) { 343 const protocol::PairingResponse& response) {
360 jni_runtime_->ui_task_runner()->PostTask( 344 jni_runtime_->ui_task_runner()->PostTask(
361 FROM_HERE, 345 FROM_HERE, base::Bind(&JniClient::CommitPairingCredentials, jni_client_,
362 base::Bind(&JniClient::CommitPairingCredentials, 346 client_auth_config_.host_id, response.client_id(),
363 jni_client_->GetWeakPtr(), client_auth_config_.host_id, 347 response.shared_secret()));
364 response.client_id(), response.shared_secret()));
365 } 348 }
366 349
367 void ChromotingJniInstance::DeliverHostMessage( 350 void ChromotingJniInstance::DeliverHostMessage(
368 const protocol::ExtensionMessage& message) { 351 const protocol::ExtensionMessage& message) {
369 jni_runtime_->ui_task_runner()->PostTask( 352 jni_runtime_->ui_task_runner()->PostTask(
370 FROM_HERE, base::Bind(&JniClient::HandleExtensionMessage, 353 FROM_HERE, base::Bind(&JniClient::HandleExtensionMessage, jni_client_,
371 jni_client_->GetWeakPtr(), message.type(), 354 message.type(), message.data()));
372 message.data()));
373 } 355 }
374 356
375 void ChromotingJniInstance::SetDesktopSize(const webrtc::DesktopSize& size, 357 void ChromotingJniInstance::SetDesktopSize(const webrtc::DesktopSize& size,
376 const webrtc::DesktopVector& dpi) { 358 const webrtc::DesktopVector& dpi) {
377 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this 359 // JniFrameConsumer get size from the frames and it doesn't use DPI, so this
378 // call can be ignored. 360 // call can be ignored.
379 } 361 }
380 362
381 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { 363 protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() {
382 return this; 364 return this;
383 } 365 }
384 366
385 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { 367 protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() {
386 return this; 368 return this;
387 } 369 }
388 370
389 void ChromotingJniInstance::InjectClipboardEvent( 371 void ChromotingJniInstance::InjectClipboardEvent(
390 const protocol::ClipboardEvent& event) { 372 const protocol::ClipboardEvent& event) {
391 NOTIMPLEMENTED(); 373 NOTIMPLEMENTED();
392 } 374 }
393 375
394 void ChromotingJniInstance::SetCursorShape( 376 void ChromotingJniInstance::SetCursorShape(
395 const protocol::CursorShapeInfo& shape) { 377 const protocol::CursorShapeInfo& shape) {
396 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { 378 if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) {
397 jni_runtime_->display_task_runner()->PostTask( 379 jni_runtime_->display_task_runner()->PostTask(
398 FROM_HERE, 380 FROM_HERE, base::Bind(&JniDisplayHandler::UpdateCursorShape,
399 base::Bind(&ChromotingJniInstance::SetCursorShape, this, shape)); 381 display_handler_, shape));
400 return; 382 } else if (display_handler_) {
383 display_handler_->UpdateCursorShape(shape);
401 } 384 }
385 }
402 386
403 jni_client_->UpdateCursorShape(shape); 387 base::WeakPtr<ChromotingJniInstance> ChromotingJniInstance::GetWeakPtr() {
388 return weak_factory_.GetWeakPtr();
404 } 389 }
405 390
406 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { 391 void ChromotingJniInstance::ConnectToHostOnNetworkThread() {
407 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); 392 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
408 393
409 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); 394 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
410 395
411 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner())); 396 client_context_.reset(new ClientContext(jni_runtime_->network_task_runner()));
412 client_context_->Start(); 397 client_context_->Start();
413 398
414 perf_tracker_.reset(new protocol::PerformanceTracker()); 399 perf_tracker_.reset(new protocol::PerformanceTracker());
415 400
416 view_.reset(new JniFrameConsumer(jni_runtime_, jni_client_)); 401 view_.reset(new JniFrameConsumer(jni_runtime_, display_handler_));
417 video_renderer_.reset(new SoftwareVideoRenderer( 402 video_renderer_.reset(new SoftwareVideoRenderer(
418 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get())); 403 client_context_->decode_task_runner(), view_.get(), perf_tracker_.get()));
419 404
420 client_.reset( 405 client_.reset(
421 new ChromotingClient(client_context_.get(), this, video_renderer_.get(), 406 new ChromotingClient(client_context_.get(), this, video_renderer_.get(),
422 base::WrapUnique(new AudioPlayerAndroid()))); 407 base::WrapUnique(new AudioPlayerAndroid())));
423 408
424 signaling_.reset( 409 signaling_.reset(
425 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), 410 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(),
426 jni_runtime_->url_requester(), xmpp_config_)); 411 jni_runtime_->url_requester(), xmpp_config_));
(...skipping 20 matching lines...) Expand all
447 #endif // defined(ENABLE_WEBRTC_REMOTING_CLIENT) 432 #endif // defined(ENABLE_WEBRTC_REMOTING_CLIENT)
448 client_->Start(signaling_.get(), client_auth_config_, transport_context, 433 client_->Start(signaling_.get(), client_auth_config_, transport_context,
449 host_jid_, capabilities_); 434 host_jid_, capabilities_);
450 } 435 }
451 436
452 void ChromotingJniInstance::FetchSecret( 437 void ChromotingJniInstance::FetchSecret(
453 bool pairable, 438 bool pairable,
454 const protocol::SecretFetchedCallback& callback) { 439 const protocol::SecretFetchedCallback& callback) {
455 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { 440 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) {
456 jni_runtime_->ui_task_runner()->PostTask( 441 jni_runtime_->ui_task_runner()->PostTask(
457 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, 442 FROM_HERE, base::Bind(&JniPairingSecretFetcher::FetchSecret,
458 this, pairable, callback)); 443 secret_fetcher_, pairable, callback));
459 return; 444 } else if (secret_fetcher_) {
445 secret_fetcher_->FetchSecret(pairable, callback);
460 } 446 }
461
462 // Delete pairing credentials if they exist.
463 jni_client_->CommitPairingCredentials(client_auth_config_.host_id, "", "");
464
465 pin_callback_ = callback;
466 jni_client_->DisplayAuthenticationPrompt(pairable);
467 } 447 }
468 448
469 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) { 449 void ChromotingJniInstance::SetDeviceName(const std::string& device_name) {
470 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 450 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
471 jni_runtime_->network_task_runner()->PostTask( 451 jni_runtime_->network_task_runner()->PostTask(
472 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName, this, 452 FROM_HERE, base::Bind(&ChromotingJniInstance::SetDeviceName,
473 device_name)); 453 GetWeakPtr(), device_name));
474 return; 454 return;
475 } 455 }
476 456
477 device_name_ = device_name; 457 device_name_ = device_name;
478 } 458 }
479 459
480 void ChromotingJniInstance::SendKeyEventInternal(int usb_key_code, 460 void ChromotingJniInstance::SendKeyEventInternal(int usb_key_code,
481 bool key_down) { 461 bool key_down) {
482 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { 462 if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) {
483 jni_runtime_->network_task_runner()->PostTask( 463 jni_runtime_->network_task_runner()->PostTask(
484 FROM_HERE, base::Bind(&ChromotingJniInstance::SendKeyEventInternal, 464 FROM_HERE, base::Bind(&ChromotingJniInstance::SendKeyEventInternal,
485 this, usb_key_code, key_down)); 465 GetWeakPtr(), usb_key_code, key_down));
486 return; 466 return;
487 } 467 }
488 468
489 protocol::KeyEvent event; 469 protocol::KeyEvent event;
490 event.set_usb_keycode(usb_key_code); 470 event.set_usb_keycode(usb_key_code);
491 event.set_pressed(key_down); 471 event.set_pressed(key_down);
492 client_->input_stub()->InjectKeyEvent(event); 472 client_->input_stub()->InjectKeyEvent(event);
493 } 473 }
494 474
495 void ChromotingJniInstance::EnableStatsLogging(bool enabled) { 475 void ChromotingJniInstance::EnableStatsLogging(bool enabled) {
496 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); 476 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
497 477
498 if (enabled && !stats_logging_enabled_) { 478 if (enabled && !stats_logging_enabled_) {
499 jni_runtime_->network_task_runner()->PostDelayedTask( 479 jni_runtime_->network_task_runner()->PostDelayedTask(
500 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), 480 FROM_HERE,
481 base::Bind(&ChromotingJniInstance::LogPerfStats, GetWeakPtr()),
501 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); 482 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs));
502 } 483 }
503 stats_logging_enabled_ = enabled; 484 stats_logging_enabled_ = enabled;
504 } 485 }
505 486
506 void ChromotingJniInstance::LogPerfStats() { 487 void ChromotingJniInstance::LogPerfStats() {
507 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); 488 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread());
508 489
509 if (!stats_logging_enabled_) 490 if (!stats_logging_enabled_)
510 return; 491 return;
(...skipping 11 matching lines...) Expand all
522 perf_tracker_->video_decode_ms().Average(), 503 perf_tracker_->video_decode_ms().Average(),
523 perf_tracker_->video_decode_ms().Max(), 504 perf_tracker_->video_decode_ms().Max(),
524 perf_tracker_->video_paint_ms().Average(), 505 perf_tracker_->video_paint_ms().Average(),
525 perf_tracker_->video_paint_ms().Max(), 506 perf_tracker_->video_paint_ms().Max(),
526 perf_tracker_->round_trip_ms().Average(), 507 perf_tracker_->round_trip_ms().Average(),
527 perf_tracker_->round_trip_ms().Max()); 508 perf_tracker_->round_trip_ms().Max());
528 509
529 jni_runtime_->logger()->LogStatistics(perf_tracker_.get()); 510 jni_runtime_->logger()->LogStatistics(perf_tracker_.get());
530 511
531 jni_runtime_->network_task_runner()->PostDelayedTask( 512 jni_runtime_->network_task_runner()->PostDelayedTask(
532 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), 513 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, GetWeakPtr()),
533 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); 514 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs));
534 } 515 }
535 516
517 void ChromotingJniInstance::ReleaseResources() {
518 // |client_| must be torn down before |signaling_|.
519 client_.reset();
520 video_renderer_.reset();
521 view_.reset();
522 signaling_.reset();
523 perf_tracker_.reset();
524 client_context_.reset();
525
526 weak_factory_.InvalidateWeakPtrs();
527 }
528
536 } // namespace remoting 529 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/jni/chromoting_jni_instance.h ('k') | remoting/client/jni/jni_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698