Chromium Code Reviews| Index: chrome/browser/command_updater.cc |
| diff --git a/chrome/browser/command_updater.cc b/chrome/browser/command_updater.cc |
| index 63e50305256ce60d4394d512aa5d74ed0973d66a..1312c0209119cd601dd068c59be0f442c2d3dcec 100644 |
| --- a/chrome/browser/command_updater.cc |
| +++ b/chrome/browser/command_updater.cc |
| @@ -7,8 +7,8 @@ |
| #include <algorithm> |
| #include "base/logging.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/observer_list.h" |
| -#include "base/stl_util.h" |
| #include "chrome/browser/command_observer.h" |
| #include "chrome/browser/command_updater_delegate.h" |
| @@ -25,8 +25,6 @@ CommandUpdater::CommandUpdater(CommandUpdaterDelegate* delegate) |
| } |
| CommandUpdater::~CommandUpdater() { |
| - base::STLDeleteContainerPairSecondPointers(commands_.begin(), |
| - commands_.end()); |
| } |
| bool CommandUpdater::SupportsCommand(int id) const { |
| @@ -34,7 +32,7 @@ bool CommandUpdater::SupportsCommand(int id) const { |
| } |
| bool CommandUpdater::IsCommandEnabled(int id) const { |
| - const CommandMap::const_iterator command(commands_.find(id)); |
| + auto command = commands_.find(id); |
| if (command == commands_.end()) |
| return false; |
| return command->second->enabled; |
| @@ -63,10 +61,8 @@ void CommandUpdater::RemoveCommandObserver(int id, CommandObserver* observer) { |
| } |
| void CommandUpdater::RemoveCommandObserver(CommandObserver* observer) { |
| - for (CommandMap::const_iterator it = commands_.begin(); |
| - it != commands_.end(); |
| - ++it) { |
| - Command* command = it->second; |
| + for (auto it = commands_.begin(); it != commands_.end(); ++it) { |
|
Nico
2016/09/22 15:56:11
can't this be a for ( ... : commands_) style loop?
Avi (use Gerrit)
2016/09/22 19:17:17
Done.
|
| + Command* command = it->second.get(); |
| if (command) |
| command->observers.RemoveObserver(observer); |
| } |
| @@ -84,9 +80,8 @@ void CommandUpdater::UpdateCommandEnabled(int id, bool enabled) { |
| CommandUpdater::Command* CommandUpdater::GetCommand(int id, bool create) { |
| bool supported = SupportsCommand(id); |
| if (supported) |
| - return commands_[id]; |
| + return commands_[id].get(); |
| DCHECK(create); |
| - Command* command = new Command; |
| - commands_[id] = command; |
| - return command; |
| + commands_[id] = base::MakeUnique<Command>(); |
| + return commands_[id].get(); |
|
Nico
2016/09/22 15:56:11
also walks twice
Avi (use Gerrit)
2016/09/22 19:17:16
Done.
|
| } |