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