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

Unified Diff: remoting/client/chromoting_client.cc

Issue 10454040: Replace ScopedThreadProxy with MessageLoopProxy & WeakPtrs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review points and tweak comments. Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/client/chromoting_client.h ('k') | remoting/client/plugin/chromoting_instance.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/client/chromoting_client.cc
diff --git a/remoting/client/chromoting_client.cc b/remoting/client/chromoting_client.cc
index 9edb480a61d07bfaad26c0568e885dd670d6192f..b240fad61121eac6feb43507d2ef92e69d256ae3 100644
--- a/remoting/client/chromoting_client.cc
+++ b/remoting/client/chromoting_client.cc
@@ -40,7 +40,7 @@ ChromotingClient::ChromotingClient(const ClientConfig& config,
client_done_(client_done),
packet_being_processed_(false),
last_sequence_number_(0),
- thread_proxy_(context_->network_message_loop()) {
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
ChromotingClient::~ChromotingClient() {
@@ -51,6 +51,9 @@ void ChromotingClient::Start(
scoped_ptr<protocol::TransportFactory> transport_factory) {
DCHECK(message_loop()->BelongsToCurrentThread());
+ // Create a WeakPtr to ourself for to use for all posted tasks.
+ weak_ptr_ = weak_factory_.GetWeakPtr();
+
scoped_ptr<protocol::Authenticator> authenticator;
authenticator = protocol::NegotiatingAuthenticator::CreateForClient(
config_.authentication_tag,
@@ -69,7 +72,7 @@ void ChromotingClient::Stop(const base::Closure& shutdown_task) {
if (!message_loop()->BelongsToCurrentThread()) {
message_loop()->PostTask(
FROM_HERE, base::Bind(&ChromotingClient::Stop,
- base::Unretained(this), shutdown_task));
+ weak_ptr_, shutdown_task));
return;
}
@@ -81,7 +84,7 @@ void ChromotingClient::Stop(const base::Closure& shutdown_task) {
}
connection_->Disconnect(base::Bind(&ChromotingClient::OnDisconnected,
- base::Unretained(this), shutdown_task));
+ weak_ptr_, shutdown_task));
}
void ChromotingClient::OnDisconnected(const base::Closure& shutdown_task) {
@@ -186,7 +189,7 @@ base::MessageLoopProxy* ChromotingClient::message_loop() {
void ChromotingClient::OnPacketDone(bool last_packet,
base::Time decode_start) {
if (!message_loop()->BelongsToCurrentThread()) {
- thread_proxy_.PostTask(FROM_HERE, base::Bind(
+ message_loop()->PostTask(FROM_HERE, base::Bind(
&ChromotingClient::OnPacketDone, base::Unretained(this),
last_packet, decode_start));
return;
@@ -210,8 +213,8 @@ void ChromotingClient::OnPacketDone(bool last_packet,
void ChromotingClient::Initialize() {
if (!message_loop()->BelongsToCurrentThread()) {
- thread_proxy_.PostTask(FROM_HERE, base::Bind(
- &ChromotingClient::Initialize, base::Unretained(this)));
+ message_loop()->PostTask(FROM_HERE, base::Bind(
+ &ChromotingClient::Initialize, weak_ptr_));
return;
}
« 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