Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/plugin/chromoting_instance.h" | 5 #include "remoting/client/plugin/chromoting_instance.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #if defined(OS_NACL) | 10 #if defined(OS_NACL) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "remoting/base/constants.h" | 37 #include "remoting/base/constants.h" |
| 38 #include "remoting/base/util.h" | 38 #include "remoting/base/util.h" |
| 39 #include "remoting/client/chromoting_client.h" | 39 #include "remoting/client/chromoting_client.h" |
| 40 #include "remoting/client/plugin/delegating_signal_strategy.h" | 40 #include "remoting/client/plugin/delegating_signal_strategy.h" |
| 41 #include "remoting/client/plugin/normalizing_input_filter_cros.h" | 41 #include "remoting/client/plugin/normalizing_input_filter_cros.h" |
| 42 #include "remoting/client/plugin/normalizing_input_filter_mac.h" | 42 #include "remoting/client/plugin/normalizing_input_filter_mac.h" |
| 43 #include "remoting/client/plugin/pepper_audio_player.h" | 43 #include "remoting/client/plugin/pepper_audio_player.h" |
| 44 #include "remoting/client/plugin/pepper_mouse_locker.h" | 44 #include "remoting/client/plugin/pepper_mouse_locker.h" |
| 45 #include "remoting/client/plugin/pepper_port_allocator.h" | 45 #include "remoting/client/plugin/pepper_port_allocator.h" |
| 46 #include "remoting/client/plugin/pepper_video_renderer_2d.h" | 46 #include "remoting/client/plugin/pepper_video_renderer_2d.h" |
| 47 #include "remoting/client/plugin/pepper_video_renderer_3d.h" | |
| 47 #include "remoting/client/software_video_renderer.h" | 48 #include "remoting/client/software_video_renderer.h" |
| 48 #include "remoting/client/token_fetcher_proxy.h" | 49 #include "remoting/client/token_fetcher_proxy.h" |
| 49 #include "remoting/protocol/connection_to_host.h" | 50 #include "remoting/protocol/connection_to_host.h" |
| 50 #include "remoting/protocol/host_stub.h" | 51 #include "remoting/protocol/host_stub.h" |
| 51 #include "remoting/protocol/libjingle_transport_factory.h" | 52 #include "remoting/protocol/libjingle_transport_factory.h" |
| 52 #include "third_party/webrtc/base/helpers.h" | 53 #include "third_party/webrtc/base/helpers.h" |
| 53 #include "third_party/webrtc/base/ssladapter.h" | 54 #include "third_party/webrtc/base/ssladapter.h" |
| 54 #include "url/gurl.h" | 55 #include "url/gurl.h" |
| 55 | 56 |
| 56 // Windows defines 'PostMessage', so we have to undef it. | 57 // Windows defines 'PostMessage', so we have to undef it. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 data->SetInteger("apiMinVersion", kApiMinMessagingVersion); | 243 data->SetInteger("apiMinVersion", kApiMinMessagingVersion); |
| 243 data->SetString("requestedCapabilities", kRequestedCapabilities); | 244 data->SetString("requestedCapabilities", kRequestedCapabilities); |
| 244 data->SetString("supportedCapabilities", kSupportedCapabilities); | 245 data->SetString("supportedCapabilities", kSupportedCapabilities); |
| 245 | 246 |
| 246 PostLegacyJsonMessage("hello", data.Pass()); | 247 PostLegacyJsonMessage("hello", data.Pass()); |
| 247 } | 248 } |
| 248 | 249 |
| 249 ChromotingInstance::~ChromotingInstance() { | 250 ChromotingInstance::~ChromotingInstance() { |
| 250 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 251 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 251 | 252 |
| 253 // Disconnect the client. | |
| 254 Disconnect(); | |
| 255 | |
| 252 // Unregister this instance so that debug log messages will no longer be sent | 256 // Unregister this instance so that debug log messages will no longer be sent |
| 253 // to it. This will stop all logging in all Chromoting instances. | 257 // to it. This will stop all logging in all Chromoting instances. |
| 254 UnregisterLoggingInstance(); | 258 UnregisterLoggingInstance(); |
| 255 | 259 |
| 256 client_.reset(); | |
| 257 video_renderer_.reset(); | |
| 258 | |
| 259 plugin_task_runner_->Quit(); | 260 plugin_task_runner_->Quit(); |
| 260 | 261 |
| 261 // Ensure that nothing touches the plugin thread delegate after this point. | 262 // Ensure that nothing touches the plugin thread delegate after this point. |
| 262 plugin_task_runner_->DetachAndRunShutdownLoop(); | 263 plugin_task_runner_->DetachAndRunShutdownLoop(); |
| 263 | 264 |
| 264 // Stopping the context shuts down all chromoting threads. | 265 // Stopping the context shuts down all chromoting threads. |
| 265 context_.Stop(); | 266 context_.Stop(); |
| 266 } | 267 } |
| 267 | 268 |
| 268 bool ChromotingInstance::Init(uint32_t argc, | 269 bool ChromotingInstance::Init(uint32_t argc, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 | 377 |
| 377 bool ChromotingInstance::HandleInputEvent(const pp::InputEvent& event) { | 378 bool ChromotingInstance::HandleInputEvent(const pp::InputEvent& event) { |
| 378 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 379 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 379 | 380 |
| 380 if (!IsConnected()) | 381 if (!IsConnected()) |
| 381 return false; | 382 return false; |
| 382 | 383 |
| 383 return input_handler_.HandleInputEvent(event); | 384 return input_handler_.HandleInputEvent(event); |
| 384 } | 385 } |
| 385 | 386 |
| 387 void ChromotingInstance::OnVideoDecodeError() { | |
| 388 Disconnect(); | |
| 389 | |
| 390 // Assume that the decoder failure was caused by the host not encoding video | |
| 391 // correctly and report it as a protocol error. | |
| 392 // TODO(sergeyu): Consider using a different error code in case the decoder | |
| 393 // error was caused by some other problem. | |
| 394 OnConnectionState(protocol::ConnectionToHost::FAILED, | |
| 395 protocol::INCOMPATIBLE_PROTOCOL); | |
| 396 } | |
| 397 | |
| 386 void ChromotingInstance::OnVideoFirstFrameReceived() { | 398 void ChromotingInstance::OnVideoFirstFrameReceived() { |
| 387 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 399 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 388 PostLegacyJsonMessage("onFirstFrameReceived", data.Pass()); | 400 PostLegacyJsonMessage("onFirstFrameReceived", data.Pass()); |
| 389 } | 401 } |
| 390 | 402 |
| 391 void ChromotingInstance::OnVideoSize(const webrtc::DesktopSize& size, | 403 void ChromotingInstance::OnVideoSize(const webrtc::DesktopSize& size, |
| 392 const webrtc::DesktopVector& dpi) { | 404 const webrtc::DesktopVector& dpi) { |
| 393 mouse_input_filter_.set_output_size(size); | 405 mouse_input_filter_.set_output_size(size); |
| 394 | 406 |
| 395 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 407 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 } | 629 } |
| 618 #elif defined(OS_MACOSX) | 630 #elif defined(OS_MACOSX) |
| 619 normalizing_input_filter_.reset(new NormalizingInputFilterMac(&key_mapper_)); | 631 normalizing_input_filter_.reset(new NormalizingInputFilterMac(&key_mapper_)); |
| 620 #elif defined(OS_CHROMEOS) | 632 #elif defined(OS_CHROMEOS) |
| 621 normalizing_input_filter_.reset(new NormalizingInputFilterCros(&key_mapper_)); | 633 normalizing_input_filter_.reset(new NormalizingInputFilterCros(&key_mapper_)); |
| 622 #else | 634 #else |
| 623 normalizing_input_filter_.reset(new protocol::InputFilter(&key_mapper_)); | 635 normalizing_input_filter_.reset(new protocol::InputFilter(&key_mapper_)); |
| 624 #endif | 636 #endif |
| 625 input_handler_.set_input_stub(normalizing_input_filter_.get()); | 637 input_handler_.set_input_stub(normalizing_input_filter_.get()); |
| 626 | 638 |
| 627 video_renderer_.reset(new PepperVideoRenderer2D()); | 639 video_renderer_.reset(new PepperVideoRenderer3D()); |
| 628 bool initialized = | 640 if (!video_renderer_->Initialize(this, context_, this)) |
| 629 video_renderer_->Initialize(this, context_, this); | 641 video_renderer_.reset(); |
|
Wez
2015/01/06 22:17:10
nit: This would be cleaner if you replaced the new
Sergey Ulanov
2015/01/07 19:37:30
Yes, but given that this is the only place were th
Wez
2015/01/07 20:55:01
Acknowledged.
| |
| 630 CHECK(initialized); | 642 |
| 643 // If we failed to initialize 3D renderer (because there is no hardware | |
| 644 // support on this machine) then use the 2D renderer. | |
| 645 if (!video_renderer_) { | |
| 646 LOG(WARNING) | |
| 647 << "Failed to initialize 3D renderer. Using 2D renderer instead."; | |
| 648 video_renderer_.reset(new PepperVideoRenderer2D()); | |
| 649 if (!video_renderer_->Initialize(this, context_, this)) | |
| 650 video_renderer_.reset(); | |
| 651 } | |
| 652 | |
| 653 CHECK(video_renderer_); | |
| 631 | 654 |
| 632 if (!plugin_view_.is_null()) | 655 if (!plugin_view_.is_null()) |
| 633 video_renderer_->OnViewChanged(plugin_view_); | 656 video_renderer_->OnViewChanged(plugin_view_); |
| 634 | 657 |
| 635 scoped_ptr<AudioPlayer> audio_player(new PepperAudioPlayer(this)); | 658 scoped_ptr<AudioPlayer> audio_player(new PepperAudioPlayer(this)); |
| 636 client_.reset(new ChromotingClient(&context_, this, video_renderer_.get(), | 659 client_.reset(new ChromotingClient(&context_, this, video_renderer_.get(), |
| 637 audio_player.Pass())); | 660 audio_player.Pass())); |
| 638 | 661 |
| 639 // Connect the input pipeline to the protocol stub & initialize components. | 662 // Connect the input pipeline to the protocol stub & initialize components. |
| 640 mouse_input_filter_.set_input_stub(client_->input_stub()); | 663 mouse_input_filter_.set_input_stub(client_->input_stub()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 | 696 |
| 674 // Start timer that periodically sends perf stats. | 697 // Start timer that periodically sends perf stats. |
| 675 plugin_task_runner_->PostDelayedTask( | 698 plugin_task_runner_->PostDelayedTask( |
| 676 FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, | 699 FROM_HERE, base::Bind(&ChromotingInstance::SendPerfStats, |
| 677 weak_factory_.GetWeakPtr()), | 700 weak_factory_.GetWeakPtr()), |
| 678 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); | 701 base::TimeDelta::FromMilliseconds(kPerfStatsIntervalMs)); |
| 679 } | 702 } |
| 680 | 703 |
| 681 void ChromotingInstance::HandleDisconnect(const base::DictionaryValue& data) { | 704 void ChromotingInstance::HandleDisconnect(const base::DictionaryValue& data) { |
| 682 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 705 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
| 683 | 706 Disconnect(); |
| 684 VLOG(0) << "Disconnecting from host."; | |
| 685 | |
| 686 // Disconnect the input pipeline and teardown the connection. | |
| 687 mouse_input_filter_.set_input_stub(NULL); | |
| 688 client_.reset(); | |
| 689 video_renderer_.reset(); | |
| 690 } | 707 } |
| 691 | 708 |
| 692 void ChromotingInstance::HandleOnIncomingIq(const base::DictionaryValue& data) { | 709 void ChromotingInstance::HandleOnIncomingIq(const base::DictionaryValue& data) { |
| 693 std::string iq; | 710 std::string iq; |
| 694 if (!data.GetString("iq", &iq)) { | 711 if (!data.GetString("iq", &iq)) { |
| 695 LOG(ERROR) << "Invalid incomingIq() data."; | 712 LOG(ERROR) << "Invalid incomingIq() data."; |
| 696 return; | 713 return; |
| 697 } | 714 } |
| 698 | 715 |
| 699 // Just ignore the message if it's received before Connect() is called. It's | 716 // Just ignore the message if it's received before Connect() is called. It's |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 917 } | 934 } |
| 918 | 935 |
| 919 void ChromotingInstance::HandleSendMouseInputWhenUnfocused() { | 936 void ChromotingInstance::HandleSendMouseInputWhenUnfocused() { |
| 920 input_handler_.set_send_mouse_input_when_unfocused(true); | 937 input_handler_.set_send_mouse_input_when_unfocused(true); |
| 921 } | 938 } |
| 922 | 939 |
| 923 void ChromotingInstance::HandleDelegateLargeCursors() { | 940 void ChromotingInstance::HandleDelegateLargeCursors() { |
| 924 cursor_setter_.set_delegate_stub(this); | 941 cursor_setter_.set_delegate_stub(this); |
| 925 } | 942 } |
| 926 | 943 |
| 944 void ChromotingInstance::Disconnect() { | |
| 945 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | |
| 946 | |
| 947 VLOG(0) << "Disconnecting from host."; | |
| 948 | |
| 949 // Disconnect the input pipeline and teardown the connection. | |
| 950 mouse_input_filter_.set_input_stub(NULL); | |
| 951 client_.reset(); | |
| 952 video_renderer_.reset(); | |
| 953 } | |
| 954 | |
| 927 void ChromotingInstance::PostChromotingMessage(const std::string& method, | 955 void ChromotingInstance::PostChromotingMessage(const std::string& method, |
| 928 const pp::VarDictionary& data) { | 956 const pp::VarDictionary& data) { |
| 929 pp::VarDictionary message; | 957 pp::VarDictionary message; |
| 930 message.Set(pp::Var("method"), pp::Var(method)); | 958 message.Set(pp::Var("method"), pp::Var(method)); |
| 931 message.Set(pp::Var("data"), data); | 959 message.Set(pp::Var("data"), data); |
| 932 PostMessage(message); | 960 PostMessage(message); |
| 933 } | 961 } |
| 934 | 962 |
| 935 void ChromotingInstance::PostLegacyJsonMessage( | 963 void ChromotingInstance::PostLegacyJsonMessage( |
| 936 const std::string& method, | 964 const std::string& method, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1096 url_components.scheme.len); | 1124 url_components.scheme.len); |
| 1097 return url_scheme == kChromeExtensionUrlScheme; | 1125 return url_scheme == kChromeExtensionUrlScheme; |
| 1098 } | 1126 } |
| 1099 | 1127 |
| 1100 bool ChromotingInstance::IsConnected() { | 1128 bool ChromotingInstance::IsConnected() { |
| 1101 return client_ && | 1129 return client_ && |
| 1102 (client_->connection_state() == protocol::ConnectionToHost::CONNECTED); | 1130 (client_->connection_state() == protocol::ConnectionToHost::CONNECTED); |
| 1103 } | 1131 } |
| 1104 | 1132 |
| 1105 } // namespace remoting | 1133 } // namespace remoting |
| OLD | NEW |