OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "remoting/base/logger.h" | |
10 #include "remoting/base/tracer.h" | 9 #include "remoting/base/tracer.h" |
11 #include "remoting/client/chromoting_view.h" | 10 #include "remoting/client/chromoting_view.h" |
12 #include "remoting/client/client_context.h" | 11 #include "remoting/client/client_context.h" |
13 #include "remoting/client/input_handler.h" | 12 #include "remoting/client/input_handler.h" |
14 #include "remoting/client/rectangle_update_decoder.h" | 13 #include "remoting/client/rectangle_update_decoder.h" |
15 #include "remoting/protocol/connection_to_host.h" | 14 #include "remoting/protocol/connection_to_host.h" |
16 #include "remoting/protocol/session_config.h" | 15 #include "remoting/protocol/session_config.h" |
17 | 16 |
18 namespace remoting { | 17 namespace remoting { |
19 | 18 |
20 ChromotingClient::ChromotingClient(const ClientConfig& config, | 19 ChromotingClient::ChromotingClient(const ClientConfig& config, |
21 ClientContext* context, | 20 ClientContext* context, |
22 protocol::ConnectionToHost* connection, | 21 protocol::ConnectionToHost* connection, |
23 ChromotingView* view, | 22 ChromotingView* view, |
24 RectangleUpdateDecoder* rectangle_decoder, | 23 RectangleUpdateDecoder* rectangle_decoder, |
25 InputHandler* input_handler, | 24 InputHandler* input_handler, |
26 Logger* logger, | |
27 Task* client_done) | 25 Task* client_done) |
28 : config_(config), | 26 : config_(config), |
29 context_(context), | 27 context_(context), |
30 connection_(connection), | 28 connection_(connection), |
31 view_(view), | 29 view_(view), |
32 rectangle_decoder_(rectangle_decoder), | 30 rectangle_decoder_(rectangle_decoder), |
33 input_handler_(input_handler), | 31 input_handler_(input_handler), |
34 logger_(logger), | |
35 client_done_(client_done), | 32 client_done_(client_done), |
36 state_(CREATED), | 33 state_(CREATED), |
37 packet_being_processed_(false), | 34 packet_being_processed_(false), |
38 last_sequence_number_(0) { | 35 last_sequence_number_(0) { |
39 } | 36 } |
40 | 37 |
41 ChromotingClient::~ChromotingClient() { | 38 ChromotingClient::~ChromotingClient() { |
42 } | 39 } |
43 | 40 |
44 void ChromotingClient::Start(scoped_refptr<XmppProxy> xmpp_proxy) { | 41 void ChromotingClient::Start(scoped_refptr<XmppProxy> xmpp_proxy) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 base::Time decode_start; | 161 base::Time decode_start; |
165 if (last_packet) | 162 if (last_packet) |
166 decode_start = base::Time::Now(); | 163 decode_start = base::Time::Now(); |
167 | 164 |
168 rectangle_decoder_->DecodePacket( | 165 rectangle_decoder_->DecodePacket( |
169 packet, NewTracedMethod(this, &ChromotingClient::OnPacketDone, | 166 packet, NewTracedMethod(this, &ChromotingClient::OnPacketDone, |
170 last_packet, decode_start)); | 167 last_packet, decode_start)); |
171 } | 168 } |
172 | 169 |
173 void ChromotingClient::OnConnectionOpened(protocol::ConnectionToHost* conn) { | 170 void ChromotingClient::OnConnectionOpened(protocol::ConnectionToHost* conn) { |
174 logger_->VLog(1, "ChromotingClient::OnConnectionOpened"); | 171 VLOG(1) << "ChromotingClient::OnConnectionOpened"; |
175 Initialize(); | 172 Initialize(); |
176 SetConnectionState(CONNECTED); | 173 SetConnectionState(CONNECTED); |
177 } | 174 } |
178 | 175 |
179 void ChromotingClient::OnConnectionClosed(protocol::ConnectionToHost* conn) { | 176 void ChromotingClient::OnConnectionClosed(protocol::ConnectionToHost* conn) { |
180 logger_->VLog(1, "ChromotingClient::OnConnectionClosed"); | 177 VLOG(1) << "ChromotingClient::OnConnectionClosed"; |
181 SetConnectionState(DISCONNECTED); | 178 SetConnectionState(DISCONNECTED); |
182 } | 179 } |
183 | 180 |
184 void ChromotingClient::OnConnectionFailed(protocol::ConnectionToHost* conn) { | 181 void ChromotingClient::OnConnectionFailed(protocol::ConnectionToHost* conn) { |
185 logger_->VLog(1, "ChromotingClient::OnConnectionFailed"); | 182 VLOG(1) << "ChromotingClient::OnConnectionFailed"; |
186 SetConnectionState(FAILED); | 183 SetConnectionState(FAILED); |
187 } | 184 } |
188 | 185 |
189 MessageLoop* ChromotingClient::message_loop() { | 186 MessageLoop* ChromotingClient::message_loop() { |
190 return context_->jingle_thread()->message_loop(); | 187 return context_->jingle_thread()->message_loop(); |
191 } | 188 } |
192 | 189 |
193 void ChromotingClient::SetConnectionState(ConnectionState s) { | 190 void ChromotingClient::SetConnectionState(ConnectionState s) { |
194 // TODO(ajwong): We actually may want state to be a shared variable. Think | 191 // TODO(ajwong): We actually may want state to be a shared variable. Think |
195 // through later. | 192 // through later. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return; | 240 return; |
244 } | 241 } |
245 | 242 |
246 TraceContext::tracer()->PrintString("Initializing client."); | 243 TraceContext::tracer()->PrintString("Initializing client."); |
247 | 244 |
248 const protocol::SessionConfig* config = connection_->config(); | 245 const protocol::SessionConfig* config = connection_->config(); |
249 | 246 |
250 // Resize the window. | 247 // Resize the window. |
251 int width = config->initial_resolution().width; | 248 int width = config->initial_resolution().width; |
252 int height = config->initial_resolution().height; | 249 int height = config->initial_resolution().height; |
253 logger_->VLog(1, "Initial screen geometry: %dx%d", width, height); | 250 VLOG(1) << "Initial screen geometry: " << width << "x" << height; |
254 | 251 |
255 // TODO(ajwong): What to do here? Does the decoder actually need to request | 252 // TODO(ajwong): What to do here? Does the decoder actually need to request |
256 // the right frame size? This is mainly an optimization right? | 253 // the right frame size? This is mainly an optimization right? |
257 // rectangle_decoder_->SetOutputFrameSize(width, height); | 254 // rectangle_decoder_->SetOutputFrameSize(width, height); |
258 view_->SetViewport(0, 0, width, height); | 255 view_->SetViewport(0, 0, width, height); |
259 | 256 |
260 // Initialize the decoder. | 257 // Initialize the decoder. |
261 rectangle_decoder_->Initialize(config); | 258 rectangle_decoder_->Initialize(config); |
262 | 259 |
263 // Schedule the input handler to process the event queue. | 260 // Schedule the input handler to process the event queue. |
264 input_handler_->Initialize(); | 261 input_handler_->Initialize(); |
265 } | 262 } |
266 | 263 |
267 //////////////////////////////////////////////////////////////////////////// | 264 //////////////////////////////////////////////////////////////////////////// |
268 // ClientStub control channel interface. | 265 // ClientStub control channel interface. |
269 void ChromotingClient::BeginSessionResponse( | 266 void ChromotingClient::BeginSessionResponse( |
270 const protocol::LocalLoginStatus* msg, Task* done) { | 267 const protocol::LocalLoginStatus* msg, Task* done) { |
271 if (message_loop() != MessageLoop::current()) { | 268 if (message_loop() != MessageLoop::current()) { |
272 message_loop()->PostTask( | 269 message_loop()->PostTask( |
273 FROM_HERE, | 270 FROM_HERE, |
274 NewRunnableMethod(this, &ChromotingClient::BeginSessionResponse, | 271 NewRunnableMethod(this, &ChromotingClient::BeginSessionResponse, |
275 msg, done)); | 272 msg, done)); |
276 return; | 273 return; |
277 } | 274 } |
278 | 275 |
279 logger_->Log(logging::LOG_INFO, "BeginSessionResponse received"); | 276 LOG(INFO) << "BeginSessionResponse received"; |
280 | 277 |
281 // Inform the connection that the client has been authenticated. This will | 278 // Inform the connection that the client has been authenticated. This will |
282 // enable the communication channels. | 279 // enable the communication channels. |
283 if (msg->success()) { | 280 if (msg->success()) { |
284 connection_->OnClientAuthenticated(); | 281 connection_->OnClientAuthenticated(); |
285 } | 282 } |
286 | 283 |
287 view_->UpdateLoginStatus(msg->success(), msg->error_info()); | 284 view_->UpdateLoginStatus(msg->success(), msg->error_info()); |
288 done->Run(); | 285 done->Run(); |
289 delete done; | 286 delete done; |
290 } | 287 } |
291 | 288 |
292 } // namespace remoting | 289 } // namespace remoting |
OLD | NEW |