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

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

Issue 10440107: Replace ScopedThreadProxy with MessageLoopProxy & WeakPtrs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use correct TaskRunner reference, and copy instance reference in lock. Created 8 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « remoting/client/chromoting_client.h ('k') | remoting/client/plugin/chromoting_instance.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 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
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 scoped_ptr<protocol::Authenticator> authenticator( 54 scoped_ptr<protocol::Authenticator> authenticator(
55 protocol::NegotiatingAuthenticator::CreateForClient( 55 protocol::NegotiatingAuthenticator::CreateForClient(
56 config_.authentication_tag, 56 config_.authentication_tag,
57 config_.shared_secret, config_.authentication_methods)); 57 config_.shared_secret, config_.authentication_methods));
58 58
59 // Create a WeakPtr to ourself for to use for all posted tasks.
60 weak_ptr_ = weak_factory_.GetWeakPtr();
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 view_->SetConnectionState(state, error); 187 view_->SetConnectionState(state, error);
185 } 188 }
186 189
187 base::MessageLoopProxy* ChromotingClient::message_loop() { 190 base::MessageLoopProxy* ChromotingClient::message_loop() {
188 return context_->network_message_loop(); 191 return context_->network_message_loop();
189 } 192 }
190 193
191 void ChromotingClient::OnPacketDone(bool last_packet, 194 void ChromotingClient::OnPacketDone(bool last_packet,
192 base::Time decode_start) { 195 base::Time decode_start) {
193 if (!message_loop()->BelongsToCurrentThread()) { 196 if (!message_loop()->BelongsToCurrentThread()) {
194 thread_proxy_.PostTask(FROM_HERE, base::Bind( 197 message_loop()->PostTask(FROM_HERE, base::Bind(
195 &ChromotingClient::OnPacketDone, base::Unretained(this), 198 &ChromotingClient::OnPacketDone, base::Unretained(this),
196 last_packet, decode_start)); 199 last_packet, decode_start));
197 return; 200 return;
198 } 201 }
199 202
200 // Record the latency between the final packet being received and 203 // Record the latency between the final packet being received and
201 // presented. 204 // presented.
202 if (last_packet) { 205 if (last_packet) {
203 stats_.video_decode_ms()->Record( 206 stats_.video_decode_ms()->Record(
204 (base::Time::Now() - decode_start).InMilliseconds()); 207 (base::Time::Now() - decode_start).InMilliseconds());
205 } 208 }
206 209
207 received_packets_.front().done.Run(); 210 received_packets_.front().done.Run();
208 received_packets_.pop_front(); 211 received_packets_.pop_front();
209 212
210 packet_being_processed_ = false; 213 packet_being_processed_ = false;
211 214
212 // Process the next video packet. 215 // Process the next video packet.
213 DispatchPacket(); 216 DispatchPacket();
214 } 217 }
215 218
216 void ChromotingClient::Initialize() { 219 void ChromotingClient::Initialize() {
217 if (!message_loop()->BelongsToCurrentThread()) { 220 if (!message_loop()->BelongsToCurrentThread()) {
218 thread_proxy_.PostTask(FROM_HERE, base::Bind( 221 message_loop()->PostTask(FROM_HERE, base::Bind(
219 &ChromotingClient::Initialize, base::Unretained(this))); 222 &ChromotingClient::Initialize, weak_ptr_));
220 return; 223 return;
221 } 224 }
222 225
223 // Initialize the decoder. 226 // Initialize the decoder.
224 rectangle_decoder_->Initialize(connection_->config()); 227 rectangle_decoder_->Initialize(connection_->config());
225 } 228 }
226 229
227 } // namespace remoting 230 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/chromoting_client.h ('k') | remoting/client/plugin/chromoting_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698