summaryrefslogtreecommitdiffstats
path: root/remoting/host
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/host')
-rw-r--r--remoting/host/desktop_environment.h1
-rw-r--r--remoting/host/host_user_interface.cc30
-rw-r--r--remoting/host/host_user_interface.h8
-rw-r--r--remoting/host/it2me_host_user_interface.cc41
-rw-r--r--remoting/host/it2me_host_user_interface.h6
5 files changed, 45 insertions, 41 deletions
diff --git a/remoting/host/desktop_environment.h b/remoting/host/desktop_environment.h
index 6d1d80c..f49fcdc 100644
--- a/remoting/host/desktop_environment.h
+++ b/remoting/host/desktop_environment.h
@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
+#include "remoting/base/scoped_thread_proxy.h"
#include "remoting/host/event_executor.h"
namespace remoting {
diff --git a/remoting/host/host_user_interface.cc b/remoting/host/host_user_interface.cc
index 964473b..4401fb5 100644
--- a/remoting/host/host_user_interface.cc
+++ b/remoting/host/host_user_interface.cc
@@ -16,8 +16,7 @@ HostUserInterface::HostUserInterface(ChromotingHostContext* context)
: host_(NULL),
context_(context),
is_monitoring_local_inputs_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
- weak_ptr_(weak_factory_.GetWeakPtr()) {
+ ui_thread_proxy_(context->ui_message_loop()) {
}
HostUserInterface::~HostUserInterface() {
@@ -25,6 +24,8 @@ HostUserInterface::~HostUserInterface() {
MonitorLocalInputs(false);
ShowDisconnectWindow(false, std::string());
+
+ ui_thread_proxy_.Detach();
}
void HostUserInterface::Start(ChromotingHost* host,
@@ -41,23 +42,19 @@ void HostUserInterface::Start(ChromotingHost* host,
}
void HostUserInterface::OnClientAuthenticated(const std::string& jid) {
- DCHECK(network_message_loop()->BelongsToCurrentThread());
-
authenticated_jid_ = jid;
std::string username = jid.substr(0, jid.find('/'));
- ui_message_loop()->PostTask(FROM_HERE, base::Bind(
+ ui_thread_proxy_.PostTask(FROM_HERE, base::Bind(
&HostUserInterface::ProcessOnClientAuthenticated,
- weak_ptr_, username));
+ base::Unretained(this), username));
}
void HostUserInterface::OnClientDisconnected(const std::string& jid) {
- DCHECK(network_message_loop()->BelongsToCurrentThread());
-
if (jid == authenticated_jid_) {
- ui_message_loop()->PostTask(FROM_HERE, base::Bind(
+ ui_thread_proxy_.PostTask(FROM_HERE, base::Bind(
&HostUserInterface::ProcessOnClientDisconnected,
- weak_ptr_));
+ base::Unretained(this)));
}
}
@@ -65,20 +62,20 @@ 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;
+ disconnect_callback_ = base::Closure();
}
void HostUserInterface::OnDisconnectCallback() {
DCHECK(ui_message_loop()->BelongsToCurrentThread());
+ DCHECK(!disconnect_callback_.is_null());
MonitorLocalInputs(false);
ShowDisconnectWindow(false, std::string());
- DisconnectSession();
+ disconnect_callback_.Run();
}
base::MessageLoopProxy* HostUserInterface::network_message_loop() const {
@@ -89,10 +86,7 @@ base::MessageLoopProxy* HostUserInterface::ui_message_loop() const {
}
void HostUserInterface::DisconnectSession() const {
- DCHECK(ui_message_loop()->BelongsToCurrentThread());
- DCHECK(!disconnect_callback_.is_null());
-
- disconnect_callback_.Run();
+ return disconnect_callback_.Run();
}
void HostUserInterface::ProcessOnClientAuthenticated(
@@ -146,7 +140,7 @@ void HostUserInterface::ShowDisconnectWindow(bool show,
disconnect_window_->Show(
host_,
base::Bind(&HostUserInterface::OnDisconnectCallback,
- weak_ptr_),
+ base::Unretained(this)),
username);
} else {
disconnect_window_->Hide();
diff --git a/remoting/host/host_user_interface.h b/remoting/host/host_user_interface.h
index 942cd2a..9c2729e 100644
--- a/remoting/host/host_user_interface.h
+++ b/remoting/host/host_user_interface.h
@@ -11,8 +11,8 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
-#include "base/message_loop_proxy.h"
+
+#include "remoting/base/scoped_thread_proxy.h"
#include "remoting/host/host_status_observer.h"
namespace remoting {
@@ -95,9 +95,7 @@ class HostUserInterface : public HostStatusObserver {
bool is_monitoring_local_inputs_;
- // WeakPtr used to avoid tasks accessing the client after it is deleted.
- base::WeakPtrFactory<HostUserInterface> weak_factory_;
- base::WeakPtr<HostUserInterface> weak_ptr_;
+ ScopedThreadProxy ui_thread_proxy_;
DISALLOW_COPY_AND_ASSIGN(HostUserInterface);
};
diff --git a/remoting/host/it2me_host_user_interface.cc b/remoting/host/it2me_host_user_interface.cc
index 1b2f392..c39f6d3 100644
--- a/remoting/host/it2me_host_user_interface.cc
+++ b/remoting/host/it2me_host_user_interface.cc
@@ -24,15 +24,29 @@ static const int kContinueWindowHideTimeoutMs = 60 * 1000;
namespace remoting {
+class It2MeHostUserInterface::TimerTask {
+ public:
+ TimerTask(base::MessageLoopProxy* message_loop,
+ const base::Closure& task,
+ int delay_ms)
+ : thread_proxy_(message_loop) {
+ thread_proxy_.PostDelayedTask(FROM_HERE, task, delay_ms);
+ }
+
+ private:
+ ScopedThreadProxy thread_proxy_;
+};
+
+
It2MeHostUserInterface::It2MeHostUserInterface(ChromotingHostContext* context)
- : HostUserInterface(context),
- ALLOW_THIS_IN_INITIALIZER_LIST(timer_weak_factory_(this)) {
+ : HostUserInterface(context) {
}
It2MeHostUserInterface::~It2MeHostUserInterface() {
DCHECK(ui_message_loop()->BelongsToCurrentThread());
ShowContinueWindow(false);
+ StartContinueWindowTimer(false);
}
void It2MeHostUserInterface::Start(ChromotingHost* host,
@@ -89,6 +103,7 @@ void It2MeHostUserInterface::ContinueSession(bool continue_session) {
if (continue_session) {
get_host()->PauseSession(false);
+ timer_task_.reset();
StartContinueWindowTimer(true);
} else {
DisconnectSession();
@@ -101,13 +116,11 @@ void It2MeHostUserInterface::OnContinueWindowTimer() {
get_host()->PauseSession(true);
ShowContinueWindow(true);
- // Cancel any pending timer and post one to hide the continue window.
- timer_weak_factory_.InvalidateWeakPtrs();
- ui_message_loop()->PostDelayedTask(
- FROM_HERE,
+ timer_task_.reset(new TimerTask(
+ ui_message_loop(),
base::Bind(&It2MeHostUserInterface::OnShutdownHostTimer,
- timer_weak_factory_.GetWeakPtr()),
- kContinueWindowHideTimeoutMs);
+ base::Unretained(this)),
+ kContinueWindowHideTimeoutMs));
}
void It2MeHostUserInterface::OnShutdownHostTimer() {
@@ -131,14 +144,14 @@ void It2MeHostUserInterface::ShowContinueWindow(bool show) {
void It2MeHostUserInterface::StartContinueWindowTimer(bool start) {
DCHECK(ui_message_loop()->BelongsToCurrentThread());
- // Abandon previous timer events by invalidating their weak pointer to us.
- timer_weak_factory_.InvalidateWeakPtrs();
if (start) {
- ui_message_loop()->PostDelayedTask(
- FROM_HERE,
+ timer_task_.reset(new TimerTask(
+ ui_message_loop(),
base::Bind(&It2MeHostUserInterface::OnContinueWindowTimer,
- timer_weak_factory_.GetWeakPtr()),
- kContinueWindowShowTimeoutMs);
+ base::Unretained(this)),
+ kContinueWindowShowTimeoutMs));
+ } else {
+ timer_task_.reset();
}
}
diff --git a/remoting/host/it2me_host_user_interface.h b/remoting/host/it2me_host_user_interface.h
index 71619ea..b054c65 100644
--- a/remoting/host/it2me_host_user_interface.h
+++ b/remoting/host/it2me_host_user_interface.h
@@ -11,7 +11,6 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "remoting/host/host_user_interface.h"
@@ -68,9 +67,8 @@ class It2MeHostUserInterface : public HostUserInterface {
// the connection.
scoped_ptr<ContinueWindow> continue_window_;
- // Weak pointer factory used to abandon the "continue session" timer when
- // hiding the "continue session" dialog, or tearing down the IT2Me UI.
- base::WeakPtrFactory<It2MeHostUserInterface> timer_weak_factory_;
+ // Timer controlling the "continue session" dialog.
+ scoped_ptr<TimerTask> timer_task_;
DISALLOW_COPY_AND_ASSIGN(It2MeHostUserInterface);
};