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

Unified Diff: remoting/host/host_user_interface.cc

Issue 10454040: Replace ScopedThreadProxy with MessageLoopProxy & WeakPtrs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
Index: remoting/host/host_user_interface.cc
diff --git a/remoting/host/host_user_interface.cc b/remoting/host/host_user_interface.cc
index 365b52b6a2ae1eaea330771747c1a066f17f7430..0f52172cce7c5d17b32b12cd120a08dd2df76ff9 100644
--- a/remoting/host/host_user_interface.cc
+++ b/remoting/host/host_user_interface.cc
@@ -16,7 +16,8 @@ HostUserInterface::HostUserInterface(ChromotingHostContext* context)
: host_(NULL),
context_(context),
is_monitoring_local_inputs_(false),
- ui_thread_proxy_(context->ui_message_loop()),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
+ weak_ptr_(weak_factory_.GetWeakPtr()),
disable_disconnect_shortcut_on_mac_(false) {
}
@@ -25,8 +26,6 @@ HostUserInterface::~HostUserInterface() {
MonitorLocalInputs(false);
ShowDisconnectWindow(false, std::string());
-
- ui_thread_proxy_.Detach();
}
void HostUserInterface::Start(ChromotingHost* host,
@@ -47,19 +46,23 @@ void HostUserInterface::DisableDisconnectShortcutOnMac() {
}
void HostUserInterface::OnClientAuthenticated(const std::string& jid) {
+ DCHECK(network_message_loop()->BelongsToCurrentThread());
+
authenticated_jid_ = jid;
std::string username = jid.substr(0, jid.find('/'));
- ui_thread_proxy_.PostTask(FROM_HERE, base::Bind(
+ ui_message_loop()->PostTask(FROM_HERE, base::Bind(
&HostUserInterface::ProcessOnClientAuthenticated,
- base::Unretained(this), username));
+ weak_ptr_, username));
}
void HostUserInterface::OnClientDisconnected(const std::string& jid) {
+ DCHECK(network_message_loop()->BelongsToCurrentThread());
+
if (jid == authenticated_jid_) {
- ui_thread_proxy_.PostTask(FROM_HERE, base::Bind(
+ ui_message_loop()->PostTask(FROM_HERE, base::Bind(
&HostUserInterface::ProcessOnClientDisconnected,
- base::Unretained(this)));
+ weak_ptr_));
}
}
@@ -67,20 +70,23 @@ void HostUserInterface::OnAccessDenied(const std::string& jid) {
}
void HostUserInterface::OnShutdown() {
+ DCHECK(network_message_loop()->BelongsToCurrentThread());
+
// Host status observers must be removed on the network thread, so
// it must happen here instead of in the destructor.
host_->RemoveStatusObserver(this);
host_ = NULL;
+
+ // TODO(wez): This isn't safe, since the callback gets called on UI thread.
Sergey Ulanov 2012/05/29 18:58:30 I think we can just remove this line. The disconne
Wez 2012/05/30 00:18:39 Done. Not sure whether the intent was that Start(
disconnect_callback_ = base::Closure();
}
void HostUserInterface::OnDisconnectCallback() {
DCHECK(ui_message_loop()->BelongsToCurrentThread());
- DCHECK(!disconnect_callback_.is_null());
MonitorLocalInputs(false);
ShowDisconnectWindow(false, std::string());
- disconnect_callback_.Run();
+ DisconnectSession();
Sergey Ulanov 2012/05/29 18:58:30 Do we need DisconnectSession() method at all?
Wez 2012/05/30 00:18:39 It's used by It2MeHostUserInterface when the Disco
}
base::MessageLoopProxy* HostUserInterface::network_message_loop() const {
@@ -91,7 +97,10 @@ base::MessageLoopProxy* HostUserInterface::ui_message_loop() const {
}
void HostUserInterface::DisconnectSession() const {
- return disconnect_callback_.Run();
+ DCHECK(ui_message_loop()->BelongsToCurrentThread());
+ DCHECK(!disconnect_callback_.is_null());
+
+ disconnect_callback_.Run();
}
void HostUserInterface::ProcessOnClientAuthenticated(
@@ -148,7 +157,7 @@ void HostUserInterface::ShowDisconnectWindow(bool show,
disconnect_window_->Show(
host_,
base::Bind(&HostUserInterface::OnDisconnectCallback,
- base::Unretained(this)),
+ weak_ptr_),
username);
} else {
disconnect_window_->Hide();

Powered by Google App Engine
This is Rietveld 408576698