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

Unified Diff: remoting/host/disconnect_window_win.cc

Issue 11583023: Give DisconnectWindow some TLC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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/disconnect_window_win.cc
diff --git a/remoting/host/disconnect_window_win.cc b/remoting/host/disconnect_window_win.cc
index a31e11d3ae1ee55f8200b5aaf57833f077c9fea2..c3b29ec79c188aa79a6408c69672e1c5773ddf96 100644
--- a/remoting/host/disconnect_window_win.cc
+++ b/remoting/host/disconnect_window_win.cc
@@ -41,6 +41,7 @@ class DisconnectWindowWin : public DisconnectWindow {
DisconnectWindowWin();
virtual ~DisconnectWindowWin();
+ // DisconnectWindow interface.
virtual bool Show(const UiStrings& ui_strings,
const DisconnectCallback& disconnect_callback,
const std::string& username) OVERRIDE;
@@ -56,12 +57,10 @@ private:
bool BeginDialog(const UiStrings& ui_strings,
const std::string& username);
- // Unregisters the disconnect hot key and closed the dialog.
+ // Closes the dialog, unregisters the hot key and invokes the disconnect
+ // callback, if set.
void EndDialog();
- // Invokes the disconnect callback passed to Show().
- void InvokeDiconnectCallback();
-
// Trys to position the dialog window above the taskbar.
void SetDialogPosition();
@@ -97,7 +96,7 @@ DisconnectWindowWin::DisconnectWindowWin()
}
DisconnectWindowWin::~DisconnectWindowWin() {
- EndDialog();
+ Hide();
}
bool DisconnectWindowWin::Show(const UiStrings& ui_strings,
@@ -111,12 +110,14 @@ bool DisconnectWindowWin::Show(const UiStrings& ui_strings,
if (BeginDialog(ui_strings, username)) {
return true;
} else {
- EndDialog();
+ Hide();
return false;
}
}
void DisconnectWindowWin::Hide() {
+ // Clear the |disconnect_callback_| so it won't be invoked by EndDialog().
+ disconnect_callback_.Reset();
EndDialog();
}
@@ -154,7 +155,6 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT message,
switch (LOWORD(wparam)) {
case IDC_DISCONNECT:
EndDialog();
- InvokeDiconnectCallback();
return TRUE;
}
return FALSE;
@@ -162,6 +162,11 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT message,
// Ensure we don't try to use the HWND anymore.
case WM_DESTROY:
hwnd_ = NULL;
+
+ // Ensure that the disconnect callback is invoked even if somehow our
+ // window gets destroyed.
+ EndDialog();
+
return TRUE;
// Ensure the dialog stays visible if the work area dimensions change.
@@ -178,7 +183,6 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT message,
// Handle the disconnect hot-key.
case WM_HOTKEY:
EndDialog();
- InvokeDiconnectCallback();
return TRUE;
// Let the window be draggable by its client area by responding
@@ -266,14 +270,13 @@ void DisconnectWindowWin::EndDialog() {
if (hwnd_) {
::DestroyWindow(hwnd_);
- hwnd_ = NULL;
+ DCHECK(hwnd_ == NULL);
}
- disconnect_callback_.Reset();
-}
-
-void DisconnectWindowWin::InvokeDiconnectCallback() {
- disconnect_callback_.Run();
+ if (!disconnect_callback_.is_null()) {
+ disconnect_callback_.Run();
+ disconnect_callback_.Reset();
+ }
}
void DisconnectWindowWin::SetDialogPosition() {
« remoting/host/disconnect_window.h ('K') | « remoting/host/disconnect_window_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698