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/commands.h" | 5 #include "chrome/browser/extensions/api/commands/commands.h" |
6 | 6 |
| 7 #include <memory> |
| 8 #include <utility> |
| 9 |
7 #include "chrome/browser/extensions/api/commands/command_service.h" | 10 #include "chrome/browser/extensions/api/commands/command_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
9 | 12 |
10 namespace { | 13 namespace { |
11 | 14 |
12 base::DictionaryValue* CreateCommandValue( | 15 base::DictionaryValue* CreateCommandValue( |
13 const extensions::Command& command, bool active) { | 16 const extensions::Command& command, bool active) { |
14 base::DictionaryValue* result = new base::DictionaryValue(); | 17 base::DictionaryValue* result = new base::DictionaryValue(); |
15 result->SetString("name", command.command_name()); | 18 result->SetString("name", command.command_name()); |
16 result->SetString("description", command.description()); | 19 result->SetString("description", command.description()); |
17 result->SetString("shortcut", | 20 result->SetString("shortcut", |
18 active ? command.accelerator().GetShortcutText() : | 21 active ? command.accelerator().GetShortcutText() : |
19 base::string16()); | 22 base::string16()); |
20 return result; | 23 return result; |
21 } | 24 } |
22 | 25 |
23 } // namespace | 26 } // namespace |
24 | 27 |
25 bool GetAllCommandsFunction::RunSync() { | 28 bool GetAllCommandsFunction::RunSync() { |
26 base::ListValue* command_list = new base::ListValue(); | 29 std::unique_ptr<base::ListValue> command_list(new base::ListValue()); |
27 | 30 |
28 extensions::CommandService* command_service = | 31 extensions::CommandService* command_service = |
29 extensions::CommandService::Get(GetProfile()); | 32 extensions::CommandService::Get(GetProfile()); |
30 | 33 |
31 extensions::Command browser_action; | 34 extensions::Command browser_action; |
32 bool active = false; | 35 bool active = false; |
33 if (command_service->GetBrowserActionCommand(extension_->id(), | 36 if (command_service->GetBrowserActionCommand(extension_->id(), |
34 extensions::CommandService::ALL, | 37 extensions::CommandService::ALL, |
35 &browser_action, | 38 &browser_action, |
36 &active)) { | 39 &active)) { |
(...skipping 17 matching lines...) Expand all Loading... |
54 for (extensions::CommandMap::const_iterator iter = named_commands.begin(); | 57 for (extensions::CommandMap::const_iterator iter = named_commands.begin(); |
55 iter != named_commands.end(); ++iter) { | 58 iter != named_commands.end(); ++iter) { |
56 extensions::Command command = command_service->FindCommandByName( | 59 extensions::Command command = command_service->FindCommandByName( |
57 extension_->id(), iter->second.command_name()); | 60 extension_->id(), iter->second.command_name()); |
58 ui::Accelerator shortcut_assigned = command.accelerator(); | 61 ui::Accelerator shortcut_assigned = command.accelerator(); |
59 active = (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN); | 62 active = (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN); |
60 | 63 |
61 command_list->Append(CreateCommandValue(iter->second, active)); | 64 command_list->Append(CreateCommandValue(iter->second, active)); |
62 } | 65 } |
63 | 66 |
64 SetResult(command_list); | 67 SetResult(std::move(command_list)); |
65 return true; | 68 return true; |
66 } | 69 } |
OLD | NEW |