1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_COMMAND_UPDATER_H_
6 #define CHROME_BROWSER_COMMAND_UPDATER_H_
8 #include "base/time/time.h"
9 #include "ui/base/window_open_disposition.h"
11 class CommandObserver;
13 ////////////////////////////////////////////////////////////////////////////////
15 // CommandUpdater interface
17 // This is the public API to manage the enabled state of a set of commands.
18 // Observers register to listen to changes in this state so they can update
19 // their presentation.
21 // The actual implementation of this is in CommandUpdaterImpl, this interface
22 // exists purely so that classes using the actual CommandUpdaterImpl can
23 // expose it through a safe public interface (as opposed to directly exposing
24 // the private implementation details).
26 class CommandUpdater {
28 virtual ~CommandUpdater() {}
30 // Returns true if the specified command ID is supported.
31 virtual bool SupportsCommand(int id) const = 0;
33 // Returns true if the specified command ID is enabled. The command ID must be
34 // supported by this updater.
35 virtual bool IsCommandEnabled(int id) const = 0;
37 // Performs the action associated with this command ID using CURRENT_TAB
39 // Returns true if the command was executed (i.e. it is supported and is
41 virtual bool ExecuteCommand(
43 base::TimeTicks time_stamp = base::TimeTicks::Now()) = 0;
45 // Performs the action associated with this command ID using the given
47 // Returns true if the command was executed (i.e. it is supported and is
49 virtual bool ExecuteCommandWithDisposition(
51 WindowOpenDisposition disposition,
52 base::TimeTicks time_stamp = base::TimeTicks::Now()) = 0;
54 // Adds an observer to the state of a particular command. If the command does
55 // not exist, it is created, initialized to false.
56 virtual void AddCommandObserver(int id, CommandObserver* observer) = 0;
58 // Removes an observer to the state of a particular command.
59 virtual void RemoveCommandObserver(int id, CommandObserver* observer) = 0;
61 // Removes |observer| for all commands on which it's registered.
62 virtual void RemoveCommandObserver(CommandObserver* observer) = 0;
64 // Notify all observers of a particular command that the command has been
65 // enabled or disabled. If the command does not exist, it is created and
66 // initialized to |state|. This function is very lightweight if the command
67 // state has not changed.
68 // Returns true if the update succeeded (it's possible that the browser is in
69 // "locked-down" state where we prevent changes to the command state).
70 virtual bool UpdateCommandEnabled(int id, bool state) = 0;
73 #endif // CHROME_BROWSER_COMMAND_UPDATER_H_