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/command_updater.h" | 5 #include "chrome/browser/command_updater.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "chrome/browser/command_observer.h" | 12 #include "chrome/browser/command_observer.h" |
13 #include "chrome/browser/command_updater_delegate.h" | 13 #include "chrome/browser/command_updater_delegate.h" |
14 | 14 |
15 class CommandUpdater::Command { | 15 class CommandUpdater::Command { |
16 public: | 16 public: |
17 bool enabled; | 17 bool enabled; |
18 base::ObserverList<CommandObserver> observers; | 18 base::ObserverList<CommandObserver> observers; |
19 | 19 |
20 Command() : enabled(true) {} | 20 Command() : enabled(true) {} |
21 }; | 21 }; |
22 | 22 |
23 CommandUpdater::CommandUpdater(CommandUpdaterDelegate* delegate) | 23 CommandUpdater::CommandUpdater(CommandUpdaterDelegate* delegate) |
24 : delegate_(delegate) { | 24 : delegate_(delegate) { |
25 } | 25 } |
26 | 26 |
27 CommandUpdater::~CommandUpdater() { | 27 CommandUpdater::~CommandUpdater() { |
28 STLDeleteContainerPairSecondPointers(commands_.begin(), commands_.end()); | 28 base::STLDeleteContainerPairSecondPointers(commands_.begin(), |
| 29 commands_.end()); |
29 } | 30 } |
30 | 31 |
31 bool CommandUpdater::SupportsCommand(int id) const { | 32 bool CommandUpdater::SupportsCommand(int id) const { |
32 return commands_.find(id) != commands_.end(); | 33 return commands_.find(id) != commands_.end(); |
33 } | 34 } |
34 | 35 |
35 bool CommandUpdater::IsCommandEnabled(int id) const { | 36 bool CommandUpdater::IsCommandEnabled(int id) const { |
36 const CommandMap::const_iterator command(commands_.find(id)); | 37 const CommandMap::const_iterator command(commands_.find(id)); |
37 if (command == commands_.end()) | 38 if (command == commands_.end()) |
38 return false; | 39 return false; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 83 |
83 CommandUpdater::Command* CommandUpdater::GetCommand(int id, bool create) { | 84 CommandUpdater::Command* CommandUpdater::GetCommand(int id, bool create) { |
84 bool supported = SupportsCommand(id); | 85 bool supported = SupportsCommand(id); |
85 if (supported) | 86 if (supported) |
86 return commands_[id]; | 87 return commands_[id]; |
87 DCHECK(create); | 88 DCHECK(create); |
88 Command* command = new Command; | 89 Command* command = new Command; |
89 commands_[id] = command; | 90 commands_[id] = command; |
90 return command; | 91 return command; |
91 } | 92 } |
OLD | NEW |