No gfx::SingletonHwnd::Observer any more.
authorHaojian Wu <hokein.wu@gmail.com>
Tue, 4 Aug 2015 08:23:54 +0000 (16:23 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 11 Aug 2015 01:48:29 +0000 (09:48 +0800)
Using gfx::SingletonHwndObserver instead.

chromium_src/chrome/browser/extensions/global_shortcut_listener_win.cc
chromium_src/chrome/browser/extensions/global_shortcut_listener_win.h

index 248ec6b..8ed234d 100644 (file)
@@ -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,17 @@ 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;
 }
 
index a155d8f..b3917e9 100644 (file)
@@ -7,26 +7,24 @@
 
 #include <windows.h>
 
+#include "base/memory/scoped_ptr.h"
 #include "chrome/browser/extensions/global_shortcut_listener.h"
 #include "ui/gfx/win/singleton_hwnd.h"
+#include "ui/gfx/win/singleton_hwnd_observer.h"
 
 namespace extensions {
 
 // Windows-specific implementation of the GlobalShortcutListener class that
 // listens for global shortcuts. Handles setting up a keyboard hook and
 // forwarding its output to the base class for processing.
-class GlobalShortcutListenerWin : public GlobalShortcutListener,
-                                  public gfx::SingletonHwnd::Observer {
+class GlobalShortcutListenerWin : public GlobalShortcutListener {
  public:
   GlobalShortcutListenerWin();
   virtual ~GlobalShortcutListenerWin();
 
  private:
-  // The implementation of our Window Proc, called by SingletonHwnd.
-  virtual void OnWndProc(HWND hwnd,
-                         UINT message,
-                         WPARAM wparam,
-                         LPARAM lparam) override;
+  // The implementation of our Window Proc, called by SingletonHwndObserver.
+  void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
 
   // GlobalShortcutListener implementation.
   virtual void StartListening() override;
@@ -43,6 +41,8 @@ class GlobalShortcutListenerWin : public GlobalShortcutListener,
   typedef std::map<ui::Accelerator, int> HotkeyIdMap;
   HotkeyIdMap hotkey_ids_;
 
+  scoped_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_;
+
   DISALLOW_COPY_AND_ASSIGN(GlobalShortcutListenerWin);
 };