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

Unified Diff: chrome/browser/extensions/global_shortcut_listener.h

Issue 109413003: Refactor GlobalShortcutListener. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update as comments. Created 7 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: chrome/browser/extensions/global_shortcut_listener.h
diff --git a/chrome/browser/extensions/global_shortcut_listener.h b/chrome/browser/extensions/global_shortcut_listener.h
index c61abe65f0c16b91c722c33a1c9b165583e20af3..f79187440749231c72a06b65234fbf9e8b782ae0 100644
--- a/chrome/browser/extensions/global_shortcut_listener.h
+++ b/chrome/browser/extensions/global_shortcut_listener.h
@@ -18,7 +18,7 @@ class Accelerator;
namespace extensions {
// Platform-neutral implementation of a class that keeps track of observers and
-// monitors keystrokes. It relays messages to the appropriate observers when a
+// monitors keystrokes. It relays messages to the appropriate observer when a
// global shortcut has been struck by the user.
class GlobalShortcutListener {
public:
@@ -32,28 +32,32 @@ class GlobalShortcutListener {
static GlobalShortcutListener* GetInstance();
- // Implemented by platform-specific implementations of this class.
- virtual void StartListening() = 0;
- virtual void StopListening() = 0;
-
- // Register an observer for when a certain |accelerator| is struck.
- virtual void RegisterAccelerator(
- const ui::Accelerator& accelerator, Observer* observer);
+ // Register an observer for when a certain |accelerator| is struck. Return
+ // true if register successfully, false if the specificied |accelerator| has
+ // been registered by callers or other native applications.
+ bool RegisterAccelerator(const ui::Accelerator& accelerator,
+ Observer* observer);
// Stop listening for the given |accelerator|.
- virtual void UnregisterAccelerator(
- const ui::Accelerator& accelerator, Observer* observer);
+ void UnregisterAccelerator(const ui::Accelerator& accelerator,
+ Observer* observer);
protected:
GlobalShortcutListener();
// Called by platform specific implementations of this class whenever a key
- // is struck. Only called for keys that have observers registered.
+ // is struck. Only called for keys that have an observer registered.
void NotifyKeyPressed(const ui::Accelerator& accelerator);
+ // Implemented by platform-specific implementations of this class.
+ virtual void StartListening() = 0;
+ virtual void StopListening() = 0;
+ virtual bool RegisterAcceleratorImpl(const ui::Accelerator& accelerator) = 0;
+ virtual void UnregisterAcceleratorImpl(
+ const ui::Accelerator& accelerator) = 0;
+
// The map of accelerators that have been successfully registered as global
- // shortcuts and their observer lists.
- typedef ObserverList<Observer> Observers;
- typedef std::map< ui::Accelerator, Observers* > AcceleratorMap;
+ // shortcuts and their observer.
+ typedef std::map< ui::Accelerator, Observer* > AcceleratorMap;
AcceleratorMap accelerator_map_;
private:

Powered by Google App Engine
This is Rietveld 408576698