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

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

Issue 109413003: Refactor GlobalShortcutListener. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clearer. 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
« no previous file with comments | « no previous file | chrome/browser/extensions/global_shortcut_listener.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_commands_global_registry.cc
diff --git a/chrome/browser/extensions/extension_commands_global_registry.cc b/chrome/browser/extensions/extension_commands_global_registry.cc
index aa11b9c5c5cf667de5a315d7573ae6d1bb1fc478..9bfb837c6fa696da79c3d2dd17b096ff6df99b65 100644
--- a/chrome/browser/extensions/extension_commands_global_registry.cc
+++ b/chrome/browser/extensions/extension_commands_global_registry.cc
@@ -71,20 +71,28 @@ void ExtensionCommandsGlobalRegistry::AddExtensionKeybinding(
for (; iter != commands.end(); ++iter) {
if (!command_name.empty() && (iter->second.command_name() != command_name))
continue;
+ const ui::Accelerator& accelerator = iter->second.accelerator();
VLOG(0) << "Adding global keybinding for " << extension->name().c_str()
<< " " << command_name.c_str()
- << " key: " << iter->second.accelerator().GetShortcutText();
-
- event_targets_[iter->second.accelerator()].push_back(
- std::make_pair(extension->id(), iter->second.command_name()));
- // Shortcuts except media keys have only one target in the list. See comment
- // about |event_targets_|.
- if (!extensions::CommandService::IsMediaKey(iter->second.accelerator()))
- DCHECK(event_targets_[iter->second.accelerator()].size() == 1);
-
- GlobalShortcutListener::GetInstance()->RegisterAccelerator(
- iter->second.accelerator(), this);
+ << " key: " << accelerator.GetShortcutText();
+
+ size_t target_count =
+ event_targets_.find(accelerator) != event_targets_.end() ?
+ event_targets_[accelerator].size() : 0;
+ if (extensions::CommandService::IsMediaKey(accelerator) &&
+ target_count > 0U) {
+ event_targets_[accelerator].push_back(
+ std::make_pair(extension->id(), iter->second.command_name()));
+ continue; // Shortcut listener already listening for this media key.
+ }
+
+ DCHECK_EQ(0U, target_count);
+ if (GlobalShortcutListener::GetInstance()->RegisterAccelerator(
+ accelerator, this)) {
+ event_targets_[accelerator].push_back(
+ std::make_pair(extension->id(), iter->second.command_name()));
+ }
Finnur 2013/12/17 16:35:45 Good catch. But I think a better alternative is (p
zhchbin 2013/12/18 01:53:07 Done. See the newest patch, actually the problem i
}
}
« no previous file with comments | « no previous file | chrome/browser/extensions/global_shortcut_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698