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

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

Issue 2777063003: Stop passing raw pointers to base::Value API in c/b/chromeos and c/b/extensions (Closed)
Patch Set: Just rebased Created 3 years, 8 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
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 <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h"
15 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/extensions/api/commands/commands.h" 17 #include "chrome/browser/extensions/api/commands/commands.h"
17 #include "chrome/browser/extensions/extension_commands_global_registry.h" 18 #include "chrome/browser/extensions/extension_commands_global_registry.h"
18 #include "chrome/browser/extensions/extension_keybinding_registry.h" 19 #include "chrome/browser/extensions/extension_keybinding_registry.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/accelerator_utils.h" 21 #include "chrome/browser/ui/accelerator_utils.h"
21 #include "chrome/common/extensions/api/commands/commands_handler.h" 22 #include "chrome/common/extensions/api/commands/commands_handler.h"
22 #include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h" 23 #include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
24 #include "components/pref_registry/pref_registry_syncable.h" 25 #include "components/pref_registry/pref_registry_syncable.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 item->GetString(kCommandName, &old_command_name); 271 item->GetString(kCommandName, &old_command_name);
271 RemoveKeybindingPrefs(old_extension_id, old_command_name); 272 RemoveKeybindingPrefs(old_extension_id, old_command_name);
272 } 273 }
273 274
274 // If the command that is taking a new shortcut already has a shortcut, remove 275 // If the command that is taking a new shortcut already has a shortcut, remove
275 // it before assigning the new one. 276 // it before assigning the new one.
276 if (existing_command.accelerator().key_code() != ui::VKEY_UNKNOWN) 277 if (existing_command.accelerator().key_code() != ui::VKEY_UNKNOWN)
277 RemoveKeybindingPrefs(extension_id, command_name); 278 RemoveKeybindingPrefs(extension_id, command_name);
278 279
279 // Set the keybinding pref. 280 // Set the keybinding pref.
280 base::DictionaryValue* keybinding = new base::DictionaryValue(); 281 auto keybinding = base::MakeUnique<base::DictionaryValue>();
281 keybinding->SetString(kExtension, extension_id); 282 keybinding->SetString(kExtension, extension_id);
282 keybinding->SetString(kCommandName, command_name); 283 keybinding->SetString(kCommandName, command_name);
283 keybinding->SetBoolean(kGlobal, global); 284 keybinding->SetBoolean(kGlobal, global);
284 285
285 bindings->Set(key, keybinding); 286 bindings->Set(key, std::move(keybinding));
286 287
287 // Set the was_assigned pref for the suggested key. 288 // Set the was_assigned pref for the suggested key.
288 std::unique_ptr<base::DictionaryValue> command_keys( 289 std::unique_ptr<base::DictionaryValue> command_keys(
289 new base::DictionaryValue); 290 new base::DictionaryValue);
290 command_keys->SetBoolean(kSuggestedKeyWasAssigned, true); 291 command_keys->SetBoolean(kSuggestedKeyWasAssigned, true);
291 std::unique_ptr<base::DictionaryValue> suggested_key_prefs( 292 std::unique_ptr<base::DictionaryValue> suggested_key_prefs(
292 new base::DictionaryValue); 293 new base::DictionaryValue);
293 suggested_key_prefs->Set(command_name, command_keys.release()); 294 suggested_key_prefs->Set(command_name, std::move(command_keys));
294 MergeSuggestedKeyPrefs(extension_id, ExtensionPrefs::Get(profile_), 295 MergeSuggestedKeyPrefs(extension_id, ExtensionPrefs::Get(profile_),
295 std::move(suggested_key_prefs)); 296 std::move(suggested_key_prefs));
296 297
297 // Fetch the newly-updated command, and notify the observers. 298 // Fetch the newly-updated command, and notify the observers.
298 for (auto& observer : observers_) { 299 for (auto& observer : observers_) {
299 observer.OnExtensionCommandAdded( 300 observer.OnExtensionCommandAdded(
300 extension_id, FindCommandByName(extension_id, command_name)); 301 extension_id, FindCommandByName(extension_id, command_name));
301 } 302 }
302 303
303 // TODO(devlin): Deprecate this notification in favor of the observers. 304 // TODO(devlin): Deprecate this notification in favor of the observers.
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 const CommandMap* commands = CommandsInfo::GetNamedCommands(extension); 640 const CommandMap* commands = CommandsInfo::GetNamedCommands(extension);
640 if (commands) { 641 if (commands) {
641 for (CommandMap::const_iterator iter = commands->begin(); 642 for (CommandMap::const_iterator iter = commands->begin();
642 iter != commands->end(); ++iter) { 643 iter != commands->end(); ++iter) {
643 const Command command = iter->second; 644 const Command command = iter->second;
644 std::unique_ptr<base::DictionaryValue> command_keys( 645 std::unique_ptr<base::DictionaryValue> command_keys(
645 new base::DictionaryValue); 646 new base::DictionaryValue);
646 command_keys->SetString( 647 command_keys->SetString(
647 kSuggestedKey, 648 kSuggestedKey,
648 Command::AcceleratorToString(command.accelerator())); 649 Command::AcceleratorToString(command.accelerator()));
649 suggested_key_prefs->Set(command.command_name(), command_keys.release()); 650 suggested_key_prefs->Set(command.command_name(), std::move(command_keys));
650 } 651 }
651 } 652 }
652 653
653 const Command* browser_action_command = 654 const Command* browser_action_command =
654 CommandsInfo::GetBrowserActionCommand(extension); 655 CommandsInfo::GetBrowserActionCommand(extension);
655 // The browser action command may be defaulted to an unassigned accelerator if 656 // The browser action command may be defaulted to an unassigned accelerator if
656 // a browser action is specified by the extension but a keybinding is not 657 // a browser action is specified by the extension but a keybinding is not
657 // declared. See CommandsHandler::MaybeSetBrowserActionDefault. 658 // declared. See CommandsHandler::MaybeSetBrowserActionDefault.
658 if (browser_action_command && 659 if (browser_action_command &&
659 browser_action_command->accelerator().key_code() != ui::VKEY_UNKNOWN) { 660 browser_action_command->accelerator().key_code() != ui::VKEY_UNKNOWN) {
660 std::unique_ptr<base::DictionaryValue> command_keys( 661 std::unique_ptr<base::DictionaryValue> command_keys(
661 new base::DictionaryValue); 662 new base::DictionaryValue);
662 command_keys->SetString( 663 command_keys->SetString(
663 kSuggestedKey, 664 kSuggestedKey,
664 Command::AcceleratorToString(browser_action_command->accelerator())); 665 Command::AcceleratorToString(browser_action_command->accelerator()));
665 suggested_key_prefs->Set(browser_action_command->command_name(), 666 suggested_key_prefs->Set(browser_action_command->command_name(),
666 command_keys.release()); 667 std::move(command_keys));
667 } 668 }
668 669
669 const Command* page_action_command = 670 const Command* page_action_command =
670 CommandsInfo::GetPageActionCommand(extension); 671 CommandsInfo::GetPageActionCommand(extension);
671 if (page_action_command) { 672 if (page_action_command) {
672 std::unique_ptr<base::DictionaryValue> command_keys( 673 std::unique_ptr<base::DictionaryValue> command_keys(
673 new base::DictionaryValue); 674 new base::DictionaryValue);
674 command_keys->SetString( 675 command_keys->SetString(
675 kSuggestedKey, 676 kSuggestedKey,
676 Command::AcceleratorToString(page_action_command->accelerator())); 677 Command::AcceleratorToString(page_action_command->accelerator()));
677 suggested_key_prefs->Set(page_action_command->command_name(), 678 suggested_key_prefs->Set(page_action_command->command_name(),
678 command_keys.release()); 679 std::move(command_keys));
679 } 680 }
680 681
681 // Merge into current prefs, if present. 682 // Merge into current prefs, if present.
682 MergeSuggestedKeyPrefs(extension->id(), ExtensionPrefs::Get(profile_), 683 MergeSuggestedKeyPrefs(extension->id(), ExtensionPrefs::Get(profile_),
683 std::move(suggested_key_prefs)); 684 std::move(suggested_key_prefs));
684 } 685 }
685 686
686 void CommandService::RemoveDefunctExtensionSuggestedCommandPrefs( 687 void CommandService::RemoveDefunctExtensionSuggestedCommandPrefs(
687 const Extension* extension) { 688 const Extension* extension) {
688 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); 689 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 return true; 909 return true;
909 } 910 }
910 911
911 template <> 912 template <>
912 void 913 void
913 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { 914 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() {
914 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); 915 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance());
915 } 916 }
916 917
917 } // namespace extensions 918 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698