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 "base/stl_util.h" |
9 #include "ui/message_center/message_center_style.h" | 10 #include "ui/message_center/message_center_style.h" |
10 #include "ui/message_center/message_center_types.h" | 11 #include "ui/message_center/message_center_types.h" |
11 #include "ui/message_center/notification.h" | 12 #include "ui/message_center/notification.h" |
12 #include "ui/message_center/notification_list.h" | 13 #include "ui/message_center/notification_list.h" |
13 | 14 |
14 namespace message_center { | 15 namespace message_center { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 base::TimeDelta GetTimeoutForNotification(Notification* notification) { | 19 base::TimeDelta GetTimeoutForNotification(Notification* notification) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 PopupTimerCollection::const_iterator iter = popup_timers_.find(id); | 87 PopupTimerCollection::const_iterator iter = popup_timers_.find(id); |
87 if (iter != popup_timers_.end()) { | 88 if (iter != popup_timers_.end()) { |
88 DCHECK(iter->second); | 89 DCHECK(iter->second); |
89 iter->second->Start(); | 90 iter->second->Start(); |
90 return; | 91 return; |
91 } | 92 } |
92 | 93 |
93 scoped_ptr<PopupTimer> timer(new PopupTimer(id, timeout, AsWeakPtr())); | 94 scoped_ptr<PopupTimer> timer(new PopupTimer(id, timeout, AsWeakPtr())); |
94 | 95 |
95 timer->Start(); | 96 timer->Start(); |
96 popup_timers_.insert(id, timer.Pass()); | 97 popup_timers_.insert(std::make_pair(id, std::move(timer))); |
97 } | 98 } |
98 | 99 |
99 void PopupTimersController::StartAll() { | 100 void PopupTimersController::StartAll() { |
100 for (auto& iter : popup_timers_) | 101 for (const auto& iter : popup_timers_) |
101 iter.second->Start(); | 102 iter.second->Start(); |
102 } | 103 } |
103 | 104 |
104 void PopupTimersController::ResetTimer(const std::string& id, | 105 void PopupTimersController::ResetTimer(const std::string& id, |
105 const base::TimeDelta& timeout) { | 106 const base::TimeDelta& timeout) { |
106 CancelTimer(id); | 107 CancelTimer(id); |
107 StartTimer(id, timeout); | 108 StartTimer(id, timeout); |
108 } | 109 } |
109 | 110 |
110 void PopupTimersController::PauseTimer(const std::string& id) { | 111 void PopupTimersController::PauseTimer(const std::string& id) { |
111 PopupTimerCollection::const_iterator iter = popup_timers_.find(id); | 112 PopupTimerCollection::const_iterator iter = popup_timers_.find(id); |
112 if (iter == popup_timers_.end()) | 113 if (iter == popup_timers_.end()) |
113 return; | 114 return; |
114 iter->second->Pause(); | 115 iter->second->Pause(); |
115 } | 116 } |
116 | 117 |
117 void PopupTimersController::PauseAll() { | 118 void PopupTimersController::PauseAll() { |
118 for (auto& iter : popup_timers_) | 119 for (const auto& iter : popup_timers_) |
119 iter.second->Pause(); | 120 iter.second->Pause(); |
120 } | 121 } |
121 | 122 |
122 void PopupTimersController::CancelTimer(const std::string& id) { | 123 void PopupTimersController::CancelTimer(const std::string& id) { |
123 popup_timers_.erase(id); | 124 popup_timers_.erase(id); |
124 } | 125 } |
125 | 126 |
126 void PopupTimersController::CancelAll() { | 127 void PopupTimersController::CancelAll() { |
127 popup_timers_.clear(); | 128 popup_timers_.clear(); |
128 } | 129 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 if (popup_timers_.find(id) == popup_timers_.end()) | 167 if (popup_timers_.find(id) == popup_timers_.end()) |
167 StartTimer(id, GetTimeoutForNotification(*iter)); | 168 StartTimer(id, GetTimeoutForNotification(*iter)); |
168 } | 169 } |
169 | 170 |
170 void PopupTimersController::OnNotificationRemoved(const std::string& id, | 171 void PopupTimersController::OnNotificationRemoved(const std::string& id, |
171 bool by_user) { | 172 bool by_user) { |
172 CancelTimer(id); | 173 CancelTimer(id); |
173 } | 174 } |
174 | 175 |
175 } // namespace message_center | 176 } // namespace message_center |
OLD | NEW |