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

Side by Side Diff: chrome/browser/extensions/api/commands/command_service.cc

Issue 156843004: Remove ExtensionService::extension_prefs() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: additional cleanup 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) 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"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/extensions/api/commands/commands.h" 15 #include "chrome/browser/extensions/api/commands/commands.h"
16 #include "chrome/browser/extensions/extension_commands_global_registry.h" 16 #include "chrome/browser/extensions/extension_commands_global_registry.h"
17 #include "chrome/browser/extensions/extension_function_registry.h" 17 #include "chrome/browser/extensions/extension_function_registry.h"
18 #include "chrome/browser/extensions/extension_keybinding_registry.h" 18 #include "chrome/browser/extensions/extension_keybinding_registry.h"
19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/accelerator_utils.h" 20 #include "chrome/browser/ui/accelerator_utils.h"
22 #include "chrome/common/extensions/api/commands/commands_handler.h" 21 #include "chrome/common/extensions/api/commands/commands_handler.h"
23 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
24 #include "components/user_prefs/pref_registry_syncable.h" 23 #include "components/user_prefs/pref_registry_syncable.h"
25 #include "content/public/browser/notification_details.h" 24 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "extensions/browser/extension_prefs.h"
27 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/extension_system.h" 28 #include "extensions/browser/extension_system.h"
28 #include "extensions/common/feature_switch.h" 29 #include "extensions/common/feature_switch.h"
29 #include "extensions/common/manifest_constants.h" 30 #include "extensions/common/manifest_constants.h"
30 31
31 using extensions::Extension; 32 using extensions::Extension;
32 using extensions::ExtensionPrefs; 33 using extensions::ExtensionPrefs;
33 34
34 namespace { 35 namespace {
35 36
36 const char kExtension[] = "extension"; 37 const char kExtension[] = "extension";
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 extensions::Command* command, 162 extensions::Command* command,
162 bool* active) { 163 bool* active) {
163 return GetExtensionActionCommand( 164 return GetExtensionActionCommand(
164 extension_id, type, command, active, PAGE_ACTION); 165 extension_id, type, command, active, PAGE_ACTION);
165 } 166 }
166 167
167 bool CommandService::GetNamedCommands(const std::string& extension_id, 168 bool CommandService::GetNamedCommands(const std::string& extension_id,
168 QueryType type, 169 QueryType type,
169 CommandScope scope, 170 CommandScope scope,
170 extensions::CommandMap* command_map) { 171 extensions::CommandMap* command_map) {
171 ExtensionService* extension_service = 172 const ExtensionSet& extensions =
172 ExtensionSystem::Get(profile_)->extension_service(); 173 ExtensionRegistry::Get(profile_)->enabled_extensions();
173 if (!extension_service) 174 const Extension* extension = extensions.GetByID(extension_id);
174 return false; // Can occur during testing.
175 const ExtensionSet* extensions = extension_service->extensions();
176 const Extension* extension = extensions->GetByID(extension_id);
177 CHECK(extension); 175 CHECK(extension);
178 176
179 command_map->clear(); 177 command_map->clear();
180 const extensions::CommandMap* commands = 178 const extensions::CommandMap* commands =
181 CommandsInfo::GetNamedCommands(extension); 179 CommandsInfo::GetNamedCommands(extension);
182 if (!commands) 180 if (!commands)
183 return false; 181 return false;
184 182
185 extensions::CommandMap::const_iterator iter = commands->begin(); 183 extensions::CommandMap::const_iterator iter = commands->begin();
186 for (; iter != commands->end(); ++iter) { 184 for (; iter != commands->end(); ++iter) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 344
347 return Command(); 345 return Command();
348 } 346 }
349 347
350 void CommandService::AssignInitialKeybindings(const Extension* extension) { 348 void CommandService::AssignInitialKeybindings(const Extension* extension) {
351 const extensions::CommandMap* commands = 349 const extensions::CommandMap* commands =
352 CommandsInfo::GetNamedCommands(extension); 350 CommandsInfo::GetNamedCommands(extension);
353 if (!commands) 351 if (!commands)
354 return; 352 return;
355 353
356 ExtensionService* extension_service = 354 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
357 ExtensionSystem::Get(profile_)->extension_service();
358 ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
359 if (InitialBindingsHaveBeenAssigned(extension_prefs, extension->id())) 355 if (InitialBindingsHaveBeenAssigned(extension_prefs, extension->id()))
360 return; 356 return;
361 SetInitialBindingsHaveBeenAssigned(extension_prefs, extension->id()); 357 SetInitialBindingsHaveBeenAssigned(extension_prefs, extension->id());
362 358
363 extensions::CommandMap::const_iterator iter = commands->begin(); 359 extensions::CommandMap::const_iterator iter = commands->begin();
364 for (; iter != commands->end(); ++iter) { 360 for (; iter != commands->end(); ++iter) {
365 // Make sure registered Chrome shortcuts cannot be automatically assigned 361 // Make sure registered Chrome shortcuts cannot be automatically assigned
366 // (overwritten) by extension developers. Media keys are an exception here. 362 // (overwritten) by extension developers. Media keys are an exception here.
367 if ((!chrome::IsChromeAccelerator(iter->second.accelerator(), profile_) && 363 if ((!chrome::IsChromeAccelerator(iter->second.accelerator(), profile_) &&
368 IsWhitelistedGlobalShortcut(iter->second)) || 364 IsWhitelistedGlobalShortcut(iter->second)) ||
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 std::pair<const std::string, const std::string> >(&details)); 446 std::pair<const std::string, const std::string> >(&details));
451 } 447 }
452 } 448 }
453 449
454 bool CommandService::GetExtensionActionCommand( 450 bool CommandService::GetExtensionActionCommand(
455 const std::string& extension_id, 451 const std::string& extension_id,
456 QueryType query_type, 452 QueryType query_type,
457 extensions::Command* command, 453 extensions::Command* command,
458 bool* active, 454 bool* active,
459 ExtensionActionType action_type) { 455 ExtensionActionType action_type) {
460 ExtensionService* service = 456 const ExtensionSet& extensions =
461 ExtensionSystem::Get(profile_)->extension_service(); 457 ExtensionRegistry::Get(profile_)->enabled_extensions();
462 if (!service) 458 const Extension* extension = extensions.GetByID(extension_id);
463 return false; // Can happen in tests.
464 const ExtensionSet* extensions = service->extensions();
465 const Extension* extension = extensions->GetByID(extension_id);
466 CHECK(extension); 459 CHECK(extension);
467 460
468 if (active) 461 if (active)
469 *active = false; 462 *active = false;
470 463
471 const extensions::Command* requested_command = NULL; 464 const extensions::Command* requested_command = NULL;
472 switch (action_type) { 465 switch (action_type) {
473 case BROWSER_ACTION: 466 case BROWSER_ACTION:
474 requested_command = CommandsInfo::GetBrowserActionCommand(extension); 467 requested_command = CommandsInfo::GetBrowserActionCommand(extension);
475 break; 468 break;
(...skipping 22 matching lines...) Expand all
498 491
499 return true; 492 return true;
500 } 493 }
501 494
502 template <> 495 template <>
503 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { 496 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() {
504 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); 497 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance());
505 } 498 }
506 499
507 } // namespace extensions 500 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698