| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_COMMAND_UPDATER_H_ | 5 #ifndef CHROME_BROWSER_COMMAND_UPDATER_H_ |
| 6 #define CHROME_BROWSER_COMMAND_UPDATER_H_ | 6 #define CHROME_BROWSER_COMMAND_UPDATER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
| 10 | 10 |
| 11 //////////////////////////////////////////////////////////////////////////////// | 11 //////////////////////////////////////////////////////////////////////////////// |
| 12 // | 12 // |
| 13 // CommandUpdater class | 13 // CommandUpdater class |
| 14 // | 14 // |
| 15 // This object manages the enabled state of a set of commands. Observers | 15 // This object manages the enabled state of a set of commands. Observers |
| 16 // register to listen to changes in this state so they can update their | 16 // register to listen to changes in this state so they can update their |
| 17 // presentation. | 17 // presentation. |
| 18 // | 18 // |
| 19 class CommandUpdater { | 19 class CommandUpdater { |
| 20 public: | 20 public: |
| 21 // A Delegate object implements this interface so that it can execute commands | 21 // A Delegate object implements this interface so that it can execute commands |
| 22 // when needed. | 22 // when needed. |
| 23 class CommandUpdaterDelegate { | 23 class CommandUpdaterDelegate { |
| 24 public: | 24 public: |
| 25 // Perform the action associated with the command with the specified ID. | 25 // Perform the action associated with the command with the specified ID. |
| 26 virtual void ExecuteCommand(int id) = 0; | 26 virtual void ExecuteCommand(int id) = 0; |
| 27 protected: | |
| 28 ~CommandUpdaterDelegate() {} | |
| 29 }; | 27 }; |
| 30 | 28 |
| 31 // Create a CommandUpdater with a CommandUpdaterDelegate to handle execution | 29 // Create a CommandUpdater with a CommandUpdaterDelegate to handle execution |
| 32 // of specific commands. | 30 // of specific commands. |
| 33 explicit CommandUpdater(CommandUpdaterDelegate* handler); | 31 explicit CommandUpdater(CommandUpdaterDelegate* handler); |
| 34 virtual ~CommandUpdater(); | 32 virtual ~CommandUpdater(); |
| 35 | 33 |
| 36 // Returns true if the specified command ID is supported. | 34 // Returns true if the specified command ID is supported. |
| 37 bool SupportsCommand(int id) const; | 35 bool SupportsCommand(int id) const; |
| 38 | 36 |
| 39 // Returns true if the specified command ID is enabled. The command ID must be | 37 // Returns true if the specified command ID is enabled. The command ID must be |
| 40 // supported by this updater. | 38 // supported by this updater. |
| 41 bool IsCommandEnabled(int id) const; | 39 bool IsCommandEnabled(int id) const; |
| 42 | 40 |
| 43 // Performs the action associated with this command ID. | 41 // Performs the action associated with this command ID. |
| 44 // TODO(beng): get rid of this since it's effectively just a pass-thru and the | 42 // TODO(beng): get rid of this since it's effectively just a pass-thru and the |
| 45 // call sites would be better off using more well defined delegate interfaces. | 43 // call sites would be better off using more well defined delegate interfaces. |
| 46 void ExecuteCommand(int id); | 44 void ExecuteCommand(int id); |
| 47 | 45 |
| 48 // An Observer interface implemented by objects that want to be informed when | 46 // An Observer interface implemented by objects that want to be informed when |
| 49 // the state of a particular command ID is modified. | 47 // the state of a particular command ID is modified. |
| 50 class CommandObserver { | 48 class CommandObserver { |
| 51 public: | 49 public: |
| 52 // Notifies the observer that the enabled state has changed for the | 50 // Notifies the observer that the enabled state has changed for the |
| 53 // specified command id. | 51 // specified command id. |
| 54 virtual void EnabledStateChangedForCommand(int id, bool enabled) = 0; | 52 virtual void EnabledStateChangedForCommand(int id, bool enabled) = 0; |
| 55 protected: | |
| 56 ~CommandObserver() {} | |
| 57 }; | 53 }; |
| 58 | 54 |
| 59 // Adds an observer to the state of a particular command. If the command does | 55 // Adds an observer to the state of a particular command. If the command does |
| 60 // not exist, it is created, initialized to false. | 56 // not exist, it is created, initialized to false. |
| 61 void AddCommandObserver(int id, CommandObserver* observer); | 57 void AddCommandObserver(int id, CommandObserver* observer); |
| 62 | 58 |
| 63 // Removes an observer to the state of a particular command. | 59 // Removes an observer to the state of a particular command. |
| 64 void RemoveCommandObserver(int id, CommandObserver* observer); | 60 void RemoveCommandObserver(int id, CommandObserver* observer); |
| 65 | 61 |
| 66 // Removes |observer| for all commands on which it's registered. | 62 // Removes |observer| for all commands on which it's registered. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 86 | 82 |
| 87 // This is a map of command IDs to states and observer lists | 83 // This is a map of command IDs to states and observer lists |
| 88 typedef base::hash_map<int, Command*> CommandMap; | 84 typedef base::hash_map<int, Command*> CommandMap; |
| 89 CommandMap commands_; | 85 CommandMap commands_; |
| 90 | 86 |
| 91 CommandUpdater(); | 87 CommandUpdater(); |
| 92 DISALLOW_EVIL_CONSTRUCTORS(CommandUpdater); | 88 DISALLOW_EVIL_CONSTRUCTORS(CommandUpdater); |
| 93 }; | 89 }; |
| 94 | 90 |
| 95 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_ | 91 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_ |
| OLD | NEW |