| 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/chromoting_client.h" | 5 #include "remoting/client/chromoting_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "remoting/client/chromoting_view.h" | 8 #include "remoting/client/chromoting_view.h" |
| 9 #include "remoting/client/client_context.h" | 9 #include "remoting/client/client_context.h" |
| 10 #include "remoting/client/rectangle_update_decoder.h" | 10 #include "remoting/client/rectangle_update_decoder.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 RectangleUpdateDecoder* rectangle_decoder, | 34 RectangleUpdateDecoder* rectangle_decoder, |
| 35 const base::Closure& client_done) | 35 const base::Closure& client_done) |
| 36 : config_(config), | 36 : config_(config), |
| 37 context_(context), | 37 context_(context), |
| 38 connection_(connection), | 38 connection_(connection), |
| 39 view_(view), | 39 view_(view), |
| 40 rectangle_decoder_(rectangle_decoder), | 40 rectangle_decoder_(rectangle_decoder), |
| 41 client_done_(client_done), | 41 client_done_(client_done), |
| 42 packet_being_processed_(false), | 42 packet_being_processed_(false), |
| 43 last_sequence_number_(0), | 43 last_sequence_number_(0), |
| 44 thread_proxy_(context_->network_message_loop()) { | 44 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 45 } | 45 } |
| 46 | 46 |
| 47 ChromotingClient::~ChromotingClient() { | 47 ChromotingClient::~ChromotingClient() { |
| 48 } | 48 } |
| 49 | 49 |
| 50 void ChromotingClient::Start( | 50 void ChromotingClient::Start( |
| 51 scoped_refptr<XmppProxy> xmpp_proxy, | 51 scoped_refptr<XmppProxy> xmpp_proxy, |
| 52 scoped_ptr<protocol::TransportFactory> transport_factory) { | 52 scoped_ptr<protocol::TransportFactory> transport_factory) { |
| 53 DCHECK(message_loop()->BelongsToCurrentThread()); | 53 DCHECK(message_loop()->BelongsToCurrentThread()); |
| 54 | 54 |
| 55 // Create a WeakPtr to ourself for to use for all posted tasks. |
| 56 weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 57 |
| 55 scoped_ptr<protocol::Authenticator> authenticator; | 58 scoped_ptr<protocol::Authenticator> authenticator; |
| 56 if (config_.use_v1_authenticator) { | 59 if (config_.use_v1_authenticator) { |
| 57 authenticator.reset(new protocol::V1ClientAuthenticator( | 60 authenticator.reset(new protocol::V1ClientAuthenticator( |
| 58 config_.local_jid, config_.shared_secret)); | 61 config_.local_jid, config_.shared_secret)); |
| 59 } else { | 62 } else { |
| 60 authenticator = protocol::NegotiatingAuthenticator::CreateForClient( | 63 authenticator = protocol::NegotiatingAuthenticator::CreateForClient( |
| 61 config_.authentication_tag, | 64 config_.authentication_tag, |
| 62 config_.shared_secret, config_.authentication_methods); | 65 config_.shared_secret, config_.authentication_methods); |
| 63 } | 66 } |
| 64 | 67 |
| 65 connection_->Connect(xmpp_proxy, config_.local_jid, config_.host_jid, | 68 connection_->Connect(xmpp_proxy, config_.local_jid, config_.host_jid, |
| 66 config_.host_public_key, transport_factory.Pass(), | 69 config_.host_public_key, transport_factory.Pass(), |
| 67 authenticator.Pass(), this, this, this, this); | 70 authenticator.Pass(), this, this, this, this); |
| 68 | 71 |
| 69 if (!view_->Initialize()) { | 72 if (!view_->Initialize()) { |
| 70 ClientDone(); | 73 ClientDone(); |
| 71 } | 74 } |
| 72 } | 75 } |
| 73 | 76 |
| 74 void ChromotingClient::Stop(const base::Closure& shutdown_task) { | 77 void ChromotingClient::Stop(const base::Closure& shutdown_task) { |
| 75 if (!message_loop()->BelongsToCurrentThread()) { | 78 if (!message_loop()->BelongsToCurrentThread()) { |
| 76 message_loop()->PostTask( | 79 message_loop()->PostTask( |
| 77 FROM_HERE, base::Bind(&ChromotingClient::Stop, | 80 FROM_HERE, base::Bind(&ChromotingClient::Stop, |
| 78 base::Unretained(this), shutdown_task)); | 81 weak_ptr_, shutdown_task)); |
| 79 return; | 82 return; |
| 80 } | 83 } |
| 81 | 84 |
| 82 // Drop all pending packets. | 85 // Drop all pending packets. |
| 83 while(!received_packets_.empty()) { | 86 while(!received_packets_.empty()) { |
| 84 delete received_packets_.front().packet; | 87 delete received_packets_.front().packet; |
| 85 received_packets_.front().done.Run(); | 88 received_packets_.front().done.Run(); |
| 86 received_packets_.pop_front(); | 89 received_packets_.pop_front(); |
| 87 } | 90 } |
| 88 | 91 |
| 89 connection_->Disconnect(base::Bind(&ChromotingClient::OnDisconnected, | 92 connection_->Disconnect(base::Bind(&ChromotingClient::OnDisconnected, |
| 90 base::Unretained(this), shutdown_task)); | 93 weak_ptr_, shutdown_task)); |
| 91 } | 94 } |
| 92 | 95 |
| 93 void ChromotingClient::OnDisconnected(const base::Closure& shutdown_task) { | 96 void ChromotingClient::OnDisconnected(const base::Closure& shutdown_task) { |
| 94 view_->TearDown(); | 97 view_->TearDown(); |
| 95 | 98 |
| 96 shutdown_task.Run(); | 99 shutdown_task.Run(); |
| 97 } | 100 } |
| 98 | 101 |
| 99 void ChromotingClient::ClientDone() { | 102 void ChromotingClient::ClientDone() { |
| 100 if (!client_done_.is_null()) { | 103 if (!client_done_.is_null()) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 view_->SetConnectionState(state, error); | 188 view_->SetConnectionState(state, error); |
| 186 } | 189 } |
| 187 | 190 |
| 188 base::MessageLoopProxy* ChromotingClient::message_loop() { | 191 base::MessageLoopProxy* ChromotingClient::message_loop() { |
| 189 return context_->network_message_loop(); | 192 return context_->network_message_loop(); |
| 190 } | 193 } |
| 191 | 194 |
| 192 void ChromotingClient::OnPacketDone(bool last_packet, | 195 void ChromotingClient::OnPacketDone(bool last_packet, |
| 193 base::Time decode_start) { | 196 base::Time decode_start) { |
| 194 if (!message_loop()->BelongsToCurrentThread()) { | 197 if (!message_loop()->BelongsToCurrentThread()) { |
| 195 thread_proxy_.PostTask(FROM_HERE, base::Bind( | 198 message_loop()->PostTask(FROM_HERE, base::Bind( |
| 196 &ChromotingClient::OnPacketDone, base::Unretained(this), | 199 &ChromotingClient::OnPacketDone, base::Unretained(this), |
| 197 last_packet, decode_start)); | 200 last_packet, decode_start)); |
| 198 return; | 201 return; |
| 199 } | 202 } |
| 200 | 203 |
| 201 // Record the latency between the final packet being received and | 204 // Record the latency between the final packet being received and |
| 202 // presented. | 205 // presented. |
| 203 if (last_packet) { | 206 if (last_packet) { |
| 204 stats_.video_decode_ms()->Record( | 207 stats_.video_decode_ms()->Record( |
| 205 (base::Time::Now() - decode_start).InMilliseconds()); | 208 (base::Time::Now() - decode_start).InMilliseconds()); |
| 206 } | 209 } |
| 207 | 210 |
| 208 received_packets_.front().done.Run(); | 211 received_packets_.front().done.Run(); |
| 209 received_packets_.pop_front(); | 212 received_packets_.pop_front(); |
| 210 | 213 |
| 211 packet_being_processed_ = false; | 214 packet_being_processed_ = false; |
| 212 | 215 |
| 213 // Process the next video packet. | 216 // Process the next video packet. |
| 214 DispatchPacket(); | 217 DispatchPacket(); |
| 215 } | 218 } |
| 216 | 219 |
| 217 void ChromotingClient::Initialize() { | 220 void ChromotingClient::Initialize() { |
| 218 if (!message_loop()->BelongsToCurrentThread()) { | 221 if (!message_loop()->BelongsToCurrentThread()) { |
| 219 thread_proxy_.PostTask(FROM_HERE, base::Bind( | 222 message_loop()->PostTask(FROM_HERE, base::Bind( |
| 220 &ChromotingClient::Initialize, base::Unretained(this))); | 223 &ChromotingClient::Initialize, weak_ptr_)); |
| 221 return; | 224 return; |
| 222 } | 225 } |
| 223 | 226 |
| 224 // Initialize the decoder. | 227 // Initialize the decoder. |
| 225 rectangle_decoder_->Initialize(connection_->config()); | 228 rectangle_decoder_->Initialize(connection_->config()); |
| 226 } | 229 } |
| 227 | 230 |
| 228 } // namespace remoting | 231 } // namespace remoting |
| OLD | NEW |