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 #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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
11 #include "webkit/glue/window_open_disposition.h" | 11 #include "webkit/glue/window_open_disposition.h" |
12 | 12 |
| 13 class CommandObserver; |
| 14 |
13 //////////////////////////////////////////////////////////////////////////////// | 15 //////////////////////////////////////////////////////////////////////////////// |
14 // | 16 // |
15 // CommandUpdater class | 17 // CommandUpdater class |
16 // | 18 // |
17 // This object manages the enabled state of a set of commands. Observers | 19 // This object manages the enabled state of a set of commands. Observers |
18 // register to listen to changes in this state so they can update their | 20 // register to listen to changes in this state so they can update their |
19 // presentation. | 21 // presentation. |
20 // | 22 // |
21 class CommandUpdater { | 23 class CommandUpdater { |
22 public: | 24 public: |
(...skipping 18 matching lines...) Expand all Loading... |
41 | 43 |
42 // Returns true if the specified command ID is supported. | 44 // Returns true if the specified command ID is supported. |
43 bool SupportsCommand(int id) const; | 45 bool SupportsCommand(int id) const; |
44 | 46 |
45 // Returns true if the specified command ID is enabled. The command ID must be | 47 // Returns true if the specified command ID is enabled. The command ID must be |
46 // supported by this updater. | 48 // supported by this updater. |
47 bool IsCommandEnabled(int id) const; | 49 bool IsCommandEnabled(int id) const; |
48 | 50 |
49 // Performs the action associated with this command ID using CURRENT_TAB | 51 // Performs the action associated with this command ID using CURRENT_TAB |
50 // disposition. | 52 // disposition. |
51 // TODO(beng): get rid of this since it's effectively just a pass-thru and the | 53 // Returns true if the command was executed (i.e. it is supported and is |
52 // call sites would be better off using more well defined delegate interfaces. | 54 // enabled). |
53 void ExecuteCommand(int id); | 55 bool ExecuteCommand(int id); |
54 | 56 |
55 // Performs the action associated with this command ID using the given | 57 // Performs the action associated with this command ID using the given |
56 // disposition. | 58 // disposition. |
57 // TODO(altimofeev): refactor the interface to provide more flexible and | 59 // Returns true if the command was executed (i.e. it is supported and is |
58 // explicit way for passing command specific arguments. See | 60 // enabled). |
59 // NotificationDetails class for the possible implementation ideas. | 61 bool ExecuteCommandWithDisposition(int id, WindowOpenDisposition disposition); |
60 void ExecuteCommandWithDisposition(int id, WindowOpenDisposition disposition); | |
61 | |
62 // An Observer interface implemented by objects that want to be informed when | |
63 // the state of a particular command ID is modified. | |
64 class CommandObserver { | |
65 public: | |
66 // Notifies the observer that the enabled state has changed for the | |
67 // specified command id. | |
68 virtual void EnabledStateChangedForCommand(int id, bool enabled) = 0; | |
69 | |
70 protected: | |
71 virtual ~CommandObserver(); | |
72 }; | |
73 | 62 |
74 // Adds an observer to the state of a particular command. If the command does | 63 // Adds an observer to the state of a particular command. If the command does |
75 // not exist, it is created, initialized to false. | 64 // not exist, it is created, initialized to false. |
76 void AddCommandObserver(int id, CommandObserver* observer); | 65 void AddCommandObserver(int id, CommandObserver* observer); |
77 | 66 |
78 // Removes an observer to the state of a particular command. | 67 // Removes an observer to the state of a particular command. |
79 void RemoveCommandObserver(int id, CommandObserver* observer); | 68 void RemoveCommandObserver(int id, CommandObserver* observer); |
80 | 69 |
81 // Removes |observer| for all commands on which it's registered. | 70 // Removes |observer| for all commands on which it's registered. |
82 void RemoveCommandObserver(CommandObserver* observer); | 71 void RemoveCommandObserver(CommandObserver* observer); |
(...skipping 18 matching lines...) Expand all Loading... |
101 | 90 |
102 // This is a map of command IDs to states and observer lists | 91 // This is a map of command IDs to states and observer lists |
103 typedef base::hash_map<int, Command*> CommandMap; | 92 typedef base::hash_map<int, Command*> CommandMap; |
104 CommandMap commands_; | 93 CommandMap commands_; |
105 | 94 |
106 CommandUpdater(); | 95 CommandUpdater(); |
107 DISALLOW_COPY_AND_ASSIGN(CommandUpdater); | 96 DISALLOW_COPY_AND_ASSIGN(CommandUpdater); |
108 }; | 97 }; |
109 | 98 |
110 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_ | 99 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_ |
OLD | NEW |