[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / message_center / web_notification_tray.h
blob9ff2492d8bee8a9cd6a98ac1a43d2159cef5af1b
1 // Copyright 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_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_
6 #define CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/prefs/pref_member.h"
10 #include "chrome/browser/status_icons/status_icon_menu_model.h"
11 #include "chrome/browser/status_icons/status_icon_observer.h"
12 #include "chrome/browser/ui/views/message_center/message_center_widget_delegate.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "ui/base/models/simple_menu_model.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/message_center/message_center_tray.h"
18 #include "ui/message_center/message_center_tray_delegate.h"
19 #include "ui/views/widget/widget_observer.h"
21 #if defined(OS_WIN)
22 #include "base/threading/thread.h"
23 #endif
25 class PrefService;
26 class StatusIcon;
28 namespace message_center {
29 class MessageCenter;
30 class MessagePopupCollection;
33 namespace views {
34 class Widget;
37 namespace message_center {
39 struct PositionInfo;
41 class MessageCenterWidgetDelegate;
43 // A MessageCenterTrayDelegate implementation that exposes the MessageCenterTray
44 // via a system tray icon. The notification popups will be displayed in the
45 // corner of the screen and the message center will be displayed by the system
46 // tray icon on click.
47 class WebNotificationTray : public message_center::MessageCenterTrayDelegate,
48 public StatusIconObserver,
49 public base::SupportsWeakPtr<WebNotificationTray>,
50 public StatusIconMenuModel::Delegate {
51 public:
52 explicit WebNotificationTray(PrefService* local_state);
53 virtual ~WebNotificationTray();
55 message_center::MessageCenter* message_center();
57 // MessageCenterTrayDelegate implementation.
58 virtual bool ShowPopups() OVERRIDE;
59 virtual void HidePopups() OVERRIDE;
60 virtual bool ShowMessageCenter() OVERRIDE;
61 virtual void HideMessageCenter() OVERRIDE;
62 virtual void OnMessageCenterTrayChanged() OVERRIDE;
63 virtual bool ShowNotifierSettings() OVERRIDE;
64 virtual bool IsContextMenuEnabled() const OVERRIDE;
66 // StatusIconObserver implementation.
67 virtual void OnStatusIconClicked() OVERRIDE;
68 #if defined(OS_WIN)
69 virtual void OnBalloonClicked() OVERRIDE;
71 // This shows a platform-specific balloon informing the user of the existence
72 // of the message center in the status tray area.
73 void DisplayFirstRunBalloon();
75 void EnforceStatusIconVisible();
76 #endif
78 // StatusIconMenuModel::Delegate implementation.
79 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
81 // Changes the icon and hovertext based on number of unread notifications.
82 void UpdateStatusIcon();
83 void SendHideMessageCenter();
84 void MarkMessageCenterHidden();
86 // Gets the point where the status icon was clicked.
87 gfx::Point mouse_click_point() { return mouse_click_point_; }
88 virtual MessageCenterTray* GetMessageCenterTray() OVERRIDE;
90 private:
91 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
92 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble);
93 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest,
94 ManyMessageCenterNotifications);
95 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications);
96 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManuallyCloseMessageCenter);
98 PositionInfo GetPositionInfo();
100 void CreateStatusIcon(const gfx::ImageSkia& image,
101 const base::string16& tool_tip);
102 void DestroyStatusIcon();
103 void AddQuietModeMenu(StatusIcon* status_icon);
104 MessageCenterWidgetDelegate* GetMessageCenterWidgetDelegateForTest();
106 #if defined(OS_WIN)
107 // This member variable keeps track of whether EnforceStatusIconVisible has
108 // been invoked on this machine, so the user still has control after we try
109 // promoting it the first time.
110 scoped_ptr<BooleanPrefMember> did_force_tray_visible_;
111 #endif
113 MessageCenterWidgetDelegate* message_center_delegate_;
114 scoped_ptr<message_center::MessagePopupCollection> popup_collection_;
116 StatusIcon* status_icon_;
117 StatusIconMenuModel* status_icon_menu_;
118 scoped_ptr<MessageCenterTray> message_center_tray_;
119 gfx::Point mouse_click_point_;
121 bool should_update_tray_content_;
122 bool last_quiet_mode_state_;
124 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
127 } // namespace message_center
129 #endif // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_