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

Side by Side Diff: remoting/client/chromoting_client.cc

Issue 1520323007: Simplify ConnectionToHost interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sm_cleanup
Patch Set: Created 5 years 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
OLDNEW
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/chromoting_client.h" 5 #include "remoting/client/chromoting_client.h"
6 6
7 #include "base/bind.h"
8 #include "remoting/base/capabilities.h" 7 #include "remoting/base/capabilities.h"
9 #include "remoting/client/audio_decode_scheduler.h" 8 #include "remoting/client/audio_decode_scheduler.h"
10 #include "remoting/client/audio_player.h" 9 #include "remoting/client/audio_player.h"
11 #include "remoting/client/client_context.h" 10 #include "remoting/client/client_context.h"
12 #include "remoting/client/client_user_interface.h" 11 #include "remoting/client/client_user_interface.h"
13 #include "remoting/client/video_renderer.h" 12 #include "remoting/client/video_renderer.h"
14 #include "remoting/proto/audio.pb.h" 13 #include "remoting/protocol/authenticator.h"
15 #include "remoting/proto/video.pb.h"
16 #include "remoting/protocol/authentication_method.h"
17 #include "remoting/protocol/connection_to_host.h" 14 #include "remoting/protocol/connection_to_host.h"
18 #include "remoting/protocol/host_stub.h" 15 #include "remoting/protocol/host_stub.h"
19 #include "remoting/protocol/negotiating_client_authenticator.h" 16 #include "remoting/protocol/ice_transport.h"
17 #include "remoting/protocol/jingle_session_manager.h"
20 #include "remoting/protocol/session_config.h" 18 #include "remoting/protocol/session_config.h"
21 #include "remoting/protocol/transport_context.h" 19 #include "remoting/protocol/transport_context.h"
22 20
23 namespace remoting { 21 namespace remoting {
24 22
25 using protocol::AuthenticationMethod;
26
27 ChromotingClient::ChromotingClient(ClientContext* client_context, 23 ChromotingClient::ChromotingClient(ClientContext* client_context,
28 ClientUserInterface* user_interface, 24 ClientUserInterface* user_interface,
29 VideoRenderer* video_renderer, 25 VideoRenderer* video_renderer,
30 scoped_ptr<AudioPlayer> audio_player) 26 scoped_ptr<AudioPlayer> audio_player)
31 : task_runner_(client_context->main_task_runner()), 27 : user_interface_(user_interface),
32 user_interface_(user_interface),
33 video_renderer_(video_renderer), 28 video_renderer_(video_renderer),
34 connection_(new protocol::ConnectionToHostImpl()), 29 connection_(new protocol::ConnectionToHostImpl()) {
35 host_capabilities_received_(false) { 30 DCHECK(client_context->main_task_runner()->BelongsToCurrentThread());
36 if (audio_player) { 31 if (audio_player) {
37 audio_decode_scheduler_.reset(new AudioDecodeScheduler( 32 audio_decode_scheduler_.reset(new AudioDecodeScheduler(
38 client_context->main_task_runner(), 33 client_context->main_task_runner(),
39 client_context->audio_decode_task_runner(), audio_player.Pass())); 34 client_context->audio_decode_task_runner(), audio_player.Pass()));
40 } 35 }
41 } 36 }
42 37
43 ChromotingClient::~ChromotingClient() { 38 ChromotingClient::~ChromotingClient() {
44 } 39 if (signal_strategy_)
45 40 signal_strategy_->RemoveListener(this);
46 void ChromotingClient::set_protocol_config(
47 scoped_ptr<protocol::CandidateSessionConfig> config) {
48 connection_->set_candidate_config(config.Pass());
49 } 41 }
50 42
51 void ChromotingClient::SetConnectionToHostForTests( 43 void ChromotingClient::SetConnectionToHostForTests(
52 scoped_ptr<protocol::ConnectionToHost> connection_to_host) { 44 scoped_ptr<protocol::ConnectionToHost> connection_to_host) {
53 connection_ = connection_to_host.Pass(); 45 connection_ = connection_to_host.Pass();
54 } 46 }
55 47
56 void ChromotingClient::Start( 48 void ChromotingClient::Start(
57 SignalStrategy* signal_strategy, 49 SignalStrategy* signal_strategy,
58 scoped_ptr<protocol::Authenticator> authenticator, 50 scoped_ptr<protocol::Authenticator> authenticator,
59 scoped_refptr<protocol::TransportContext> transport_context, 51 scoped_refptr<protocol::TransportContext> transport_context,
60 const std::string& host_jid, 52 const std::string& host_jid,
61 const std::string& capabilities) { 53 const std::string& capabilities) {
62 DCHECK(task_runner_->BelongsToCurrentThread()); 54 DCHECK(thread_checker_.CalledOnValidThread());
63 55
56 host_jid_ = host_jid;
64 local_capabilities_ = capabilities; 57 local_capabilities_ = capabilities;
65 58
66 connection_->set_client_stub(this); 59 connection_->set_client_stub(this);
67 connection_->set_clipboard_stub(this); 60 connection_->set_clipboard_stub(this);
68 connection_->set_video_stub(video_renderer_->GetVideoStub()); 61 connection_->set_video_stub(video_renderer_->GetVideoStub());
69 connection_->set_audio_stub(audio_decode_scheduler_.get()); 62 connection_->set_audio_stub(audio_decode_scheduler_.get());
70 63
71 connection_->Connect(signal_strategy, transport_context, authenticator.Pass(), 64 session_manager_.reset(new protocol::JingleSessionManager(
72 host_jid, this); 65 make_scoped_ptr(new protocol::IceTransportFactory(transport_context)),
66 signal_strategy));
67
68 if (!protocol_config_)
69 protocol_config_ = protocol::CandidateSessionConfig::CreateDefault();
70 if (!audio_decode_scheduler_)
71 protocol_config_->DisableAudioChannel();
72 session_manager_->set_protocol_config(protocol_config_.Pass());
73
74 authenticator_ = authenticator.Pass();
75
76 signal_strategy_ = signal_strategy;
joedow 2015/12/17 16:59:45 No one should be calling this twice (perhaps for r
Sergey Ulanov 2015/12/17 17:32:32 Start() is not supposed to be called more than onc
77 signal_strategy_->AddListener(this);
78
79 switch (signal_strategy_->GetState()) {
80 case SignalStrategy::CONNECTING:
81 // Nothing to do here. Just need to wait until |signal_strategy_| becomes
82 // connected.
83 break;
84 case SignalStrategy::CONNECTED:
85 StartConnection();
86 break;
87 case SignalStrategy::DISCONNECTED:
88 signal_strategy_->Connect();
89 break;
90 }
73 } 91 }
74 92
75 void ChromotingClient::SetCapabilities( 93 void ChromotingClient::SetCapabilities(
76 const protocol::Capabilities& capabilities) { 94 const protocol::Capabilities& capabilities) {
77 DCHECK(task_runner_->BelongsToCurrentThread()); 95 DCHECK(thread_checker_.CalledOnValidThread());
78 96
79 // Only accept the first |protocol::Capabilities| message. 97 // Only accept the first |protocol::Capabilities| message.
80 if (host_capabilities_received_) { 98 if (host_capabilities_received_) {
81 LOG(WARNING) << "protocol::Capabilities has been received already."; 99 LOG(WARNING) << "protocol::Capabilities has been received already.";
82 return; 100 return;
83 } 101 }
84 102
85 host_capabilities_received_ = true; 103 host_capabilities_received_ = true;
86 if (capabilities.has_capabilities()) 104 if (capabilities.has_capabilities())
87 host_capabilities_ = capabilities.capabilities(); 105 host_capabilities_ = capabilities.capabilities();
88 106
89 VLOG(1) << "Host capabilities: " << host_capabilities_; 107 VLOG(1) << "Host capabilities: " << host_capabilities_;
90 108
91 // Calculate the set of capabilities enabled by both client and host and pass 109 // Calculate the set of capabilities enabled by both client and host and pass
92 // it to the webapp. 110 // it to the webapp.
93 user_interface_->SetCapabilities( 111 user_interface_->SetCapabilities(
94 IntersectCapabilities(local_capabilities_, host_capabilities_)); 112 IntersectCapabilities(local_capabilities_, host_capabilities_));
95 } 113 }
96 114
97 void ChromotingClient::SetPairingResponse( 115 void ChromotingClient::SetPairingResponse(
98 const protocol::PairingResponse& pairing_response) { 116 const protocol::PairingResponse& pairing_response) {
99 DCHECK(task_runner_->BelongsToCurrentThread()); 117 DCHECK(thread_checker_.CalledOnValidThread());
100 118
101 user_interface_->SetPairingResponse(pairing_response); 119 user_interface_->SetPairingResponse(pairing_response);
102 } 120 }
103 121
104 void ChromotingClient::DeliverHostMessage( 122 void ChromotingClient::DeliverHostMessage(
105 const protocol::ExtensionMessage& message) { 123 const protocol::ExtensionMessage& message) {
106 DCHECK(task_runner_->BelongsToCurrentThread()); 124 DCHECK(thread_checker_.CalledOnValidThread());
107 125
108 user_interface_->DeliverHostMessage(message); 126 user_interface_->DeliverHostMessage(message);
109 } 127 }
110 128
111 void ChromotingClient::InjectClipboardEvent( 129 void ChromotingClient::InjectClipboardEvent(
112 const protocol::ClipboardEvent& event) { 130 const protocol::ClipboardEvent& event) {
113 DCHECK(task_runner_->BelongsToCurrentThread()); 131 DCHECK(thread_checker_.CalledOnValidThread());
114 132
115 user_interface_->GetClipboardStub()->InjectClipboardEvent(event); 133 user_interface_->GetClipboardStub()->InjectClipboardEvent(event);
116 } 134 }
117 135
118 void ChromotingClient::SetCursorShape( 136 void ChromotingClient::SetCursorShape(
119 const protocol::CursorShapeInfo& cursor_shape) { 137 const protocol::CursorShapeInfo& cursor_shape) {
120 DCHECK(task_runner_->BelongsToCurrentThread()); 138 DCHECK(thread_checker_.CalledOnValidThread());
121 139
122 user_interface_->GetCursorShapeStub()->SetCursorShape(cursor_shape); 140 user_interface_->GetCursorShapeStub()->SetCursorShape(cursor_shape);
123 } 141 }
124 142
125 void ChromotingClient::OnConnectionState( 143 void ChromotingClient::OnConnectionState(
126 protocol::ConnectionToHost::State state, 144 protocol::ConnectionToHost::State state,
127 protocol::ErrorCode error) { 145 protocol::ErrorCode error) {
128 DCHECK(task_runner_->BelongsToCurrentThread()); 146 DCHECK(thread_checker_.CalledOnValidThread());
129 VLOG(1) << "ChromotingClient::OnConnectionState(" << state << ")"; 147 VLOG(1) << "ChromotingClient::OnConnectionState(" << state << ")";
130 148
131 if (state == protocol::ConnectionToHost::AUTHENTICATED) { 149 if (state == protocol::ConnectionToHost::AUTHENTICATED) {
132 OnAuthenticated(); 150 OnAuthenticated();
133 } else if (state == protocol::ConnectionToHost::CONNECTED) { 151 } else if (state == protocol::ConnectionToHost::CONNECTED) {
134 OnChannelsConnected(); 152 OnChannelsConnected();
135 } 153 }
136 user_interface_->OnConnectionState(state, error); 154 user_interface_->OnConnectionState(state, error);
137 } 155 }
138 156
139 void ChromotingClient::OnConnectionReady(bool ready) { 157 void ChromotingClient::OnConnectionReady(bool ready) {
140 VLOG(1) << "ChromotingClient::OnConnectionReady(" << ready << ")"; 158 VLOG(1) << "ChromotingClient::OnConnectionReady(" << ready << ")";
141 user_interface_->OnConnectionReady(ready); 159 user_interface_->OnConnectionReady(ready);
142 } 160 }
143 161
144 void ChromotingClient::OnRouteChanged(const std::string& channel_name, 162 void ChromotingClient::OnRouteChanged(const std::string& channel_name,
145 const protocol::TransportRoute& route) { 163 const protocol::TransportRoute& route) {
146 VLOG(0) << "Using " << protocol::TransportRoute::GetTypeString(route.type) 164 VLOG(0) << "Using " << protocol::TransportRoute::GetTypeString(route.type)
147 << " connection for " << channel_name << " channel"; 165 << " connection for " << channel_name << " channel";
148 user_interface_->OnRouteChanged(channel_name, route); 166 user_interface_->OnRouteChanged(channel_name, route);
149 } 167 }
150 168
169 void ChromotingClient::OnSignalStrategyStateChange(
170 SignalStrategy::State state) {
171 DCHECK(thread_checker_.CalledOnValidThread());
172
173 if (state == SignalStrategy::CONNECTED) {
174 VLOG(1) << "Connected as: " << signal_strategy_->GetLocalJid();
175 // After signaling has been connected we can try connecting to the host.
176 if (connection_ &&
177 connection_->state() == protocol::ConnectionToHost::INITIALIZING) {
178 StartConnection();
179 }
180 } else if (state == SignalStrategy::DISCONNECTED) {
181 VLOG(1) << "Signaling connection closed.";
182 connection_.reset();
183 user_interface_->OnConnectionState(protocol::ConnectionToHost::CLOSED,
184 protocol::SIGNALING_ERROR);
185 }
186 }
187
188 bool ChromotingClient::OnSignalStrategyIncomingStanza(
189 const buzz::XmlElement* stanza) {
190 return false;
191 }
192
193 void ChromotingClient::StartConnection() {
194 DCHECK(thread_checker_.CalledOnValidThread());
195 connection_->Connect(
196 session_manager_->Connect(host_jid_, authenticator_.Pass()), this);
197 }
198
151 void ChromotingClient::OnAuthenticated() { 199 void ChromotingClient::OnAuthenticated() {
152 DCHECK(task_runner_->BelongsToCurrentThread()); 200 DCHECK(thread_checker_.CalledOnValidThread());
153 201
154 // Initialize the decoder. 202 // Initialize the decoder.
155 video_renderer_->OnSessionConfig(connection_->config()); 203 video_renderer_->OnSessionConfig(connection_->config());
156 if (connection_->config().is_audio_enabled()) 204 if (connection_->config().is_audio_enabled())
157 audio_decode_scheduler_->Initialize(connection_->config()); 205 audio_decode_scheduler_->Initialize(connection_->config());
158 } 206 }
159 207
160 void ChromotingClient::OnChannelsConnected() { 208 void ChromotingClient::OnChannelsConnected() {
161 DCHECK(task_runner_->BelongsToCurrentThread()); 209 DCHECK(thread_checker_.CalledOnValidThread());
162 210
163 // Negotiate capabilities with the host. 211 // Negotiate capabilities with the host.
164 VLOG(1) << "Client capabilities: " << local_capabilities_; 212 VLOG(1) << "Client capabilities: " << local_capabilities_;
165 213
166 protocol::Capabilities capabilities; 214 protocol::Capabilities capabilities;
167 capabilities.set_capabilities(local_capabilities_); 215 capabilities.set_capabilities(local_capabilities_);
168 connection_->host_stub()->SetCapabilities(capabilities); 216 connection_->host_stub()->SetCapabilities(capabilities);
169 } 217 }
170 218
171 } // namespace remoting 219 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698