Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: chrome/browser/command_updater.h

Issue 10677009: Move command handling and updating off Browser and onto a helper object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // An Observer interface implemented by objects that want to be informed when
14 // the state of a particular command ID is modified.
15 class CommandObserver {
16 public:
sky 2012/06/27 03:09:28 nit: spacing is off here and 21. Also, I think th
17 // Notifies the observer that the enabled state has changed for the
18 // specified command id.
19 virtual void EnabledStateChangedForCommand(int id, bool enabled) = 0;
20
21 protected:
22 virtual ~CommandObserver();
23 };
24
13 //////////////////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////////////////
14 // 26 //
15 // CommandUpdater class 27 // CommandUpdater class
16 // 28 //
17 // This object manages the enabled state of a set of commands. Observers 29 // 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 30 // register to listen to changes in this state so they can update their
19 // presentation. 31 // presentation.
20 // 32 //
21 class CommandUpdater { 33 class CommandUpdater {
22 public: 34 public:
(...skipping 18 matching lines...) Expand all
41 53
42 // Returns true if the specified command ID is supported. 54 // Returns true if the specified command ID is supported.
43 bool SupportsCommand(int id) const; 55 bool SupportsCommand(int id) const;
44 56
45 // Returns true if the specified command ID is enabled. The command ID must be 57 // Returns true if the specified command ID is enabled. The command ID must be
46 // supported by this updater. 58 // supported by this updater.
47 bool IsCommandEnabled(int id) const; 59 bool IsCommandEnabled(int id) const;
48 60
49 // Performs the action associated with this command ID using CURRENT_TAB 61 // Performs the action associated with this command ID using CURRENT_TAB
50 // disposition. 62 // disposition.
51 // TODO(beng): get rid of this since it's effectively just a pass-thru and the 63 // 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. 64 // enabled).
53 void ExecuteCommand(int id); 65 bool ExecuteCommand(int id);
54 66
55 // Performs the action associated with this command ID using the given 67 // Performs the action associated with this command ID using the given
56 // disposition. 68 // disposition.
57 // TODO(altimofeev): refactor the interface to provide more flexible and 69 // Returns true if the command was executed (i.e. it is supported and is
58 // explicit way for passing command specific arguments. See 70 // enabled).
59 // NotificationDetails class for the possible implementation ideas. 71 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 72
74 // Adds an observer to the state of a particular command. If the command does 73 // Adds an observer to the state of a particular command. If the command does
75 // not exist, it is created, initialized to false. 74 // not exist, it is created, initialized to false.
76 void AddCommandObserver(int id, CommandObserver* observer); 75 void AddCommandObserver(int id, CommandObserver* observer);
77 76
78 // Removes an observer to the state of a particular command. 77 // Removes an observer to the state of a particular command.
79 void RemoveCommandObserver(int id, CommandObserver* observer); 78 void RemoveCommandObserver(int id, CommandObserver* observer);
80 79
81 // Removes |observer| for all commands on which it's registered. 80 // Removes |observer| for all commands on which it's registered.
82 void RemoveCommandObserver(CommandObserver* observer); 81 void RemoveCommandObserver(CommandObserver* observer);
(...skipping 18 matching lines...) Expand all
101 100
102 // This is a map of command IDs to states and observer lists 101 // This is a map of command IDs to states and observer lists
103 typedef base::hash_map<int, Command*> CommandMap; 102 typedef base::hash_map<int, Command*> CommandMap;
104 CommandMap commands_; 103 CommandMap commands_;
105 104
106 CommandUpdater(); 105 CommandUpdater();
107 DISALLOW_COPY_AND_ASSIGN(CommandUpdater); 106 DISALLOW_COPY_AND_ASSIGN(CommandUpdater);
108 }; 107 };
109 108
110 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_ 109 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698