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 <utility> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
10 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
11 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/extensions/api/commands/commands.h" | 16 #include "chrome/browser/extensions/api/commands/commands.h" |
16 #include "chrome/browser/extensions/extension_commands_global_registry.h" | 17 #include "chrome/browser/extensions/extension_commands_global_registry.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 keybinding->SetBoolean(kGlobal, global); | 282 keybinding->SetBoolean(kGlobal, global); |
282 | 283 |
283 bindings->Set(key, keybinding); | 284 bindings->Set(key, keybinding); |
284 | 285 |
285 // Set the was_assigned pref for the suggested key. | 286 // Set the was_assigned pref for the suggested key. |
286 scoped_ptr<base::DictionaryValue> command_keys(new base::DictionaryValue); | 287 scoped_ptr<base::DictionaryValue> command_keys(new base::DictionaryValue); |
287 command_keys->SetBoolean(kSuggestedKeyWasAssigned, true); | 288 command_keys->SetBoolean(kSuggestedKeyWasAssigned, true); |
288 scoped_ptr<base::DictionaryValue> suggested_key_prefs( | 289 scoped_ptr<base::DictionaryValue> suggested_key_prefs( |
289 new base::DictionaryValue); | 290 new base::DictionaryValue); |
290 suggested_key_prefs->Set(command_name, command_keys.release()); | 291 suggested_key_prefs->Set(command_name, command_keys.release()); |
291 MergeSuggestedKeyPrefs(extension_id, | 292 MergeSuggestedKeyPrefs(extension_id, ExtensionPrefs::Get(profile_), |
292 ExtensionPrefs::Get(profile_), | 293 std::move(suggested_key_prefs)); |
293 suggested_key_prefs.Pass()); | |
294 | 294 |
295 // Fetch the newly-updated command, and notify the observers. | 295 // Fetch the newly-updated command, and notify the observers. |
296 FOR_EACH_OBSERVER( | 296 FOR_EACH_OBSERVER( |
297 Observer, | 297 Observer, |
298 observers_, | 298 observers_, |
299 OnExtensionCommandAdded(extension_id, | 299 OnExtensionCommandAdded(extension_id, |
300 FindCommandByName(extension_id, command_name))); | 300 FindCommandByName(extension_id, command_name))); |
301 | 301 |
302 // TODO(devlin): Deprecate this notification in favor of the observers. | 302 // TODO(devlin): Deprecate this notification in favor of the observers. |
303 std::pair<const std::string, const std::string> details = | 303 std::pair<const std::string, const std::string> details = |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 if (page_action_command) { | 668 if (page_action_command) { |
669 scoped_ptr<base::DictionaryValue> command_keys(new base::DictionaryValue); | 669 scoped_ptr<base::DictionaryValue> command_keys(new base::DictionaryValue); |
670 command_keys->SetString( | 670 command_keys->SetString( |
671 kSuggestedKey, | 671 kSuggestedKey, |
672 Command::AcceleratorToString(page_action_command->accelerator())); | 672 Command::AcceleratorToString(page_action_command->accelerator())); |
673 suggested_key_prefs->Set(page_action_command->command_name(), | 673 suggested_key_prefs->Set(page_action_command->command_name(), |
674 command_keys.release()); | 674 command_keys.release()); |
675 } | 675 } |
676 | 676 |
677 // Merge into current prefs, if present. | 677 // Merge into current prefs, if present. |
678 MergeSuggestedKeyPrefs(extension->id(), | 678 MergeSuggestedKeyPrefs(extension->id(), ExtensionPrefs::Get(profile_), |
679 ExtensionPrefs::Get(profile_), | 679 std::move(suggested_key_prefs)); |
680 suggested_key_prefs.Pass()); | |
681 } | 680 } |
682 | 681 |
683 void CommandService::RemoveDefunctExtensionSuggestedCommandPrefs( | 682 void CommandService::RemoveDefunctExtensionSuggestedCommandPrefs( |
684 const Extension* extension) { | 683 const Extension* extension) { |
685 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); | 684 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); |
686 const base::DictionaryValue* current_prefs = NULL; | 685 const base::DictionaryValue* current_prefs = NULL; |
687 extension_prefs->ReadPrefAsDictionary(extension->id(), | 686 extension_prefs->ReadPrefAsDictionary(extension->id(), |
688 kCommands, | 687 kCommands, |
689 ¤t_prefs); | 688 ¤t_prefs); |
690 | 689 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 return true; | 907 return true; |
909 } | 908 } |
910 | 909 |
911 template <> | 910 template <> |
912 void | 911 void |
913 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { | 912 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { |
914 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); | 913 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); |
915 } | 914 } |
916 | 915 |
917 } // namespace extensions | 916 } // namespace extensions |
OLD | NEW |