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 #include "remoting/client/jni/chromoting_jni_instance.h" | 5 #include "remoting/client/jni/chromoting_jni_instance.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "remoting/client/audio_player.h" | 9 #include "remoting/client/audio_player.h" |
| 10 #include "remoting/client/jni/chromoting_jni.h" | 10 #include "remoting/client/jni/chromoting_jni_runtime.h" |
| 11 #include "remoting/protocol/libjingle_transport_factory.h" | 11 #include "remoting/protocol/libjingle_transport_factory.h" |
| 12 | 12 |
| 13 // TODO(solb) Move into location shared with client plugin. | 13 // TODO(solb) Move into location shared with client plugin. |
| 14 const char* const CHAT_SERVER = "talk.google.com"; | 14 const char* const CHAT_SERVER = "talk.google.com"; |
| 15 const int CHAT_PORT = 5222; | 15 const int CHAT_PORT = 5222; |
| 16 const bool CHAT_USE_TLS = true; | 16 const bool CHAT_USE_TLS = true; |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 | 19 |
| 20 ChromotingJniInstance::ChromotingJniInstance(const char* username, | 20 ChromotingJniInstance::ChromotingJniInstance(const char* username, |
| 21 const char* auth_token, | 21 const char* auth_token, |
| 22 const char* host_jid, | 22 const char* host_jid, |
| 23 const char* host_id, | 23 const char* host_id, |
| 24 const char* host_pubkey) { | 24 const char* host_pubkey) { |
| 25 DCHECK(ChromotingJni::GetInstance()-> | 25 DCHECK(ChromotingJniRuntime::GetInstance()-> |
|
Wez
2013/07/23 19:59:07
This seems to be using the GetInstance() model, to
solb
2013/07/23 20:50:28
Done.
| |
| 26 ui_task_runner()->BelongsToCurrentThread()); | 26 ui_task_runner()->BelongsToCurrentThread()); |
| 27 | 27 |
| 28 username_ = username; | 28 username_ = username; |
| 29 auth_token_ = auth_token; | 29 auth_token_ = auth_token; |
| 30 host_jid_ = host_jid; | 30 host_jid_ = host_jid; |
| 31 host_id_ = host_id; | 31 host_id_ = host_id; |
| 32 host_pubkey_ = host_pubkey; | 32 host_pubkey_ = host_pubkey; |
| 33 | 33 |
| 34 ChromotingJni::GetInstance()->display_task_runner()->PostTask( | 34 ChromotingJniRuntime::GetInstance()->display_task_runner()->PostTask( |
| 35 FROM_HERE, | 35 FROM_HERE, |
| 36 base::Bind(&ChromotingJniInstance::ConnectToHostOnDisplayThread, | 36 base::Bind(&ChromotingJniInstance::ConnectToHostOnDisplayThread, |
| 37 this)); | 37 this)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 ChromotingJniInstance::~ChromotingJniInstance() {} | 40 ChromotingJniInstance::~ChromotingJniInstance() {} |
| 41 | 41 |
| 42 void ChromotingJniInstance::Cleanup() { | 42 void ChromotingJniInstance::Cleanup() { |
| 43 if (!ChromotingJni::GetInstance()-> | 43 if (!ChromotingJniRuntime::GetInstance()-> |
| 44 display_task_runner()->BelongsToCurrentThread()) { | 44 display_task_runner()->BelongsToCurrentThread()) { |
| 45 ChromotingJni::GetInstance()->display_task_runner()->PostTask( | 45 ChromotingJniRuntime::GetInstance()->display_task_runner()->PostTask( |
| 46 FROM_HERE, | 46 FROM_HERE, |
| 47 base::Bind(&ChromotingJniInstance::Cleanup, this)); | 47 base::Bind(&ChromotingJniInstance::Cleanup, this)); |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // This must be destroyed on the display thread before the producer is gone. | 51 // This must be destroyed on the display thread before the producer is gone. |
| 52 view_.reset(); | 52 view_.reset(); |
| 53 | 53 |
| 54 // The weak pointers must be invalidated on the same thread they were used. | 54 // The weak pointers must be invalidated on the same thread they were used. |
| 55 view_weak_factory_->InvalidateWeakPtrs(); | 55 view_weak_factory_->InvalidateWeakPtrs(); |
| 56 | 56 |
| 57 ChromotingJni::GetInstance()->network_task_runner()->PostTask(FROM_HERE, | 57 ChromotingJniRuntime::GetInstance()->network_task_runner()->PostTask( |
| 58 FROM_HERE, | |
| 58 base::Bind(&ChromotingJniInstance::DisconnectFromHostOnNetworkThread, | 59 base::Bind(&ChromotingJniInstance::DisconnectFromHostOnNetworkThread, |
| 59 this)); | 60 this)); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void ChromotingJniInstance::ProvideSecret(const char* pin) { | 63 void ChromotingJniInstance::ProvideSecret(const char* pin) { |
| 63 DCHECK(ChromotingJni::GetInstance()-> | 64 DCHECK(ChromotingJniRuntime::GetInstance()-> |
| 64 ui_task_runner()->BelongsToCurrentThread()); | 65 ui_task_runner()->BelongsToCurrentThread()); |
| 65 DCHECK(!pin_callback_.is_null()); | 66 DCHECK(!pin_callback_.is_null()); |
| 66 | 67 |
| 67 // We invoke the string constructor to ensure |pin| gets copied *before* the | 68 // We invoke the string constructor to ensure |pin| gets copied *before* the |
| 68 // asynchronous run, since Java might want it back as soon as we return. | 69 // asynchronous run, since Java might want it back as soon as we return. |
| 69 ChromotingJni::GetInstance()->network_task_runner()->PostTask(FROM_HERE, | 70 ChromotingJniRuntime::GetInstance()->network_task_runner()->PostTask( |
| 70 base::Bind(pin_callback_, pin)); | 71 FROM_HERE, |
| 72 base::Bind(pin_callback_, pin)); | |
| 71 } | 73 } |
| 72 | 74 |
| 73 void ChromotingJniInstance::RedrawDesktop() { | 75 void ChromotingJniInstance::RedrawDesktop() { |
| 74 if (!ChromotingJni::GetInstance()-> | 76 if (!ChromotingJniRuntime::GetInstance()-> |
| 75 display_task_runner()->BelongsToCurrentThread()) { | 77 display_task_runner()->BelongsToCurrentThread()) { |
| 76 ChromotingJni::GetInstance()->display_task_runner()->PostTask( | 78 ChromotingJniRuntime::GetInstance()->display_task_runner()->PostTask( |
| 77 FROM_HERE, | 79 FROM_HERE, |
| 78 base::Bind(&ChromotingJniInstance::RedrawDesktop, this)); | 80 base::Bind(&ChromotingJniInstance::RedrawDesktop, this)); |
| 79 return; | 81 return; |
| 80 } | 82 } |
| 81 | 83 |
| 82 ChromotingJni::GetInstance()->RedrawCanvas(); | 84 ChromotingJniRuntime::GetInstance()->RedrawCanvas(); |
| 83 } | 85 } |
| 84 | 86 |
| 85 void ChromotingJniInstance::PerformMouseAction( | 87 void ChromotingJniInstance::PerformMouseAction( |
| 86 int x, | 88 int x, |
| 87 int y, | 89 int y, |
| 88 protocol::MouseEvent_MouseButton button, | 90 protocol::MouseEvent_MouseButton button, |
| 89 bool buttonDown) { | 91 bool buttonDown) { |
| 90 if(!ChromotingJni::GetInstance()-> | 92 if(!ChromotingJniRuntime::GetInstance()-> |
| 91 network_task_runner()->BelongsToCurrentThread()) { | 93 network_task_runner()->BelongsToCurrentThread()) { |
| 92 ChromotingJni::GetInstance()->network_task_runner()->PostTask( | 94 ChromotingJniRuntime::GetInstance()->network_task_runner()->PostTask( |
| 93 FROM_HERE, | 95 FROM_HERE, |
| 94 base::Bind(&ChromotingJniInstance::PerformMouseAction, | 96 base::Bind(&ChromotingJniInstance::PerformMouseAction, |
| 95 this, | 97 this, |
| 96 x, | 98 x, |
| 97 y, | 99 y, |
| 98 button, | 100 button, |
| 99 buttonDown)); | 101 buttonDown)); |
| 100 return; | 102 return; |
| 101 } | 103 } |
| 102 | 104 |
| 103 protocol::MouseEvent action; | 105 protocol::MouseEvent action; |
| 104 action.set_x(x); | 106 action.set_x(x); |
| 105 action.set_y(y); | 107 action.set_y(y); |
| 106 action.set_button(button); | 108 action.set_button(button); |
| 107 if (button != protocol::MouseEvent::BUTTON_UNDEFINED) | 109 if (button != protocol::MouseEvent::BUTTON_UNDEFINED) |
| 108 action.set_button_down(buttonDown); | 110 action.set_button_down(buttonDown); |
| 109 | 111 |
| 110 connection_->input_stub()->InjectMouseEvent(action); | 112 connection_->input_stub()->InjectMouseEvent(action); |
| 111 } | 113 } |
| 112 | 114 |
| 113 void ChromotingJniInstance::OnConnectionState( | 115 void ChromotingJniInstance::OnConnectionState( |
| 114 protocol::ConnectionToHost::State state, | 116 protocol::ConnectionToHost::State state, |
| 115 protocol::ErrorCode error) { | 117 protocol::ErrorCode error) { |
| 116 if (!ChromotingJni::GetInstance()-> | 118 if (!ChromotingJniRuntime::GetInstance()-> |
| 117 ui_task_runner()->BelongsToCurrentThread()) { | 119 ui_task_runner()->BelongsToCurrentThread()) { |
| 118 ChromotingJni::GetInstance()-> | 120 ChromotingJniRuntime::GetInstance()-> |
| 119 ui_task_runner()->PostTask( | 121 ui_task_runner()->PostTask( |
| 120 FROM_HERE, | 122 FROM_HERE, |
| 121 base::Bind(&ChromotingJniInstance::OnConnectionState, | 123 base::Bind(&ChromotingJniInstance::OnConnectionState, |
| 122 this, | 124 this, |
| 123 state, | 125 state, |
| 124 error)); | 126 error)); |
| 125 return; | 127 return; |
| 126 } | 128 } |
| 127 | 129 |
| 128 ChromotingJni::GetInstance()->ReportConnectionStatus(state, error); | 130 ChromotingJniRuntime::GetInstance()->ReportConnectionStatus(state, error); |
| 129 } | 131 } |
| 130 | 132 |
| 131 void ChromotingJniInstance::OnConnectionReady(bool ready) { | 133 void ChromotingJniInstance::OnConnectionReady(bool ready) { |
| 132 // We ignore this message, since OnConnectionState() tells us the same thing. | 134 // We ignore this message, since OnConnectionState() tells us the same thing. |
| 133 } | 135 } |
| 134 | 136 |
| 135 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) {} | 137 void ChromotingJniInstance::SetCapabilities(const std::string& capabilities) {} |
| 136 | 138 |
| 137 void ChromotingJniInstance::SetPairingResponse( | 139 void ChromotingJniInstance::SetPairingResponse( |
| 138 const protocol::PairingResponse& response) { | 140 const protocol::PairingResponse& response) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 157 const protocol::ClipboardEvent& event) { | 159 const protocol::ClipboardEvent& event) { |
| 158 NOTIMPLEMENTED(); | 160 NOTIMPLEMENTED(); |
| 159 } | 161 } |
| 160 | 162 |
| 161 void ChromotingJniInstance::SetCursorShape( | 163 void ChromotingJniInstance::SetCursorShape( |
| 162 const protocol::CursorShapeInfo& shape) { | 164 const protocol::CursorShapeInfo& shape) { |
| 163 NOTIMPLEMENTED(); | 165 NOTIMPLEMENTED(); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void ChromotingJniInstance::ConnectToHostOnDisplayThread() { | 168 void ChromotingJniInstance::ConnectToHostOnDisplayThread() { |
| 167 DCHECK(ChromotingJni::GetInstance()-> | 169 DCHECK(ChromotingJniRuntime::GetInstance()-> |
| 168 display_task_runner()->BelongsToCurrentThread()); | 170 display_task_runner()->BelongsToCurrentThread()); |
| 169 | 171 |
| 170 frame_consumer_ = new FrameConsumerProxy( | 172 frame_consumer_ = new FrameConsumerProxy( |
| 171 ChromotingJni::GetInstance()->display_task_runner()); | 173 ChromotingJniRuntime::GetInstance()->display_task_runner()); |
| 172 view_.reset(new JniFrameConsumer()); | 174 view_.reset(new JniFrameConsumer(ChromotingJniRuntime::GetInstance())); |
| 173 view_weak_factory_.reset(new base::WeakPtrFactory<JniFrameConsumer>( | 175 view_weak_factory_.reset(new base::WeakPtrFactory<JniFrameConsumer>( |
| 174 view_.get())); | 176 view_.get())); |
| 175 frame_consumer_->Attach(view_weak_factory_->GetWeakPtr()); | 177 frame_consumer_->Attach(view_weak_factory_->GetWeakPtr()); |
| 176 | 178 |
| 177 ChromotingJni::GetInstance()->network_task_runner()->PostTask( | 179 ChromotingJniRuntime::GetInstance()->network_task_runner()->PostTask( |
| 178 FROM_HERE, | 180 FROM_HERE, |
| 179 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, | 181 base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, |
| 180 this)); | 182 this)); |
| 181 } | 183 } |
| 182 | 184 |
| 183 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { | 185 void ChromotingJniInstance::ConnectToHostOnNetworkThread() { |
| 184 DCHECK(ChromotingJni::GetInstance()-> | 186 DCHECK(ChromotingJniRuntime::GetInstance()-> |
| 185 network_task_runner()->BelongsToCurrentThread()); | 187 network_task_runner()->BelongsToCurrentThread()); |
| 186 | 188 |
| 187 client_config_.reset(new ClientConfig()); | 189 client_config_.reset(new ClientConfig()); |
| 188 client_config_->host_jid = host_jid_; | 190 client_config_->host_jid = host_jid_; |
| 189 client_config_->host_public_key = host_pubkey_; | 191 client_config_->host_public_key = host_pubkey_; |
| 190 | 192 |
| 191 client_config_->fetch_secret_callback = base::Bind( | 193 client_config_->fetch_secret_callback = base::Bind( |
| 192 &ChromotingJniInstance::FetchSecret, | 194 &ChromotingJniInstance::FetchSecret, |
| 193 this); | 195 this); |
| 194 client_config_->authentication_tag = host_id_; | 196 client_config_->authentication_tag = host_id_; |
| 195 | 197 |
| 196 client_config_->authentication_methods.push_back( | 198 client_config_->authentication_methods.push_back( |
| 197 protocol::AuthenticationMethod::FromString("spake2_hmac")); | 199 protocol::AuthenticationMethod::FromString("spake2_hmac")); |
| 198 client_config_->authentication_methods.push_back( | 200 client_config_->authentication_methods.push_back( |
| 199 protocol::AuthenticationMethod::FromString("spake2_plain")); | 201 protocol::AuthenticationMethod::FromString("spake2_plain")); |
| 200 | 202 |
| 201 client_context_.reset(new ClientContext( | 203 client_context_.reset(new ClientContext( |
| 202 ChromotingJni::GetInstance()->network_task_runner().get())); | 204 ChromotingJniRuntime::GetInstance()->network_task_runner().get())); |
| 203 client_context_->Start(); | 205 client_context_->Start(); |
| 204 | 206 |
| 205 connection_.reset(new protocol::ConnectionToHost(true)); | 207 connection_.reset(new protocol::ConnectionToHost(true)); |
| 206 | 208 |
| 207 client_.reset(new ChromotingClient(*client_config_, | 209 client_.reset(new ChromotingClient(*client_config_, |
| 208 client_context_.get(), | 210 client_context_.get(), |
| 209 connection_.get(), | 211 connection_.get(), |
| 210 this, | 212 this, |
| 211 frame_consumer_, | 213 frame_consumer_, |
| 212 scoped_ptr<AudioPlayer>())); | 214 scoped_ptr<AudioPlayer>())); |
| 213 | 215 |
| 214 view_->set_frame_producer(client_->GetFrameProducer()); | 216 view_->set_frame_producer(client_->GetFrameProducer()); |
| 215 | 217 |
| 216 signaling_config_.reset(new XmppSignalStrategy::XmppServerConfig()); | 218 signaling_config_.reset(new XmppSignalStrategy::XmppServerConfig()); |
| 217 signaling_config_->host = CHAT_SERVER; | 219 signaling_config_->host = CHAT_SERVER; |
| 218 signaling_config_->port = CHAT_PORT; | 220 signaling_config_->port = CHAT_PORT; |
| 219 signaling_config_->use_tls = CHAT_USE_TLS; | 221 signaling_config_->use_tls = CHAT_USE_TLS; |
| 220 | 222 |
| 221 signaling_.reset(new XmppSignalStrategy( | 223 signaling_.reset(new XmppSignalStrategy( |
| 222 ChromotingJni::GetInstance()->url_requester(), | 224 ChromotingJniRuntime::GetInstance()->url_requester(), |
| 223 username_, | 225 username_, |
| 224 auth_token_, | 226 auth_token_, |
| 225 "oauth2", | 227 "oauth2", |
| 226 *signaling_config_)); | 228 *signaling_config_)); |
| 227 | 229 |
| 228 network_settings_.reset(new NetworkSettings( | 230 network_settings_.reset(new NetworkSettings( |
| 229 NetworkSettings::NAT_TRAVERSAL_OUTGOING)); | 231 NetworkSettings::NAT_TRAVERSAL_OUTGOING)); |
| 230 scoped_ptr<protocol::TransportFactory> fact( | 232 scoped_ptr<protocol::TransportFactory> fact( |
| 231 protocol::LibjingleTransportFactory::Create( | 233 protocol::LibjingleTransportFactory::Create( |
| 232 *network_settings_, | 234 *network_settings_, |
| 233 ChromotingJni::GetInstance()->url_requester())); | 235 ChromotingJniRuntime::GetInstance()->url_requester())); |
| 234 | 236 |
| 235 client_->Start(signaling_.get(), fact.Pass()); | 237 client_->Start(signaling_.get(), fact.Pass()); |
| 236 } | 238 } |
| 237 | 239 |
| 238 void ChromotingJniInstance::DisconnectFromHostOnNetworkThread() { | 240 void ChromotingJniInstance::DisconnectFromHostOnNetworkThread() { |
| 239 DCHECK(ChromotingJni::GetInstance()-> | 241 DCHECK(ChromotingJniRuntime::GetInstance()-> |
| 240 network_task_runner()->BelongsToCurrentThread()); | 242 network_task_runner()->BelongsToCurrentThread()); |
| 241 | 243 |
| 242 username_ = ""; | 244 username_ = ""; |
| 243 auth_token_ = ""; | 245 auth_token_ = ""; |
| 244 host_jid_ = ""; | 246 host_jid_ = ""; |
| 245 host_id_ = ""; | 247 host_id_ = ""; |
| 246 host_pubkey_ = ""; | 248 host_pubkey_ = ""; |
| 247 | 249 |
| 248 // |client_| must be torn down before |signaling_|. | 250 // |client_| must be torn down before |signaling_|. |
| 249 connection_.reset(); | 251 connection_.reset(); |
| 250 client_.reset(); | 252 client_.reset(); |
| 251 } | 253 } |
| 252 | 254 |
| 253 void ChromotingJniInstance::FetchSecret( | 255 void ChromotingJniInstance::FetchSecret( |
| 254 bool pairable, | 256 bool pairable, |
| 255 const protocol::SecretFetchedCallback& callback) { | 257 const protocol::SecretFetchedCallback& callback) { |
| 256 if (!ChromotingJni::GetInstance()-> | 258 if (!ChromotingJniRuntime::GetInstance()-> |
| 257 ui_task_runner()->BelongsToCurrentThread()) { | 259 ui_task_runner()->BelongsToCurrentThread()) { |
| 258 ChromotingJni::GetInstance()->ui_task_runner()->PostTask( | 260 ChromotingJniRuntime::GetInstance()->ui_task_runner()->PostTask( |
| 259 FROM_HERE, | 261 FROM_HERE, |
| 260 base::Bind(&ChromotingJniInstance::FetchSecret, | 262 base::Bind(&ChromotingJniInstance::FetchSecret, |
| 261 this, | 263 this, |
| 262 pairable, | 264 pairable, |
| 263 callback)); | 265 callback)); |
| 264 return; | 266 return; |
| 265 } | 267 } |
| 266 | 268 |
| 267 pin_callback_ = callback; | 269 pin_callback_ = callback; |
| 268 ChromotingJni::GetInstance()->DisplayAuthenticationPrompt(); | 270 ChromotingJniRuntime::GetInstance()->DisplayAuthenticationPrompt(); |
| 269 } | 271 } |
| 270 | 272 |
| 271 } // namespace remoting | 273 } // namespace remoting |
| OLD | NEW |