diff options
-rw-r--r-- | remoting/host/continue_window.h | 11 | ||||
-rw-r--r-- | remoting/host/continue_window_linux.cc | 14 | ||||
-rw-r--r-- | remoting/host/continue_window_mac.mm | 27 | ||||
-rw-r--r-- | remoting/host/continue_window_win.cc | 14 | ||||
-rw-r--r-- | remoting/host/desktop_environment.cc | 24 | ||||
-rw-r--r-- | remoting/host/desktop_environment.h | 7 | ||||
-rw-r--r-- | remoting/host/host_mock_objects.h | 4 |
7 files changed, 67 insertions, 34 deletions
diff --git a/remoting/host/continue_window.h b/remoting/host/continue_window.h index 0c52416..1840664 100644 --- a/remoting/host/continue_window.h +++ b/remoting/host/continue_window.h @@ -5,17 +5,26 @@ #ifndef REMOTING_HOST_CONTINUE_WINDOW_H #define REMOTING_HOST_CONTINUE_WINDOW_H +#include "base/callback.h" + namespace remoting { class ChromotingHost; class ContinueWindow { public: + // ContinueSessionCallback is called when the user clicks on the + // Continue button to resume the session, or dismisses the window to + // terminate the session. This callback is provided as a parameter to the + // Show() method, and will be triggered on the UI thread. + typedef base::Callback<void(bool)> ContinueSessionCallback; + virtual ~ContinueWindow() {} // Show the continuation window requesting that the user approve continuing // the session. - virtual void Show(ChromotingHost* host) = 0; + virtual void Show(ChromotingHost* host, + const ContinueSessionCallback& callback) = 0; // Hide the continuation window if it is visible. virtual void Hide() = 0; diff --git a/remoting/host/continue_window_linux.cc b/remoting/host/continue_window_linux.cc index ddd959c..b84e49b 100644 --- a/remoting/host/continue_window_linux.cc +++ b/remoting/host/continue_window_linux.cc @@ -20,7 +20,8 @@ class ContinueWindowLinux : public remoting::ContinueWindow { ContinueWindowLinux(); virtual ~ContinueWindowLinux(); - virtual void Show(remoting::ChromotingHost* host) OVERRIDE; + virtual void Show(remoting::ChromotingHost* host, + const ContinueSessionCallback& callback) OVERRIDE; virtual void Hide() OVERRIDE; private: @@ -29,6 +30,7 @@ class ContinueWindowLinux : public remoting::ContinueWindow { void CreateWindow(const UiStrings& ui_strings); ChromotingHost* host_; + ContinueSessionCallback callback_; GtkWidget* continue_window_; DISALLOW_COPY_AND_ASSIGN(ContinueWindowLinux); @@ -79,8 +81,10 @@ void ContinueWindowLinux::CreateWindow(const UiStrings& ui_strings) { gtk_widget_show_all(content_area); } -void ContinueWindowLinux::Show(remoting::ChromotingHost* host) { +void ContinueWindowLinux::Show(remoting::ChromotingHost* host, + const ContinueSessionCallback& callback) { host_ = host; + callback_ = callback; CreateWindow(host->ui_strings()); gtk_window_set_urgency_hint(GTK_WINDOW(continue_window_), TRUE); gtk_window_present(GTK_WINDOW(continue_window_)); @@ -94,11 +98,7 @@ void ContinueWindowLinux::Hide() { } void ContinueWindowLinux::OnResponse(GtkWidget* dialog, int response_id) { - if (response_id == GTK_RESPONSE_OK) { - host_->PauseSession(false); - } else { - host_->Shutdown(base::Closure()); - } + callback_.Run(response_id == GTK_RESPONSE_OK); Hide(); } diff --git a/remoting/host/continue_window_mac.mm b/remoting/host/continue_window_mac.mm index 2dac22c..f5661846 100644 --- a/remoting/host/continue_window_mac.mm +++ b/remoting/host/continue_window_mac.mm @@ -13,15 +13,20 @@ #include "base/sys_string_conversions.h" #include "remoting/host/chromoting_host.h" +typedef remoting::ContinueWindow::ContinueSessionCallback + ContinueSessionCallback; + // Handles the ContinueWindow. @interface ContinueWindowMacController : NSObject { @private scoped_nsobject<NSMutableArray> shades_; scoped_nsobject<NSAlert> continue_alert_; remoting::ChromotingHost* host_; + ContinueSessionCallback callback_; } -- (id)initWithHost:(remoting::ChromotingHost*)host; +- (id)initWithHost:(remoting::ChromotingHost*)host + callback:(const ContinueSessionCallback&)callback; - (void)show; - (void)hide; - (void)onCancel:(id)sender; @@ -37,20 +42,24 @@ class ContinueWindowMac : public remoting::ContinueWindow { ContinueWindowMac() {} virtual ~ContinueWindowMac() {} - virtual void Show(remoting::ChromotingHost* host) OVERRIDE; + virtual void Show(remoting::ChromotingHost* host, + const ContinueSessionCallback& callback) OVERRIDE; virtual void Hide() OVERRIDE; private: scoped_nsobject<ContinueWindowMacController> controller_; + ContinueSessionCallback callback_; DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac); }; -void ContinueWindowMac::Show(remoting::ChromotingHost* host) { +void ContinueWindowMac::Show(remoting::ChromotingHost* host, + const ContinueSessionCallback& callback) { base::mac::ScopedNSAutoreleasePool pool; - controller_.reset([[ContinueWindowMacController alloc] initWithHost:host]); + controller_.reset( + [[ContinueWindowMacController alloc] initWithHost:host + callback:callback]); [controller_ show]; - } void ContinueWindowMac::Hide() { @@ -66,9 +75,11 @@ ContinueWindow* ContinueWindow::Create() { @implementation ContinueWindowMacController -- (id)initWithHost:(remoting::ChromotingHost*)host { +- (id)initWithHost:(remoting::ChromotingHost*)host + callback:(const ContinueSessionCallback&)callback { if ((self = [super init])) { host_ = host; + callback_ = callback; } return self; } @@ -143,13 +154,13 @@ ContinueWindow* ContinueWindow::Create() { - (void)onCancel:(id)sender { [self hide]; - host_->Shutdown(base::Closure()); + callback_.Run(false); host_ = nil; } - (void)onContinue:(id)sender { [self hide]; - host_->PauseSession(false); + callback_.Run(true); host_ = nil; } diff --git a/remoting/host/continue_window_win.cc b/remoting/host/continue_window_win.cc index 73a214a..190cc42 100644 --- a/remoting/host/continue_window_win.cc +++ b/remoting/host/continue_window_win.cc @@ -32,7 +32,8 @@ class ContinueWindowWin : public ContinueWindow { ContinueWindowWin(); virtual ~ContinueWindowWin(); - virtual void Show(remoting::ChromotingHost* host) OVERRIDE; + virtual void Show(remoting::ChromotingHost* host, + const ContinueSessionCallback& callback) OVERRIDE; virtual void Hide() OVERRIDE; private: @@ -45,6 +46,7 @@ class ContinueWindowWin : public ContinueWindow { void SetStrings(const UiStrings& strings); remoting::ChromotingHost* host_; + ContinueSessionCallback callback_; HWND hwnd_; DISALLOW_COPY_AND_ASSIGN(ContinueWindowWin); @@ -88,14 +90,12 @@ BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg, case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_CONTINUE_DEFAULT: - CHECK(host_); - host_->PauseSession(false); + callback_.Run(true); ::EndDialog(hwnd, LOWORD(wParam)); hwnd_ = NULL; return TRUE; case IDC_CONTINUE_CANCEL: - CHECK(host_); - host_->Shutdown(base::Closure()); + callback_.Run(false); ::EndDialog(hwnd, LOWORD(wParam)); hwnd_ = NULL; return TRUE; @@ -104,8 +104,10 @@ BOOL ContinueWindowWin::OnDialogMessage(HWND hwnd, UINT msg, return FALSE; } -void ContinueWindowWin::Show(ChromotingHost* host) { +void ContinueWindowWin::Show(ChromotingHost* host, + const ContinueSessionCallback& callback) { host_ = host; + callback_ = callback; CHECK(!hwnd_); hwnd_ = CreateDialogParam(g_hModule, MAKEINTRESOURCE(IDD_CONTINUE), NULL, diff --git a/remoting/host/desktop_environment.cc b/remoting/host/desktop_environment.cc index c838a0f..48db5f1 100644 --- a/remoting/host/desktop_environment.cc +++ b/remoting/host/desktop_environment.cc @@ -108,8 +108,6 @@ void DesktopEnvironment::OnLastDisconnect() { } void DesktopEnvironment::OnPause(bool pause) { - ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( - &DesktopEnvironment::ProcessOnPause, base::Unretained(this), pause)); } void DesktopEnvironment::ProcessOnConnect(const std::string& username) { @@ -129,13 +127,6 @@ void DesktopEnvironment::ProcessOnLastDisconnect() { StartContinueWindowTimer(false); } -void DesktopEnvironment::ProcessOnPause(bool pause) { - if (!pause) { - timer_task_.reset(); - StartContinueWindowTimer(true); - } -} - void DesktopEnvironment::MonitorLocalInputs(bool enable) { DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); @@ -164,12 +155,25 @@ void DesktopEnvironment::ShowContinueWindow(bool show) { DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); if (show) { - continue_window_->Show(host_); + continue_window_->Show(host_, base::Bind( + &DesktopEnvironment::ContinueSession, base::Unretained(this))); } else { continue_window_->Hide(); } } +void DesktopEnvironment::ContinueSession(bool continue_session) { + DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); + + if (continue_session) { + host_->PauseSession(false); + timer_task_.reset(); + StartContinueWindowTimer(true); + } else { + host_->Shutdown(base::Closure()); + } +} + void DesktopEnvironment::StartContinueWindowTimer(bool start) { DCHECK(context_->ui_message_loop()->BelongsToCurrentThread()); diff --git a/remoting/host/desktop_environment.h b/remoting/host/desktop_environment.h index 31335f5..28da047e 100644 --- a/remoting/host/desktop_environment.h +++ b/remoting/host/desktop_environment.h @@ -62,7 +62,6 @@ class DesktopEnvironment { void ProcessOnConnect(const std::string& username); void ProcessOnLastDisconnect(); - void ProcessOnPause(bool pause); void MonitorLocalInputs(bool enable); @@ -73,6 +72,12 @@ class DesktopEnvironment { // Show or hide the Continue Sharing window on the UI thread. void ShowContinueWindow(bool show); + // Called by the ContinueWindow implementation (on the UI thread) when the + // user dismisses the Continue prompt. + // TODO(lambroslambrou): Move this method to the (to be written) + // It2MeObserver class. + void ContinueSession(bool continue_session); + void StartContinueWindowTimer(bool start); void OnContinueWindowTimer(); diff --git a/remoting/host/host_mock_objects.h b/remoting/host/host_mock_objects.h index 0613499..3810714 100644 --- a/remoting/host/host_mock_objects.h +++ b/remoting/host/host_mock_objects.h @@ -70,7 +70,9 @@ class MockContinueWindow : public ContinueWindow { MockContinueWindow(); virtual ~MockContinueWindow(); - MOCK_METHOD1(Show, void(remoting::ChromotingHost* host)); + MOCK_METHOD2(Show, void( + remoting::ChromotingHost* host, + const remoting::ContinueWindow::ContinueSessionCallback& callback)); MOCK_METHOD0(Hide, void()); }; |