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

Side by Side Diff: chrome/browser/extensions/extension_commands_global_registry.cc

Issue 174513003: Move ProfileKeyedAPI implementations to take BrowserContext in the constructor (part 3). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_commands_global_registry.h" 5 #include "chrome/browser/extensions/extension_commands_global_registry.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "chrome/browser/extensions/api/commands/command_service.h" 8 #include "chrome/browser/extensions/api/commands/command_service.h"
9 #include "chrome/browser/extensions/global_shortcut_listener.h" 9 #include "chrome/browser/extensions/global_shortcut_listener.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "extensions/common/extension.h" 10 #include "extensions/common/extension.h"
12 11
13 namespace extensions { 12 namespace extensions {
14 13
15 ExtensionCommandsGlobalRegistry::ExtensionCommandsGlobalRegistry( 14 ExtensionCommandsGlobalRegistry::ExtensionCommandsGlobalRegistry(
16 Profile* profile) 15 content::BrowserContext* context)
17 : ExtensionKeybindingRegistry( 16 : ExtensionKeybindingRegistry(context,
18 profile, ExtensionKeybindingRegistry::ALL_EXTENSIONS, NULL), 17 ExtensionKeybindingRegistry::ALL_EXTENSIONS,
19 profile_(profile) { 18 NULL),
19 browser_context_(context) {
20 Init(); 20 Init();
21 } 21 }
22 22
23 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() { 23 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() {
24 for (EventTargets::const_iterator iter = event_targets_.begin(); 24 for (EventTargets::const_iterator iter = event_targets_.begin();
25 iter != event_targets_.end(); ++iter) { 25 iter != event_targets_.end(); ++iter) {
26 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( 26 GlobalShortcutListener::GetInstance()->UnregisterAccelerator(
27 iter->first, this); 27 iter->first, this);
28 } 28 }
29 } 29 }
30 30
31 static base::LazyInstance< 31 static base::LazyInstance<
32 ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry> > 32 ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry> >
33 g_factory = LAZY_INSTANCE_INITIALIZER; 33 g_factory = LAZY_INSTANCE_INITIALIZER;
34 34
35 // static 35 // static
36 ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry>* 36 ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry>*
37 ExtensionCommandsGlobalRegistry::GetFactoryInstance() { 37 ExtensionCommandsGlobalRegistry::GetFactoryInstance() {
38 return g_factory.Pointer(); 38 return g_factory.Pointer();
39 } 39 }
40 40
41 // static 41 // static
42 ExtensionCommandsGlobalRegistry* 42 ExtensionCommandsGlobalRegistry* ExtensionCommandsGlobalRegistry::Get(
43 ExtensionCommandsGlobalRegistry::Get(Profile* profile) { 43 content::BrowserContext* context) {
44 return ProfileKeyedAPIFactory< 44 return ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry>::GetForProfile(
45 ExtensionCommandsGlobalRegistry>::GetForProfile(profile); 45 context);
46 } 46 }
47 47
48 void ExtensionCommandsGlobalRegistry::AddExtensionKeybinding( 48 void ExtensionCommandsGlobalRegistry::AddExtensionKeybinding(
49 const extensions::Extension* extension, 49 const extensions::Extension* extension,
50 const std::string& command_name) { 50 const std::string& command_name) {
51 // This object only handles named commands, not browser/page actions. 51 // This object only handles named commands, not browser/page actions.
52 if (ShouldIgnoreCommand(command_name)) 52 if (ShouldIgnoreCommand(command_name))
53 return; 53 return;
54 54
55 extensions::CommandService* command_service = 55 extensions::CommandService* command_service =
56 extensions::CommandService::Get(profile_); 56 extensions::CommandService::Get(browser_context_);
57 // Add all the active global keybindings, if any. 57 // Add all the active global keybindings, if any.
58 extensions::CommandMap commands; 58 extensions::CommandMap commands;
59 if (!command_service->GetNamedCommands( 59 if (!command_service->GetNamedCommands(
60 extension->id(), 60 extension->id(),
61 extensions::CommandService::ACTIVE_ONLY, 61 extensions::CommandService::ACTIVE_ONLY,
62 extensions::CommandService::GLOBAL, 62 extensions::CommandService::GLOBAL,
63 &commands)) 63 &commands))
64 return; 64 return;
65 65
66 extensions::CommandMap::const_iterator iter = commands.begin(); 66 extensions::CommandMap::const_iterator iter = commands.begin();
(...skipping 29 matching lines...) Expand all
96 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( 96 GlobalShortcutListener::GetInstance()->UnregisterAccelerator(
97 accelerator, this); 97 accelerator, this);
98 } 98 }
99 99
100 void ExtensionCommandsGlobalRegistry::OnKeyPressed( 100 void ExtensionCommandsGlobalRegistry::OnKeyPressed(
101 const ui::Accelerator& accelerator) { 101 const ui::Accelerator& accelerator) {
102 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); 102 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator);
103 } 103 }
104 104
105 } // namespace extensions 105 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698