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

Unified Diff: chrome/browser/extensions/global_shortcut_listener_win.cc

Issue 1092183005: Fix Up SingletonHwnd Observer Lifetime Issues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow null SingletonHwnd Hwnd Created 5 years, 8 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: chrome/browser/extensions/global_shortcut_listener_win.cc
diff --git a/chrome/browser/extensions/global_shortcut_listener_win.cc b/chrome/browser/extensions/global_shortcut_listener_win.cc
index 8f6f1912e36fc0b7a63893473c190c32798d1b9c..65b244d55441b07f55e61c7b634d6cec57f2b1e7 100644
--- a/chrome/browser/extensions/global_shortcut_listener_win.cc
+++ b/chrome/browser/extensions/global_shortcut_listener_win.cc
@@ -4,11 +4,14 @@
#include "chrome/browser/extensions/global_shortcut_listener_win.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/win/win_util.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
+#include "ui/gfx/win/singleton_hwnd.h"
using content::BrowserThread;
@@ -35,14 +38,16 @@ GlobalShortcutListenerWin::~GlobalShortcutListenerWin() {
void GlobalShortcutListenerWin::StartListening() {
DCHECK(!is_listening_); // Don't start twice.
DCHECK(!hotkey_ids_.empty()); // Also don't start if no hotkey is registered.
- gfx::SingletonHwnd::GetInstance()->AddObserver(this);
+ singleton_hwnd_observer_.reset(new gfx::SingletonHwndObserver(
+ base::Bind(
+ &GlobalShortcutListenerWin::OnWndProc, base::Unretained(this))));
is_listening_ = true;
}
void GlobalShortcutListenerWin::StopListening() {
DCHECK(is_listening_); // No point if we are not already listening.
DCHECK(hotkey_ids_.empty()); // Make sure the map is clean before ending.
- gfx::SingletonHwnd::GetInstance()->RemoveObserver(this);
+ singleton_hwnd_observer_.reset(nullptr);
is_listening_ = false;
}

Powered by Google App Engine
This is Rietveld 408576698