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 <android/log.h> | 7 #include <android/log.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "net/socket/client_socket_factory.h" | 11 #include "net/socket/client_socket_factory.h" |
| 12 #include "remoting/client/audio_player.h" | 12 #include "remoting/client/audio_player.h" |
| 13 #include "remoting/client/jni/android_keymap.h" | 13 #include "remoting/client/jni/android_keymap.h" |
| 14 #include "remoting/client/jni/chromoting_jni_runtime.h" | 14 #include "remoting/client/jni/chromoting_jni_runtime.h" |
| 15 #include "remoting/client/log_to_server.h" | |
| 16 #include "remoting/client/server_log_entry.h" | |
| 15 #include "remoting/client/software_video_renderer.h" | 17 #include "remoting/client/software_video_renderer.h" |
| 16 #include "remoting/jingle_glue/chromium_port_allocator.h" | 18 #include "remoting/jingle_glue/chromium_port_allocator.h" |
| 17 #include "remoting/jingle_glue/chromium_socket_factory.h" | 19 #include "remoting/jingle_glue/chromium_socket_factory.h" |
| 18 #include "remoting/jingle_glue/network_settings.h" | 20 #include "remoting/jingle_glue/network_settings.h" |
| 19 #include "remoting/protocol/host_stub.h" | 21 #include "remoting/protocol/host_stub.h" |
| 20 #include "remoting/protocol/libjingle_transport_factory.h" | 22 #include "remoting/protocol/libjingle_transport_factory.h" |
| 21 | 23 |
| 22 namespace remoting { | 24 namespace remoting { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // TODO(solb) Move into location shared with client plugin. | 28 // TODO(solb) Move into location shared with client plugin. |
| 27 const char* const kXmppServer = "talk.google.com"; | 29 const char* const kXmppServer = "talk.google.com"; |
| 28 const int kXmppPort = 5222; | 30 const int kXmppPort = 5222; |
| 29 const bool kXmppUseTls = true; | 31 const bool kXmppUseTls = true; |
| 30 | 32 |
| 31 // Interval at which to log performance statistics, if enabled. | 33 // Interval at which to log performance statistics, if enabled. |
| 32 const int kPerfStatsIntervalMs = 10000; | 34 const int kPerfStatsIntervalMs = 60000; |
| 33 | 35 |
| 34 } | 36 } |
| 35 | 37 |
| 36 ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, | 38 ChromotingJniInstance::ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, |
| 37 const char* username, | 39 const char* username, |
| 38 const char* auth_token, | 40 const char* auth_token, |
| 39 const char* host_jid, | 41 const char* host_jid, |
| 40 const char* host_id, | 42 const char* host_id, |
| 41 const char* host_pubkey, | 43 const char* host_pubkey, |
| 42 const char* pairing_id, | 44 const char* pairing_id, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 video_renderer_->GetStats()->video_paint_ms()->Record(paint_time_ms); | 210 video_renderer_->GetStats()->video_paint_ms()->Record(paint_time_ms); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void ChromotingJniInstance::OnConnectionState( | 213 void ChromotingJniInstance::OnConnectionState( |
| 212 protocol::ConnectionToHost::State state, | 214 protocol::ConnectionToHost::State state, |
| 213 protocol::ErrorCode error) { | 215 protocol::ErrorCode error) { |
| 214 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 216 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 215 | 217 |
| 216 EnableStatsLogging(state == protocol::ConnectionToHost::CONNECTED); | 218 EnableStatsLogging(state == protocol::ConnectionToHost::CONNECTED); |
| 217 | 219 |
| 220 log_to_server_->LogSessionStateChange(state, error); | |
| 221 | |
| 218 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { | 222 if (create_pairing_ && state == protocol::ConnectionToHost::CONNECTED) { |
| 219 protocol::PairingRequest request; | 223 protocol::PairingRequest request; |
| 220 DCHECK(!device_name_.empty()); | 224 DCHECK(!device_name_.empty()); |
| 221 request.set_client_name(device_name_); | 225 request.set_client_name(device_name_); |
| 222 connection_->host_stub()->RequestPairing(request); | 226 connection_->host_stub()->RequestPairing(request); |
| 223 } | 227 } |
| 224 | 228 |
| 225 jni_runtime_->ui_task_runner()->PostTask( | 229 jni_runtime_->ui_task_runner()->PostTask( |
| 226 FROM_HERE, | 230 FROM_HERE, |
| 227 base::Bind(&ChromotingJniRuntime::ReportConnectionStatus, | 231 base::Bind(&ChromotingJniRuntime::ReportConnectionStatus, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 | 329 |
| 326 client_.reset(new ChromotingClient( | 330 client_.reset(new ChromotingClient( |
| 327 client_config_, client_context_.get(), connection_.get(), | 331 client_config_, client_context_.get(), connection_.get(), |
| 328 this, video_renderer_.get(), scoped_ptr<AudioPlayer>())); | 332 this, video_renderer_.get(), scoped_ptr<AudioPlayer>())); |
| 329 | 333 |
| 330 | 334 |
| 331 signaling_.reset(new XmppSignalStrategy( | 335 signaling_.reset(new XmppSignalStrategy( |
| 332 net::ClientSocketFactory::GetDefaultFactory(), | 336 net::ClientSocketFactory::GetDefaultFactory(), |
| 333 jni_runtime_->url_requester(), xmpp_config_)); | 337 jni_runtime_->url_requester(), xmpp_config_)); |
| 334 | 338 |
| 339 log_to_server_.reset(new client::LogToServer(client::ServerLogEntry::ME2ME, | |
| 340 signaling_.get(), | |
| 341 "remoting@bot.talk.google.com")); | |
|
Sergey Ulanov
2014/05/16 22:44:17
Move kDirectoryBotJid from remoting/host/service_u
| |
| 342 | |
| 335 NetworkSettings network_settings(NetworkSettings::NAT_TRAVERSAL_FULL); | 343 NetworkSettings network_settings(NetworkSettings::NAT_TRAVERSAL_FULL); |
| 336 | 344 |
| 337 // Use Chrome's network stack to allocate ports for peer-to-peer channels. | 345 // Use Chrome's network stack to allocate ports for peer-to-peer channels. |
| 338 scoped_ptr<ChromiumPortAllocator> port_allocator( | 346 scoped_ptr<ChromiumPortAllocator> port_allocator( |
| 339 ChromiumPortAllocator::Create(jni_runtime_->url_requester(), | 347 ChromiumPortAllocator::Create(jni_runtime_->url_requester(), |
| 340 network_settings)); | 348 network_settings)); |
| 341 | 349 |
| 342 scoped_ptr<protocol::TransportFactory> transport_factory( | 350 scoped_ptr<protocol::TransportFactory> transport_factory( |
| 343 new protocol::LibjingleTransportFactory( | 351 new protocol::LibjingleTransportFactory( |
| 344 signaling_.get(), | 352 signaling_.get(), |
| 345 port_allocator.PassAs<cricket::HttpPortAllocatorBase>(), | 353 port_allocator.PassAs<cricket::HttpPortAllocatorBase>(), |
| 346 network_settings)); | 354 network_settings)); |
| 347 | 355 |
| 348 client_->Start(signaling_.get(), transport_factory.Pass()); | 356 client_->Start(signaling_.get(), transport_factory.Pass()); |
| 349 } | 357 } |
| 350 | 358 |
| 351 void ChromotingJniInstance::DisconnectFromHostOnNetworkThread() { | 359 void ChromotingJniInstance::DisconnectFromHostOnNetworkThread() { |
| 352 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 360 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 353 | 361 |
| 354 host_id_.clear(); | 362 host_id_.clear(); |
| 355 | 363 |
| 356 stats_logging_enabled_ = false; | 364 stats_logging_enabled_ = false; |
| 357 | 365 |
| 358 // |client_| must be torn down before |signaling_|. | 366 // |client_| must be torn down before |signaling_|. |
| 359 connection_.reset(); | 367 connection_.reset(); |
| 360 client_.reset(); | 368 client_.reset(); |
| 369 log_to_server_.reset(); | |
| 361 } | 370 } |
| 362 | 371 |
| 363 void ChromotingJniInstance::FetchSecret( | 372 void ChromotingJniInstance::FetchSecret( |
| 364 bool pairable, | 373 bool pairable, |
| 365 const protocol::SecretFetchedCallback& callback) { | 374 const protocol::SecretFetchedCallback& callback) { |
| 366 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { | 375 if (!jni_runtime_->ui_task_runner()->BelongsToCurrentThread()) { |
| 367 jni_runtime_->ui_task_runner()->PostTask( | 376 jni_runtime_->ui_task_runner()->PostTask( |
| 368 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, | 377 FROM_HERE, base::Bind(&ChromotingJniInstance::FetchSecret, |
| 369 this, pairable, callback)); | 378 this, pairable, callback)); |
| 370 return; | 379 return; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 "Bandwidth:%.0f FrameRate:%.1f Capture:%.1f Encode:%.1f " | 422 "Bandwidth:%.0f FrameRate:%.1f Capture:%.1f Encode:%.1f " |
| 414 "Decode:%.1f Render:%.1f Latency:%.0f", | 423 "Decode:%.1f Render:%.1f Latency:%.0f", |
| 415 stats->video_bandwidth()->Rate(), | 424 stats->video_bandwidth()->Rate(), |
| 416 stats->video_frame_rate()->Rate(), | 425 stats->video_frame_rate()->Rate(), |
| 417 stats->video_capture_ms()->Average(), | 426 stats->video_capture_ms()->Average(), |
| 418 stats->video_encode_ms()->Average(), | 427 stats->video_encode_ms()->Average(), |
| 419 stats->video_decode_ms()->Average(), | 428 stats->video_decode_ms()->Average(), |
| 420 stats->video_paint_ms()->Average(), | 429 stats->video_paint_ms()->Average(), |
| 421 stats->round_trip_ms()->Average()); | 430 stats->round_trip_ms()->Average()); |
| 422 | 431 |
| 432 log_to_server_->LogStatistics(stats); | |
| 433 | |
| 423 jni_runtime_->network_task_runner()->PostDelayedTask( | 434 jni_runtime_->network_task_runner()->PostDelayedTask( |
| 424 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), | 435 FROM_HERE, base::Bind(&ChromotingJniInstance::LogPerfStats, this), |
| 425 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 436 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
| 426 } | 437 } |
| 427 | 438 |
| 428 } // namespace remoting | 439 } // namespace remoting |
| OLD | NEW |