OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/message_center/message_center_impl.h" | 5 #include "ui/message_center/message_center_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 base::Closure closure_; | 100 base::Closure closure_; |
101 | 101 |
102 DISALLOW_COPY_AND_ASSIGN(MessageCenterImplTest); | 102 DISALLOW_COPY_AND_ASSIGN(MessageCenterImplTest); |
103 }; | 103 }; |
104 | 104 |
105 class ToggledNotificationBlocker : public NotificationBlocker { | 105 class ToggledNotificationBlocker : public NotificationBlocker { |
106 public: | 106 public: |
107 explicit ToggledNotificationBlocker(MessageCenter* message_center) | 107 explicit ToggledNotificationBlocker(MessageCenter* message_center) |
108 : NotificationBlocker(message_center), | 108 : NotificationBlocker(message_center), |
109 notifications_enabled_(true) {} | 109 notifications_enabled_(true) {} |
110 virtual ~ToggledNotificationBlocker() {} | 110 ~ToggledNotificationBlocker() override {} |
111 | 111 |
112 void SetNotificationsEnabled(bool enabled) { | 112 void SetNotificationsEnabled(bool enabled) { |
113 if (notifications_enabled_ != enabled) { | 113 if (notifications_enabled_ != enabled) { |
114 notifications_enabled_ = enabled; | 114 notifications_enabled_ = enabled; |
115 NotifyBlockingStateChanged(); | 115 NotifyBlockingStateChanged(); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 // NotificationBlocker overrides: | 119 // NotificationBlocker overrides: |
120 virtual bool ShouldShowNotificationAsPopup( | 120 bool ShouldShowNotificationAsPopup( |
121 const message_center::NotifierId& notifier_id) const override { | 121 const message_center::NotifierId& notifier_id) const override { |
122 return notifications_enabled_; | 122 return notifications_enabled_; |
123 } | 123 } |
124 | 124 |
125 private: | 125 private: |
126 bool notifications_enabled_; | 126 bool notifications_enabled_; |
127 | 127 |
128 DISALLOW_COPY_AND_ASSIGN(ToggledNotificationBlocker); | 128 DISALLOW_COPY_AND_ASSIGN(ToggledNotificationBlocker); |
129 }; | 129 }; |
130 | 130 |
131 class PopupNotificationBlocker : public ToggledNotificationBlocker { | 131 class PopupNotificationBlocker : public ToggledNotificationBlocker { |
132 public: | 132 public: |
133 PopupNotificationBlocker(MessageCenter* message_center, | 133 PopupNotificationBlocker(MessageCenter* message_center, |
134 const NotifierId& allowed_notifier) | 134 const NotifierId& allowed_notifier) |
135 : ToggledNotificationBlocker(message_center), | 135 : ToggledNotificationBlocker(message_center), |
136 allowed_notifier_(allowed_notifier) {} | 136 allowed_notifier_(allowed_notifier) {} |
137 virtual ~PopupNotificationBlocker() {} | 137 ~PopupNotificationBlocker() override {} |
138 | 138 |
139 // NotificationBlocker overrides: | 139 // NotificationBlocker overrides: |
140 virtual bool ShouldShowNotificationAsPopup( | 140 bool ShouldShowNotificationAsPopup( |
141 const NotifierId& notifier_id) const override { | 141 const NotifierId& notifier_id) const override { |
142 return (notifier_id == allowed_notifier_) || | 142 return (notifier_id == allowed_notifier_) || |
143 ToggledNotificationBlocker::ShouldShowNotificationAsPopup(notifier_id); | 143 ToggledNotificationBlocker::ShouldShowNotificationAsPopup(notifier_id); |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 NotifierId allowed_notifier_; | 147 NotifierId allowed_notifier_; |
148 | 148 |
149 DISALLOW_COPY_AND_ASSIGN(PopupNotificationBlocker); | 149 DISALLOW_COPY_AND_ASSIGN(PopupNotificationBlocker); |
150 }; | 150 }; |
151 | 151 |
152 class TotalNotificationBlocker : public PopupNotificationBlocker { | 152 class TotalNotificationBlocker : public PopupNotificationBlocker { |
153 public: | 153 public: |
154 TotalNotificationBlocker(MessageCenter* message_center, | 154 TotalNotificationBlocker(MessageCenter* message_center, |
155 const NotifierId& allowed_notifier) | 155 const NotifierId& allowed_notifier) |
156 : PopupNotificationBlocker(message_center, allowed_notifier) {} | 156 : PopupNotificationBlocker(message_center, allowed_notifier) {} |
157 virtual ~TotalNotificationBlocker() {} | 157 ~TotalNotificationBlocker() override {} |
158 | 158 |
159 // NotificationBlocker overrides: | 159 // NotificationBlocker overrides: |
160 virtual bool ShouldShowNotification( | 160 bool ShouldShowNotification(const NotifierId& notifier_id) const override { |
161 const NotifierId& notifier_id) const override { | |
162 return ShouldShowNotificationAsPopup(notifier_id); | 161 return ShouldShowNotificationAsPopup(notifier_id); |
163 } | 162 } |
164 | 163 |
165 private: | 164 private: |
166 DISALLOW_COPY_AND_ASSIGN(TotalNotificationBlocker); | 165 DISALLOW_COPY_AND_ASSIGN(TotalNotificationBlocker); |
167 }; | 166 }; |
168 | 167 |
169 bool PopupNotificationsContain( | 168 bool PopupNotificationsContain( |
170 const NotificationList::PopupNotifications& popups, | 169 const NotificationList::PopupNotifications& popups, |
171 const std::string& id) { | 170 const std::string& id) { |
(...skipping 21 matching lines...) Expand all Loading... |
193 | 192 |
194 namespace internal { | 193 namespace internal { |
195 | 194 |
196 class MockPopupTimersController : public PopupTimersController { | 195 class MockPopupTimersController : public PopupTimersController { |
197 public: | 196 public: |
198 MockPopupTimersController(MessageCenter* message_center, | 197 MockPopupTimersController(MessageCenter* message_center, |
199 base::Closure quit_closure) | 198 base::Closure quit_closure) |
200 : PopupTimersController(message_center), | 199 : PopupTimersController(message_center), |
201 timer_finished_(false), | 200 timer_finished_(false), |
202 quit_closure_(quit_closure) {} | 201 quit_closure_(quit_closure) {} |
203 virtual ~MockPopupTimersController() {} | 202 ~MockPopupTimersController() override {} |
204 | 203 |
205 virtual void TimerFinished(const std::string& id) override { | 204 void TimerFinished(const std::string& id) override { |
206 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); | 205 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); |
207 timer_finished_ = true; | 206 timer_finished_ = true; |
208 last_id_ = id; | 207 last_id_ = id; |
209 } | 208 } |
210 | 209 |
211 bool timer_finished() const { return timer_finished_; } | 210 bool timer_finished() const { return timer_finished_; } |
212 const std::string& last_id() const { return last_id_; } | 211 const std::string& last_id() const { return last_id_; } |
213 | 212 |
214 private: | 213 private: |
215 bool timer_finished_; | 214 bool timer_finished_; |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 ASSERT_EQ(3u, message_center()->NotificationCount()); | 861 ASSERT_EQ(3u, message_center()->NotificationCount()); |
863 | 862 |
864 // Now we remove the remaining notifications. | 863 // Now we remove the remaining notifications. |
865 notifier_settings_observer()->NotifierEnabledChanged( | 864 notifier_settings_observer()->NotifierEnabledChanged( |
866 NotifierId(NotifierId::APPLICATION, "app1"), false); | 865 NotifierId(NotifierId::APPLICATION, "app1"), false); |
867 ASSERT_EQ(0u, message_center()->NotificationCount()); | 866 ASSERT_EQ(0u, message_center()->NotificationCount()); |
868 } | 867 } |
869 | 868 |
870 } // namespace internal | 869 } // namespace internal |
871 } // namespace message_center | 870 } // namespace message_center |
OLD | NEW |