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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 const CommandMap::const_iterator command(commands_.find(id)); | 33 const CommandMap::const_iterator command(commands_.find(id)); |
34 if (command == commands_.end()) | 34 if (command == commands_.end()) |
35 return false; | 35 return false; |
36 return command->second->enabled; | 36 return command->second->enabled; |
37 } | 37 } |
38 | 38 |
39 bool CommandUpdater::SupportsCommand(int id) const { | 39 bool CommandUpdater::SupportsCommand(int id) const { |
40 return commands_.find(id) != commands_.end(); | 40 return commands_.find(id) != commands_.end(); |
41 } | 41 } |
42 | 42 |
43 void CommandUpdater::ExecuteCommand(int id) { | 43 bool CommandUpdater::ExecuteCommand(int id) { |
44 ExecuteCommandWithDisposition(id, CURRENT_TAB); | 44 return ExecuteCommandWithDisposition(id, CURRENT_TAB); |
45 } | 45 } |
46 | 46 |
47 void CommandUpdater::ExecuteCommandWithDisposition( | 47 bool CommandUpdater::ExecuteCommandWithDisposition( |
48 int id, | 48 int id, |
49 WindowOpenDisposition disposition) { | 49 WindowOpenDisposition disposition) { |
50 if (IsCommandEnabled(id)) | 50 if (SupportsCommand(id) && IsCommandEnabled(id)) { |
51 delegate_->ExecuteCommandWithDisposition(id, disposition); | 51 delegate_->ExecuteCommandWithDisposition(id, disposition); |
| 52 return true; |
| 53 } |
| 54 return false; |
52 } | 55 } |
53 | 56 |
54 CommandUpdater::CommandObserver::~CommandObserver() { | 57 CommandObserver::~CommandObserver() { |
55 } | 58 } |
56 | 59 |
57 void CommandUpdater::UpdateCommandEnabled(int id, bool enabled) { | 60 void CommandUpdater::UpdateCommandEnabled(int id, bool enabled) { |
58 Command* command = GetCommand(id, true); | 61 Command* command = GetCommand(id, true); |
59 if (command->enabled == enabled) | 62 if (command->enabled == enabled) |
60 return; // Nothing to do. | 63 return; // Nothing to do. |
61 command->enabled = enabled; | 64 command->enabled = enabled; |
62 FOR_EACH_OBSERVER(CommandObserver, command->observers, | 65 FOR_EACH_OBSERVER(CommandObserver, command->observers, |
63 EnabledStateChangedForCommand(id, enabled)); | 66 EnabledStateChangedForCommand(id, enabled)); |
64 } | 67 } |
(...skipping 18 matching lines...) Expand all Loading... |
83 | 86 |
84 void CommandUpdater::RemoveCommandObserver(CommandObserver* observer) { | 87 void CommandUpdater::RemoveCommandObserver(CommandObserver* observer) { |
85 for (CommandMap::const_iterator it = commands_.begin(); | 88 for (CommandMap::const_iterator it = commands_.begin(); |
86 it != commands_.end(); | 89 it != commands_.end(); |
87 ++it) { | 90 ++it) { |
88 Command* command = it->second; | 91 Command* command = it->second; |
89 if (command) | 92 if (command) |
90 command->observers.RemoveObserver(observer); | 93 command->observers.RemoveObserver(observer); |
91 } | 94 } |
92 } | 95 } |
OLD | NEW |