1 // Copyright (c) 2011 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.
5 #ifndef CHROME_BROWSER_UI_COCOA_COMMAND_OBSERVER_BRIDGE
6 #define CHROME_BROWSER_UI_COCOA_COMMAND_OBSERVER_BRIDGE
8 #import <Cocoa/Cocoa.h>
10 #include "base/compiler_specific.h"
11 #include "chrome/browser/command_observer.h"
13 @protocol CommandObserverProtocol
;
17 // A C++ bridge class that handles listening for updates to commands and
18 // passing them back to an object that supports the protocol delcared below.
19 // The observer will create one of these bridges, call ObserveCommand() on the
20 // command ids it cares about, and then wait for update notifications,
21 // delivered via -enabledStateChangedForCommand:enabled:. Destroying this
22 // bridge will handle automatically unregistering for updates, so there's no
23 // need to do that manually.
25 class CommandObserverBridge
: public CommandObserver
{
27 CommandObserverBridge(id
<CommandObserverProtocol
> observer
,
28 CommandUpdater
* commands
);
29 virtual ~CommandObserverBridge();
31 // Register for updates about |command|.
32 void ObserveCommand(int command
);
35 // Overridden from CommandObserver
36 virtual void EnabledStateChangedForCommand(int command
,
37 bool enabled
) OVERRIDE
;
40 id
<CommandObserverProtocol
> observer_
; // weak, owns me
41 CommandUpdater
* commands_
; // weak
44 // Implemented by the observing Objective-C object, called when there is a
45 // state change for the given command.
46 @protocol CommandObserverProtocol
47 - (void)enabledStateChangedForCommand
:(NSInteger
)command enabled
:(BOOL
)enabled
;
50 #endif // CHROME_BROWSER_UI_COCOA_COMMAND_OBSERVER_BRIDGE