Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/popup_timer.h" | 5 #include "ui/message_center/popup_timer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/message_center/message_center_style.h" | 9 #include "ui/message_center/message_center_style.h" |
| 10 #include "ui/message_center/message_center_types.h" | 10 #include "ui/message_center/message_center_types.h" |
| 11 #include "ui/message_center/notification.h" | 11 #include "ui/message_center/notification.h" |
| 12 #include "ui/message_center/notification_list.h" | 12 #include "ui/message_center/notification_list.h" |
| 13 | 13 |
| 14 namespace message_center { | |
| 15 | |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 base::TimeDelta GetTimeoutForPriority(int priority) { | 18 base::TimeDelta GetTimeoutForNotification(Notification* notification) { |
| 17 if (priority > message_center::DEFAULT_PRIORITY) { | 19 if (notification->priority() > message_center::DEFAULT_PRIORITY) |
| 18 return base::TimeDelta::FromSeconds( | 20 return base::TimeDelta::FromSeconds(kAutocloseHighPriorityDelaySeconds); |
| 19 message_center::kAutocloseHighPriorityDelaySeconds); | 21 if (notification->is_web_notification()) { |
| 22 // Web notifications use a larger timeout, which improves re-engagement. | |
| 23 // TODO(johnme): Use Finch to experiment with different values. | |
| 24 return base::TimeDelta::FromSeconds(20); | |
|
dewittj
2015/10/07 17:56:40
please add a constant to message_center_style.h in
johnme
2015/10/07 18:18:06
Done.
| |
| 20 } | 25 } |
| 21 return base::TimeDelta::FromSeconds( | 26 return base::TimeDelta::FromSeconds(kAutocloseDefaultDelaySeconds); |
| 22 message_center::kAutocloseDefaultDelaySeconds); | |
| 23 } | 27 } |
| 24 | 28 |
| 25 } // namespace | 29 } // namespace |
| 26 | 30 |
| 27 namespace message_center { | |
| 28 | |
| 29 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
| 30 // PopupTimer | 32 // PopupTimer |
| 31 | 33 |
| 32 PopupTimer::PopupTimer(const std::string& id, | 34 PopupTimer::PopupTimer(const std::string& id, |
| 33 base::TimeDelta timeout, | 35 base::TimeDelta timeout, |
| 34 base::WeakPtr<PopupTimersController> controller) | 36 base::WeakPtr<PopupTimersController> controller) |
| 35 : id_(id), | 37 : id_(id), |
| 36 timeout_(timeout), | 38 timeout_(timeout), |
| 37 timer_controller_(controller), | 39 timer_controller_(controller), |
| 38 timer_(new base::OneShotTimer) {} | 40 timer_(new base::OneShotTimer) {} |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 break; | 160 break; |
| 159 } | 161 } |
| 160 | 162 |
| 161 if (iter == popup_notifications.end() || (*iter)->never_timeout()) { | 163 if (iter == popup_notifications.end() || (*iter)->never_timeout()) { |
| 162 CancelTimer(id); | 164 CancelTimer(id); |
| 163 return; | 165 return; |
| 164 } | 166 } |
| 165 | 167 |
| 166 // Start the timer if not yet. | 168 // Start the timer if not yet. |
| 167 if (popup_timers_.find(id) == popup_timers_.end()) | 169 if (popup_timers_.find(id) == popup_timers_.end()) |
| 168 StartTimer(id, GetTimeoutForPriority((*iter)->priority())); | 170 StartTimer(id, GetTimeoutForNotification(*iter)); |
| 169 } | 171 } |
| 170 | 172 |
| 171 void PopupTimersController::OnNotificationRemoved(const std::string& id, | 173 void PopupTimersController::OnNotificationRemoved(const std::string& id, |
| 172 bool by_user) { | 174 bool by_user) { |
| 173 CancelTimer(id); | 175 CancelTimer(id); |
| 174 } | 176 } |
| 175 | 177 |
| 176 } // namespace message_center | 178 } // namespace message_center |
| OLD | NEW |