| Index: remoting/client/chromoting_client.cc
|
| diff --git a/remoting/client/chromoting_client.cc b/remoting/client/chromoting_client.cc
|
| index 4dabdd2cf30fd663e12e7901b9a1c04a7d1365f3..2a3aa5681e6f22760579a48fe6856c92bf337429 100644
|
| --- a/remoting/client/chromoting_client.cc
|
| +++ b/remoting/client/chromoting_client.cc
|
| @@ -41,7 +41,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() {
|
| @@ -52,6 +52,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;
|
| if (config_.use_v1_authenticator) {
|
| authenticator.reset(new protocol::V1ClientAuthenticator(
|
| @@ -75,7 +78,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;
|
| }
|
|
|
| @@ -87,7 +90,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) {
|
| @@ -192,7 +195,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;
|
| @@ -216,8 +219,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;
|
| }
|
|
|
|
|