summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsimonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-05 02:26:07 +0000
committersimonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-05 02:26:07 +0000
commit34e8a36d6711b98b2190d14a0213dca3c96f82c6 (patch)
tree1aead0ac1f390e882818fb5a150b80eb7462a1ae /remoting
parent3e2d2fc688f3b53aad07d1823659de1e72874e95 (diff)
downloadchromium_src-34e8a36d6711b98b2190d14a0213dca3c96f82c6.zip
chromium_src-34e8a36d6711b98b2190d14a0213dca3c96f82c6.tar.gz
chromium_src-34e8a36d6711b98b2190d14a0213dca3c96f82c6.tar.bz2
[Chromoting] Make SessionEventExecutorWin use a WeakPtr to post messages to itself.
This prevents problems if the SessionEventExecutorWin is destroyed while there's a pending message for it. Review URL: https://chromiumcodereview.appspot.com/10517010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140476 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/session_event_executor_win.cc15
-rw-r--r--remoting/host/session_event_executor_win.h4
2 files changed, 13 insertions, 6 deletions
diff --git a/remoting/host/session_event_executor_win.cc b/remoting/host/session_event_executor_win.cc
index 079a44d..e336011 100644
--- a/remoting/host/session_event_executor_win.cc
+++ b/remoting/host/session_event_executor_win.cc
@@ -50,7 +50,9 @@ SessionEventExecutorWin::SessionEventExecutorWin(
base::MessageLoopProxy* io_message_loop,
scoped_ptr<EventExecutor> nested_executor)
: nested_executor_(nested_executor.Pass()),
- message_loop_(message_loop) {
+ message_loop_(message_loop),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
+ weak_ptr_(weak_ptr_factory_.GetWeakPtr()) {
std::string channel_name =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kProcessChannelId);
@@ -66,6 +68,7 @@ SessionEventExecutorWin::SessionEventExecutorWin(
}
SessionEventExecutorWin::~SessionEventExecutorWin() {
+ DCHECK(MessageLoop::current() == message_loop_);
}
void SessionEventExecutorWin::OnSessionStarted(
@@ -74,7 +77,7 @@ void SessionEventExecutorWin::OnSessionStarted(
message_loop_->PostTask(
FROM_HERE,
base::Bind(&SessionEventExecutorWin::OnSessionStarted,
- base::Unretained(this), base::Passed(&client_clipboard)));
+ weak_ptr_, base::Passed(&client_clipboard)));
return;
}
@@ -86,7 +89,7 @@ void SessionEventExecutorWin::OnSessionFinished() {
message_loop_->PostTask(
FROM_HERE,
base::Bind(&SessionEventExecutorWin::OnSessionFinished,
- base::Unretained(this)));
+ weak_ptr_));
return;
}
@@ -99,7 +102,7 @@ void SessionEventExecutorWin::InjectClipboardEvent(
message_loop_->PostTask(
FROM_HERE,
base::Bind(&SessionEventExecutorWin::InjectClipboardEvent,
- base::Unretained(this), event));
+ weak_ptr_, event));
return;
}
@@ -111,7 +114,7 @@ void SessionEventExecutorWin::InjectKeyEvent(const KeyEvent& event) {
message_loop_->PostTask(
FROM_HERE,
base::Bind(&SessionEventExecutorWin::InjectKeyEvent,
- base::Unretained(this), event));
+ weak_ptr_, event));
return;
}
@@ -143,7 +146,7 @@ void SessionEventExecutorWin::InjectMouseEvent(const MouseEvent& event) {
message_loop_->PostTask(
FROM_HERE,
base::Bind(&SessionEventExecutorWin::InjectMouseEvent,
- base::Unretained(this), event));
+ weak_ptr_, event));
return;
}
diff --git a/remoting/host/session_event_executor_win.h b/remoting/host/session_event_executor_win.h
index d3e650c..e54c3f9 100644
--- a/remoting/host/session_event_executor_win.h
+++ b/remoting/host/session_event_executor_win.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "ipc/ipc_channel.h"
#include "remoting/host/event_executor.h"
@@ -67,6 +68,9 @@ class SessionEventExecutorWin : public EventExecutor,
// Keys currently pressed by the client, used to detect Ctrl-Alt-Del.
std::set<uint32> pressed_keys_;
+ base::WeakPtrFactory<SessionEventExecutorWin> weak_ptr_factory_;
+ base::WeakPtr<SessionEventExecutorWin> weak_ptr_;
+
DISALLOW_COPY_AND_ASSIGN(SessionEventExecutorWin);
};