Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "remoting/client/jni/chromoting_jni_instance.h" |
| 6 | |
| 7 | #include "base/bind.h" |
| 8 | #include "base/logging.h" |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 9 | #include "net/socket/client_socket_factory.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 10 | #include "remoting/client/audio_player.h" |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 11 | #include "remoting/client/jni/android_keymap.h" |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 12 | #include "remoting/client/jni/chromoting_jni_runtime.h" |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame] | 13 | #include "remoting/protocol/host_stub.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 14 | #include "remoting/protocol/libjingle_transport_factory.h" |
| 15 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 16 | // TODO(solb) Move into location shared with client plugin. |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 17 | const char* const kXmppServer = "talk.google.com"; |
| 18 | const int kXmppPort = 5222; |
| 19 | const bool kXmppUseTls = true; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 20 | |
| 21 | namespace remoting { |
| 22 | |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 23 | ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, |
| 24 | const char* username, |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 25 | const char* auth_token, |
| 26 | const char* host_jid, |
| 27 | const char* host_id, |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame] | 28 | const char* host_pubkey, |
| 29 | const char* pairing_id, |
| 30 | const char* pairing_secret) |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 31 | : jni_runtime_(jni_runtime), |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 32 | host_id_(host_id), |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame] | 33 | create_pairing_(false) { |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 34 | DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 35 | |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 36 | // Intialize XMPP config. |
| 37 | xmpp_config_.host = kXmppServer; |
| 38 | xmpp_config_.port = kXmppPort; |
| 39 | xmpp_config_.use_tls = kXmppUseTls; |
| 40 | xmpp_config_.username = username; |
| 41 | xmpp_config_.auth_token = auth_token; |
| 42 | xmpp_config_.auth_service = "oauth2"; |
| 43 | |
| 44 | // Initialize ClientConfig. |
| 45 | client_config_.host_jid = host_jid; |
| 46 | client_config_.host_public_key = host_pubkey; |
| 47 | |
| 48 | client_config_.fetch_secret_callback = |
| 49 | base::Bind(&ChromotingJniInstance::FetchSecret, this); |
| 50 | client_config_.authentication_tag = host_id_; |
| 51 | |
| 52 | client_config_.client_pairing_id = pairing_id; |
| 53 | client_config_.client_paired_secret = pairing_secret; |
| 54 | |
| 55 | client_config_.authentication_methods.push_back( |
| 56 | protocol::AuthenticationMethod::FromString("spake2_pair")); |
| 57 | client_config_.authentication_methods.push_back( |
| 58 | protocol::AuthenticationMethod::FromString("spake2_hmac")); |
| 59 | client_config_.authentication_methods.push_back( |
| 60 | protocol::AuthenticationMethod::FromString("spake2_plain")); |
| 61 | |
| 62 | // Post a task to start connection |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 63 | jni_runtime_->display_task_runner()->PostTask( |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 64 | FROM_HERE, |
| 65 | base::Bind(&ChromotingJniInstance::ConnectToHostOnDisplayThread, |
| 66 | this)); |
| 67 | } |
| 68 | |
| 69 | ChromotingJniInstance::~ChromotingJniInstance() {} |
| 70 | |
| 71 | void ChromotingJniInstance::Cleanup() { |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 72 | if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { |
| 73 | jni_runtime_->display_task_runner()->PostTask( |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 74 | FROM_HERE, |
| 75 | base::Bind(&ChromotingJniInstance::Cleanup, this)); |
| 76 | return; |
| 77 | } |
| 78 | |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 79 | // This must be destroyed on the display thread before the producer is gone. |
| 80 | view_.reset(); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 81 | |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 82 | // The weak pointers must be invalidated on the same thread they were used. |
| 83 | view_weak_factory_->InvalidateWeakPtrs(); |
| 84 | |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 85 | jni_runtime_->network_task_runner()->PostTask( |
| 86 | FROM_HERE, |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 87 | base::Bind(&ChromotingJniInstance::DisconnectFromHostOnNetworkThread, |
| 88 | this)); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame] | 91 | void ChromotingJniInstance::ProvideSecret(const std::string& pin, |
| 92 | bool create_pairing) { |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 93 | DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 94 | DCHECK(!pin_callback_.is_null()); |
| 95 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame] | 96 | create_pairing_ = create_pairing; |
| 97 | |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 98 | jni_runtime_->network_task_runner()->PostTask(FROM_HERE, |
| 99 | base::Bind(pin_callback_, pin)); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 102 | void ChromotingJniInstance::RedrawDesktop() { |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 103 | if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { |
| 104 | jni_runtime_->display_task_runner()->PostTask( |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 105 | FROM_HERE, |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 106 | base::Bind(&ChromotingJniInstance::RedrawDesktop, this)); |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 107 | return; |
| 108 | } |
| 109 | |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 110 | jni_runtime_->RedrawCanvas(); |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 113 | void ChromotingJniInstance::PerformMouseAction( |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 114 | int x, int y, |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 115 | protocol::MouseEvent_MouseButton button, |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 116 | bool button_down) { |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 117 | if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 118 | jni_runtime_->network_task_runner()->PostTask( |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 119 | FROM_HERE, base::Bind(&ChromotingJniInstance::PerformMouseAction, |
| 120 | this, x, y, button, button_down)); |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 121 | return; |
| 122 | } |
| 123 | |
| 124 | protocol::MouseEvent action; |
| 125 | action.set_x(x); |
| 126 | action.set_y(y); |
| 127 | action.set_button(button); |
| 128 | if (button != protocol::MouseEvent::BUTTON_UNDEFINED) |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 129 | action.set_button_down(button_down); |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 130 | |
| 131 | connection_->input_stub()->InjectMouseEvent(action); |
| 132 | } |
| 133 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 134 | void ChromotingJniInstance::PerformKeyboardAction(int key_code, bool key_down) { |
| 135 | if (!jni_runtime_->network_task_runner()->BelongsToCurrentThread()) { |
| 136 | jni_runtime_->network_task_runner()->PostTask( |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 137 | FROM_HERE, base::Bind(&ChromotingJniInstance::PerformKeyboardAction, |
| 138 | this, key_code, key_down)); |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 139 | return; |
| 140 | } |
| 141 | |
| 142 | uint32 usb_code = AndroidKeycodeToUsbKeycode(key_code); |
| 143 | if (usb_code) { |
| 144 | protocol::KeyEvent action; |
| 145 | action.set_usb_keycode(usb_code); |
| 146 | action.set_pressed(key_down); |
| 147 | connection_->input_stub()->InjectKeyEvent(action); |
Ben Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 148 | } else { |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 149 | LOG(WARNING) << "Ignoring unknown keycode: " << key_code; |
| 150 | } |
| 151 | } |
| 152 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 153 | void ChromotingJniInstance::OnConnectionState( |
| 154 | protocol::ConnectionToHost::State state, |
| 155 | protocol::ErrorCode error) { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame] | 156 | DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 157 | |
| 158 | if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { |
| 159 | LOG(INFO) << "Attempting to pair with host"; |
| 160 | protocol::PairingRequest request; |
| 161 | request.set_client_name("Android"); |
| 162 | connection_->host_stub()->RequestPairing(request); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame] | 165 | jni_runtime_->ui_task_runner()->PostTask( |
| 166 | FROM_HERE, |
| 167 | base::Bind(&ChromotingJniRuntime::ReportConnectionStatus, |
| 168 | base::Unretained(jni_runtime_), |
| 169 | state, |
| 170 | error)); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | void ChromotingJniInstance::OnConnectionReady(bool ready) { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame] | 174 | // We ignore this message, since OnConnectoinState tells us the same thing. |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 177 | void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) { |
| 178 | NOTIMPLEMENTED(); |
| 179 | } |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 180 | |
| 181 | void ChromotingJniInstance::SetPairingResponse( |
| 182 | const protocol::PairingResponse& response) { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame] | 183 | LOG(INFO) << "Successfully established pairing with host"; |
| 184 | |
| 185 | jni_runtime_->ui_task_runner()->PostTask( |
| 186 | FROM_HERE, |
| 187 | base::Bind(&ChromotingJniRuntime::CommitPairingCredentials, |
| 188 | base::Unretained(jni_runtime_), |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 189 | host_id_, response.client_id(), response.shared_secret())); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Ben Murdoch | c2db58b | 2013-08-14 11:51:42 +0100 | [diff] [blame] | 192 | void ChromotingJniInstance::DeliverHostMessage( |
| 193 | const protocol::ExtensionMessage& message) { |
| 194 | NOTIMPLEMENTED(); |
| 195 | } |
| 196 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 197 | protocol::ClipboardStub* ChromotingJniInstance::GetClipboardStub() { |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 198 | return this; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | protocol::CursorShapeStub* ChromotingJniInstance::GetCursorShapeStub() { |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 202 | return this; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> |
| 206 | ChromotingJniInstance::GetTokenFetcher(const std::string& host_public_key) { |
| 207 | // Return null to indicate that third-party authentication is unsupported. |
| 208 | return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>(); |
| 209 | } |
| 210 | |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 211 | void ChromotingJniInstance::InjectClipboardEvent( |
| 212 | const protocol::ClipboardEvent& event) { |
| 213 | NOTIMPLEMENTED(); |
| 214 | } |
| 215 | |
| 216 | void ChromotingJniInstance::SetCursorShape( |
| 217 | const protocol::CursorShapeInfo& shape) { |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 218 | if (!jni_runtime_->display_task_runner()->BelongsToCurrentThread()) { |
| 219 | jni_runtime_->display_task_runner()->PostTask( |
| 220 | FROM_HERE, |
| 221 | base::Bind(&ChromotingJniInstance::SetCursorShape, this, shape)); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | jni_runtime_->UpdateCursorShape(shape); |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 226 | } |
| 227 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 228 | void ChromotingJniInstance::ConnectToHostOnDisplayThread() { |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 229 | DCHECK(jni_runtime_->display_task_runner()->BelongsToCurrentThread()); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 230 | |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 231 | view_.reset(new JniFrameConsumer(jni_runtime_)); |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 232 | view_weak_factory_.reset(new base::WeakPtrFactory<JniFrameConsumer>( |
| 233 | view_.get())); |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame^] | 234 | frame_consumer_ = new FrameConsumerProxy(jni_runtime_->display_task_runner(), |
| 235 | view_weak_factory_->GetWeakPtr()); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 236 | |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 237 | jni_runtime_->network_task_runner()->PostTask( |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 238 | FROM_HERE, |
| 239 | base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, |
| 240 | this)); |
| 241 | } |
| 242 | |
| 243 | void ChromotingJniInstance::ConnectToHostOnNetworkThread() { |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 244 | DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 245 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 246 | client_context_.reset(new ClientContext( |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 247 | jni_runtime_->network_task_runner().get())); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 248 | client_context_->Start(); |
| 249 | |
| 250 | connection_.reset(new protocol::ConnectionToHost(true)); |
| 251 | |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 252 | client_.reset(new ChromotingClient( |
| 253 | client_config_, client_context_.get(), connection_.get(), |
| 254 | this, frame_consumer_, scoped_ptr<AudioPlayer>())); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 255 | |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 256 | view_->set_frame_producer(client_->GetFrameProducer()); |
| 257 | |
Torne (Richard Coles) | 68043e1 | 2013-09-26 13:24:57 +0100 | [diff] [blame] | 258 | signaling_.reset(new XmppSignalStrategy( |
| 259 | net::ClientSocketFactory::GetDefaultFactory(), |
| 260 | jni_runtime_->url_requester(), xmpp_config_)); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 261 | |
| 262 | network_settings_.reset(new NetworkSettings( |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 263 | NetworkSettings::NAT_TRAVERSAL_ENABLED)); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 264 | scoped_ptr<protocol::TransportFactory> fact( |
| 265 | protocol::LibjingleTransportFactory::Create( |
| 266 | *network_settings_, |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 267 | jni_runtime_->url_requester())); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 268 | |
| 269 | client_->Start(signaling_.get(), fact.Pass()); |
| 270 | } |
| 271 | |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 272 | void ChromotingJniInstance::DisconnectFromHostOnNetworkThread() { |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 273 | DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 274 | |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 275 | host_id_.clear(); |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 276 | |
| 277 | // |client_| must be torn down before |signaling_|. |
| 278 | connection_.reset(); |
| 279 | client_.reset(); |
| 280 | } |
| 281 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 282 | void ChromotingJniInstance::FetchSecret( |
| 283 | bool pairable, |
| 284 | const protocol::SecretFetchedCallback& callback) { |
Ben Murdoch | bbcdd45 | 2013-07-25 10:06:34 +0100 | [diff] [blame] | 285 | if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { |
| 286 | jni_runtime_->ui_task_runner()->PostTask( |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 287 | FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, |
| 288 | this, pairable, callback)); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 289 | return; |
| 290 | } |
| 291 | |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 292 | if (!client_config_.client_pairing_id.empty()) { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame] | 293 | // We attempted to connect using an existing pairing that was rejected. |
| 294 | // Unless we forget about the stale credentials, we'll continue trying them. |
| 295 | LOG(INFO) << "Deleting rejected pairing credentials"; |
| 296 | jni_runtime_->CommitPairingCredentials(host_id_, "", ""); |
| 297 | } |
| 298 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 299 | pin_callback_ = callback; |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 300 | jni_runtime_->DisplayAuthenticationPrompt(pairable); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | } // namespace remoting |