| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_timers_controller.h" | 5 #include "ui/message_center/popup_timers_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "ui/message_center/message_center_style.h" | 10 #include "ui/message_center/message_center_style.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 timer->Start(); | 46 timer->Start(); |
| 47 popup_timers_.insert(std::make_pair(id, std::move(timer))); | 47 popup_timers_.insert(std::make_pair(id, std::move(timer))); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void PopupTimersController::StartAll() { | 50 void PopupTimersController::StartAll() { |
| 51 for (const auto& iter : popup_timers_) | 51 for (const auto& iter : popup_timers_) |
| 52 iter.second->Start(); | 52 iter.second->Start(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void PopupTimersController::ResetTimer(const std::string& id, | |
| 56 const base::TimeDelta& timeout) { | |
| 57 CancelTimer(id); | |
| 58 StartTimer(id, timeout); | |
| 59 } | |
| 60 | |
| 61 void PopupTimersController::PauseTimer(const std::string& id) { | |
| 62 PopupTimerCollection::const_iterator iter = popup_timers_.find(id); | |
| 63 if (iter == popup_timers_.end()) | |
| 64 return; | |
| 65 iter->second->Pause(); | |
| 66 } | |
| 67 | |
| 68 void PopupTimersController::PauseAll() { | 55 void PopupTimersController::PauseAll() { |
| 69 for (const auto& iter : popup_timers_) | 56 for (const auto& iter : popup_timers_) |
| 70 iter.second->Pause(); | 57 iter.second->Pause(); |
| 71 } | 58 } |
| 72 | 59 |
| 73 void PopupTimersController::CancelTimer(const std::string& id) { | 60 void PopupTimersController::CancelTimer(const std::string& id) { |
| 74 popup_timers_.erase(id); | 61 popup_timers_.erase(id); |
| 75 } | 62 } |
| 76 | 63 |
| 77 void PopupTimersController::CancelAll() { | 64 void PopupTimersController::CancelAll() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 106 for (; iter != popup_notifications.end(); ++iter) { | 93 for (; iter != popup_notifications.end(); ++iter) { |
| 107 if ((*iter)->id() == id) | 94 if ((*iter)->id() == id) |
| 108 break; | 95 break; |
| 109 } | 96 } |
| 110 | 97 |
| 111 if (iter == popup_notifications.end() || (*iter)->never_timeout()) { | 98 if (iter == popup_notifications.end() || (*iter)->never_timeout()) { |
| 112 CancelTimer(id); | 99 CancelTimer(id); |
| 113 return; | 100 return; |
| 114 } | 101 } |
| 115 | 102 |
| 116 // Start the timer if not yet. | 103 CancelTimer(id); |
| 117 if (popup_timers_.find(id) == popup_timers_.end()) | 104 StartTimer(id, GetTimeoutForNotification(*iter)); |
| 118 StartTimer(id, GetTimeoutForNotification(*iter)); | |
| 119 } | 105 } |
| 120 | 106 |
| 121 void PopupTimersController::OnNotificationRemoved(const std::string& id, | 107 void PopupTimersController::OnNotificationRemoved(const std::string& id, |
| 122 bool by_user) { | 108 bool by_user) { |
| 123 CancelTimer(id); | 109 CancelTimer(id); |
| 124 } | 110 } |
| 125 | 111 |
| 126 } // namespace message_center | 112 } // namespace message_center |
| OLD | NEW |