OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 void PopupTimer::Reset() { | 335 void PopupTimer::Reset() { |
336 if (timer_) | 336 if (timer_) |
337 timer_->Stop(); | 337 timer_->Stop(); |
338 passed_ = base::TimeDelta(); | 338 passed_ = base::TimeDelta(); |
339 } | 339 } |
340 | 340 |
341 //////////////////////////////////////////////////////////////////////////////// | 341 //////////////////////////////////////////////////////////////////////////////// |
342 // PopupTimersController | 342 // PopupTimersController |
343 | 343 |
344 PopupTimersController::PopupTimersController(MessageCenter* message_center) | 344 PopupTimersController::PopupTimersController(MessageCenter* message_center) |
345 : message_center_(message_center), popup_deleter_(&popup_timers_) { | 345 : message_center_(message_center) { |
346 message_center_->AddObserver(this); | 346 message_center_->AddObserver(this); |
347 } | 347 } |
348 | 348 |
349 PopupTimersController::~PopupTimersController() { | 349 PopupTimersController::~PopupTimersController() { |
350 message_center_->RemoveObserver(this); | 350 message_center_->RemoveObserver(this); |
351 } | 351 } |
352 | 352 |
353 void PopupTimersController::StartTimer(const std::string& id, | 353 void PopupTimersController::StartTimer(const std::string& id, |
354 const base::TimeDelta& timeout) { | 354 const base::TimeDelta& timeout) { |
355 PopupTimerCollection::iterator iter = popup_timers_.find(id); | 355 PopupTimerCollection::const_iterator iter = popup_timers_.find(id); |
356 if (iter != popup_timers_.end()) { | 356 if (iter != popup_timers_.end()) { |
357 DCHECK(iter->second); | 357 DCHECK(iter->second); |
358 iter->second->Start(); | 358 iter->second->Start(); |
359 return; | 359 return; |
360 } | 360 } |
361 | 361 |
362 PopupTimer* timer = new PopupTimer(id, timeout, AsWeakPtr()); | 362 scoped_ptr<PopupTimer> timer(new PopupTimer(id, timeout, AsWeakPtr())); |
363 | 363 |
364 timer->Start(); | 364 timer->Start(); |
365 popup_timers_[id] = timer; | 365 popup_timers_.insert(id, timer.Pass()); |
366 } | 366 } |
367 | 367 |
368 void PopupTimersController::StartAll() { | 368 void PopupTimersController::StartAll() { |
369 for (auto& iter : popup_timers_) | 369 for (auto& iter : popup_timers_) |
370 iter.second->Start(); | 370 iter.second->Start(); |
371 } | 371 } |
372 | 372 |
373 void PopupTimersController::ResetTimer(const std::string& id, | 373 void PopupTimersController::ResetTimer(const std::string& id, |
374 const base::TimeDelta& timeout) { | 374 const base::TimeDelta& timeout) { |
375 CancelTimer(id); | 375 CancelTimer(id); |
376 StartTimer(id, timeout); | 376 StartTimer(id, timeout); |
377 } | 377 } |
378 | 378 |
379 void PopupTimersController::PauseTimer(const std::string& id) { | 379 void PopupTimersController::PauseTimer(const std::string& id) { |
380 PopupTimerCollection::iterator iter = popup_timers_.find(id); | 380 PopupTimerCollection::const_iterator iter = popup_timers_.find(id); |
381 if (iter == popup_timers_.end()) | 381 if (iter == popup_timers_.end()) |
382 return; | 382 return; |
383 iter->second->Pause(); | 383 iter->second->Pause(); |
384 } | 384 } |
385 | 385 |
386 void PopupTimersController::PauseAll() { | 386 void PopupTimersController::PauseAll() { |
387 for (auto& iter : popup_timers_) | 387 for (auto& iter : popup_timers_) |
388 iter.second->Pause(); | 388 iter.second->Pause(); |
389 } | 389 } |
390 | 390 |
391 void PopupTimersController::CancelTimer(const std::string& id) { | 391 void PopupTimersController::CancelTimer(const std::string& id) { |
392 PopupTimerCollection::iterator iter = popup_timers_.find(id); | 392 popup_timers_.erase(id); |
393 if (iter == popup_timers_.end()) | |
394 return; | |
395 | |
396 delete iter->second; | |
397 popup_timers_.erase(iter); | |
398 } | 393 } |
399 | 394 |
400 void PopupTimersController::CancelAll() { | 395 void PopupTimersController::CancelAll() { |
401 STLDeleteValues(&popup_timers_); | 396 popup_timers_.clear(); |
402 } | 397 } |
403 | 398 |
404 void PopupTimersController::TimerFinished(const std::string& id) { | 399 void PopupTimersController::TimerFinished(const std::string& id) { |
405 if (!ContainsKey(popup_timers_, id)) | 400 if (!ContainsKey(popup_timers_, id)) |
406 return; | 401 return; |
407 | 402 |
408 CancelTimer(id); | 403 CancelTimer(id); |
409 message_center_->MarkSinglePopupAsShown(id, false); | 404 message_center_->MarkSinglePopupAsShown(id, false); |
410 } | 405 } |
411 | 406 |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 void MessageCenterImpl::PausePopupTimers() { | 934 void MessageCenterImpl::PausePopupTimers() { |
940 if (popup_timers_controller_) | 935 if (popup_timers_controller_) |
941 popup_timers_controller_->PauseAll(); | 936 popup_timers_controller_->PauseAll(); |
942 } | 937 } |
943 | 938 |
944 void MessageCenterImpl::DisableTimersForTest() { | 939 void MessageCenterImpl::DisableTimersForTest() { |
945 popup_timers_controller_.reset(); | 940 popup_timers_controller_.reset(); |
946 } | 941 } |
947 | 942 |
948 } // namespace message_center | 943 } // namespace message_center |
OLD | NEW |