OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/commands/command_service.h" | 5 #include "chrome/browser/extensions/api/commands/command_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 namespace extensions { | 142 namespace extensions { |
143 | 143 |
144 // static | 144 // static |
145 void CommandService::RegisterProfilePrefs( | 145 void CommandService::RegisterProfilePrefs( |
146 user_prefs::PrefRegistrySyncable* registry) { | 146 user_prefs::PrefRegistrySyncable* registry) { |
147 registry->RegisterDictionaryPref( | 147 registry->RegisterDictionaryPref( |
148 prefs::kExtensionCommands, | 148 prefs::kExtensionCommands, |
149 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 149 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
150 } | 150 } |
151 | 151 |
152 CommandService::CommandService(Profile* profile) | 152 CommandService::CommandService(content::BrowserContext* context) |
153 : profile_(profile) { | 153 : profile_(Profile::FromBrowserContext(context)) { |
154 ExtensionFunctionRegistry::GetInstance()-> | 154 ExtensionFunctionRegistry::GetInstance()-> |
155 RegisterFunction<GetAllCommandsFunction>(); | 155 RegisterFunction<GetAllCommandsFunction>(); |
156 | 156 |
157 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 157 registrar_.Add(this, |
158 content::Source<Profile>(profile)); | 158 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
159 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 159 content::Source<Profile>(profile_)); |
160 content::Source<Profile>(profile)); | 160 registrar_.Add(this, |
| 161 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 162 content::Source<Profile>(profile_)); |
161 } | 163 } |
162 | 164 |
163 CommandService::~CommandService() { | 165 CommandService::~CommandService() { |
164 } | 166 } |
165 | 167 |
166 static base::LazyInstance<ProfileKeyedAPIFactory<CommandService> > | 168 static base::LazyInstance<ProfileKeyedAPIFactory<CommandService> > |
167 g_factory = LAZY_INSTANCE_INITIALIZER; | 169 g_factory = LAZY_INSTANCE_INITIALIZER; |
168 | 170 |
169 // static | 171 // static |
170 ProfileKeyedAPIFactory<CommandService>* CommandService::GetFactoryInstance() { | 172 ProfileKeyedAPIFactory<CommandService>* CommandService::GetFactoryInstance() { |
171 return g_factory.Pointer(); | 173 return g_factory.Pointer(); |
172 } | 174 } |
173 | 175 |
174 // static | 176 // static |
175 CommandService* CommandService::Get(Profile* profile) { | 177 CommandService* CommandService::Get(content::BrowserContext* context) { |
176 return ProfileKeyedAPIFactory<CommandService>::GetForProfile(profile); | 178 return ProfileKeyedAPIFactory<CommandService>::GetForProfile(context); |
177 } | 179 } |
178 | 180 |
179 // static | 181 // static |
180 bool CommandService::IsMediaKey(const ui::Accelerator& accelerator) { | 182 bool CommandService::IsMediaKey(const ui::Accelerator& accelerator) { |
181 if (accelerator.modifiers() != 0) | 183 if (accelerator.modifiers() != 0) |
182 return false; | 184 return false; |
183 | 185 |
184 return (accelerator.key_code() == ui::VKEY_MEDIA_NEXT_TRACK || | 186 return (accelerator.key_code() == ui::VKEY_MEDIA_NEXT_TRACK || |
185 accelerator.key_code() == ui::VKEY_MEDIA_PREV_TRACK || | 187 accelerator.key_code() == ui::VKEY_MEDIA_PREV_TRACK || |
186 accelerator.key_code() == ui::VKEY_MEDIA_PLAY_PAUSE || | 188 accelerator.key_code() == ui::VKEY_MEDIA_PLAY_PAUSE || |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 538 |
537 return true; | 539 return true; |
538 } | 540 } |
539 | 541 |
540 template <> | 542 template <> |
541 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { | 543 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { |
542 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); | 544 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); |
543 } | 545 } |
544 | 546 |
545 } // namespace extensions | 547 } // namespace extensions |
OLD | NEW |