| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/timers/alarm_timer_chromeos.h" | 5 #include "components/timers/alarm_timer_chromeos.h" |
| 6 | 6 |
| 7 #include <sys/timerfd.h> | 7 #include <sys/timerfd.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/pending_task.h" | 16 #include "base/pending_task.h" |
| 17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 19 #include "base/trace_event/trace_event.h" |
| 19 | 20 |
| 20 namespace timers { | 21 namespace timers { |
| 21 namespace { | 22 namespace { |
| 22 // This class represents the IO thread that the AlarmTimer::Delegate may use for | 23 // This class represents the IO thread that the AlarmTimer::Delegate may use for |
| 23 // watching file descriptors if it gets called from a thread that does not have | 24 // watching file descriptors if it gets called from a thread that does not have |
| 24 // a MessageLoopForIO. It is a lazy global instance because it may not always | 25 // a MessageLoopForIO. It is a lazy global instance because it may not always |
| 25 // be necessary. | 26 // be necessary. |
| 26 class RtcAlarmIOThread : public base::Thread { | 27 class RtcAlarmIOThread : public base::Thread { |
| 27 public: | 28 public: |
| 28 RtcAlarmIOThread() : Thread("RTC Alarm IO Thread") { | 29 RtcAlarmIOThread() : Thread("RTC Alarm IO Thread") { |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 // Take ownership of the pending user task, which is going to be cleared by | 422 // Take ownership of the pending user task, which is going to be cleared by |
| 422 // the Stop() or Reset() functions below. | 423 // the Stop() or Reset() functions below. |
| 423 scoped_ptr<base::PendingTask> pending_user_task(pending_task_.Pass()); | 424 scoped_ptr<base::PendingTask> pending_user_task(pending_task_.Pass()); |
| 424 | 425 |
| 425 // Re-schedule or stop the timer as requested. | 426 // Re-schedule or stop the timer as requested. |
| 426 if (base::Timer::is_repeating()) | 427 if (base::Timer::is_repeating()) |
| 427 Reset(); | 428 Reset(); |
| 428 else | 429 else |
| 429 Stop(); | 430 Stop(); |
| 430 | 431 |
| 432 TRACE_TASK_EXECUTION("AlarmTimer::OnTimerFired", *pending_user_task); |
| 433 |
| 431 // Now run the user task. | 434 // Now run the user task. |
| 432 base::MessageLoop::current()->task_annotator()->RunTask( | 435 base::MessageLoop::current()->task_annotator()->RunTask("AlarmTimer::Reset", |
| 433 "AlarmTimer::Reset", "AlarmTimer::OnTimerFired", *pending_user_task); | 436 *pending_user_task); |
| 434 } | 437 } |
| 435 | 438 |
| 436 OneShotAlarmTimer::OneShotAlarmTimer() : AlarmTimer(false, false) { | 439 OneShotAlarmTimer::OneShotAlarmTimer() : AlarmTimer(false, false) { |
| 437 } | 440 } |
| 438 | 441 |
| 439 OneShotAlarmTimer::~OneShotAlarmTimer() { | 442 OneShotAlarmTimer::~OneShotAlarmTimer() { |
| 440 } | 443 } |
| 441 | 444 |
| 442 RepeatingAlarmTimer::RepeatingAlarmTimer() : AlarmTimer(true, true) { | 445 RepeatingAlarmTimer::RepeatingAlarmTimer() : AlarmTimer(true, true) { |
| 443 } | 446 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 458 SimpleAlarmTimer::SimpleAlarmTimer(const tracked_objects::Location& posted_from, | 461 SimpleAlarmTimer::SimpleAlarmTimer(const tracked_objects::Location& posted_from, |
| 459 base::TimeDelta delay, | 462 base::TimeDelta delay, |
| 460 const base::Closure& user_task) | 463 const base::Closure& user_task) |
| 461 : AlarmTimer(posted_from, delay, user_task, false) { | 464 : AlarmTimer(posted_from, delay, user_task, false) { |
| 462 } | 465 } |
| 463 | 466 |
| 464 SimpleAlarmTimer::~SimpleAlarmTimer() { | 467 SimpleAlarmTimer::~SimpleAlarmTimer() { |
| 465 } | 468 } |
| 466 | 469 |
| 467 } // namespace timers | 470 } // namespace timers |
| OLD | NEW |