command_updater.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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
  3. // found in the LICENSE file.
  4. #ifndef CHROME_BROWSER_COMMAND_UPDATER_H_
  5. #define CHROME_BROWSER_COMMAND_UPDATER_H_
  6. #include "base/time/time.h"
  7. #include "ui/base/window_open_disposition.h"
  8. class CommandObserver;
  9. ////////////////////////////////////////////////////////////////////////////////
  10. //
  11. // CommandUpdater interface
  12. //
  13. // This is the public API to manage the enabled state of a set of commands.
  14. // Observers register to listen to changes in this state so they can update
  15. // their presentation.
  16. //
  17. // The actual implementation of this is in CommandUpdaterImpl, this interface
  18. // exists purely so that classes using the actual CommandUpdaterImpl can
  19. // expose it through a safe public interface (as opposed to directly exposing
  20. // the private implementation details).
  21. //
  22. class CommandUpdater {
  23. public:
  24. virtual ~CommandUpdater() {}
  25. // Returns true if the specified command ID is supported.
  26. virtual bool SupportsCommand(int id) const = 0;
  27. // Returns true if the specified command ID is enabled. The command ID must be
  28. // supported by this updater.
  29. virtual bool IsCommandEnabled(int id) const = 0;
  30. // Performs the action associated with this command ID using CURRENT_TAB
  31. // disposition.
  32. // Returns true if the command was executed (i.e. it is supported and is
  33. // enabled).
  34. virtual bool ExecuteCommand(
  35. int id,
  36. base::TimeTicks time_stamp = base::TimeTicks::Now()) = 0;
  37. // Performs the action associated with this command ID using the given
  38. // disposition.
  39. // Returns true if the command was executed (i.e. it is supported and is
  40. // enabled).
  41. virtual bool ExecuteCommandWithDisposition(
  42. int id,
  43. WindowOpenDisposition disposition,
  44. base::TimeTicks time_stamp = base::TimeTicks::Now()) = 0;
  45. // Adds an observer to the state of a particular command. If the command does
  46. // not exist, it is created, initialized to false.
  47. virtual void AddCommandObserver(int id, CommandObserver* observer) = 0;
  48. // Removes an observer to the state of a particular command.
  49. virtual void RemoveCommandObserver(int id, CommandObserver* observer) = 0;
  50. // Removes |observer| for all commands on which it's registered.
  51. virtual void RemoveCommandObserver(CommandObserver* observer) = 0;
  52. // Notify all observers of a particular command that the command has been
  53. // enabled or disabled. If the command does not exist, it is created and
  54. // initialized to |state|. This function is very lightweight if the command
  55. // state has not changed.
  56. // Returns true if the update succeeded (it's possible that the browser is in
  57. // "locked-down" state where we prevent changes to the command state).
  58. virtual bool UpdateCommandEnabled(int id, bool state) = 0;
  59. };
  60. #endif // CHROME_BROWSER_COMMAND_UPDATER_H_