Chromium Code Reviews| 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..ad12f859d34ddd99ad3cd92cecfd5d101c58ccda 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,21 +38,23 @@ 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::OnHotkey, base::Unretained(this)))); |
|
sky
2015/04/28 13:20:34
You should document why unretained is safe here.
robliao
2015/04/28 14:11:55
This use of base::Unretained(this) is fairly idiom
robliao
2015/04/28 14:12:38
lifetime same or longer than the holder.
|
| 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; |
| } |
| -void GlobalShortcutListenerWin::OnWndProc(HWND hwnd, |
| - UINT message, |
| - WPARAM wparam, |
| - LPARAM lparam) { |
| +void GlobalShortcutListenerWin::OnHotkey(HWND hwnd, |
| + UINT message, |
| + WPARAM wparam, |
| + LPARAM lparam) { |
| if (message != WM_HOTKEY) |
| return; |