Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / notifications / message_center_tray_bridge.h
blob0d0b1dd82695f1fdeef4955be0d3ead7e679c401
1 // Copyright (c) 2013 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_NOTIFICATIONS_MESSAGE_CENTER_TRAY_BRIDGE_H_
6 #define CHROME_BROWSER_UI_COCOA_NOTIFICATIONS_MESSAGE_CENTER_TRAY_BRIDGE_H_
8 #import <AppKit/AppKit.h>
10 #include "base/basictypes.h"
11 #include "base/mac/scoped_nsobject.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/prefs/pref_member.h"
15 #include "ui/message_center/message_center.h"
16 #include "ui/message_center/message_center_tray_delegate.h"
18 @class MCPopupCollection;
19 @class MCStatusItemView;
20 @class MCTrayController;
22 namespace message_center {
23 class MessageCenter;
24 class MessageCenterTray;
27 // MessageCenterTrayBridge is the owner of all the Cocoa UI objects for the
28 // message_center. It bridges C++ notifications from the MessageCenterTray to
29 // the various UI objects.
30 class MessageCenterTrayBridge :
31 public message_center::MessageCenterTrayDelegate {
32 public:
33 explicit MessageCenterTrayBridge(
34 message_center::MessageCenter* message_center);
35 ~MessageCenterTrayBridge() override;
37 // message_center::MessageCenterTrayDelegate:
38 void OnMessageCenterTrayChanged() override;
39 bool ShowPopups() override;
40 void HidePopups() override;
41 bool ShowMessageCenter() override;
42 void HideMessageCenter() override;
43 bool ShowNotifierSettings() override;
44 bool IsContextMenuEnabled() const override;
45 message_center::MessageCenterTray* GetMessageCenterTray() override;
47 message_center::MessageCenter* message_center() { return message_center_; }
49 private:
50 friend class MessageCenterTrayBridgeTest;
52 // Updates the unread count on the status item.
53 void UpdateStatusItem();
55 // Opens the message center tray.
56 void OpenTrayWindow();
58 // Returns whether the status item allowed based on the preference value.
59 bool CanShowStatusItem() const;
61 // Returns whether the status item should be shown if allowed.
62 bool NeedsStatusItem() const;
64 // Constructs the status item view and registers its callback.
65 void ShowStatusItem();
67 // Destroys the status item view.
68 void HideStatusItem();
70 // Called after returning to the event loop from the
71 // OnMessageCenterTrayChanged event to prevent multiple updates from being
72 // rendered as the message center is modified.
73 void HandleMessageCenterTrayChanged();
75 // Notifies that the user has changed the show menubar item preference.
76 void OnShowStatusItemChanged();
78 // The global, singleton message center model object. Weak.
79 message_center::MessageCenter* message_center_;
81 // C++ controller for the notification tray UI.
82 scoped_ptr<message_center::MessageCenterTray> tray_;
84 // Obj-C window controller for the notification tray.
85 base::scoped_nsobject<MCTrayController> tray_controller_;
87 // View that is displayed on the system menu bar item.
88 base::scoped_nsobject<MCStatusItemView> status_item_view_;
90 // Obj-C controller for the on-screen popup notifications.
91 base::scoped_nsobject<MCPopupCollection> popup_collection_;
93 // Used to ensure only one status item update happens in a given call stack.
94 bool status_item_update_pending_;
96 // A PrefMember that calls OnShowStatusItemChanged when the pref is updated
97 // by the user's selection in the main menu.
98 BooleanPrefMember show_status_item_;
100 // Weak pointer factory to posts tasks to self.
101 base::WeakPtrFactory<MessageCenterTrayBridge> weak_ptr_factory_;
103 DISALLOW_COPY_AND_ASSIGN(MessageCenterTrayBridge);
106 #endif // CHROME_BROWSER_UI_COCOA_NOTIFICATIONS_MESSAGE_CENTER_TRAY_BRIDGE_H_