From ae0e25d6671def1a1a4ecf7536e55d3100027ce4 Mon Sep 17 00:00:00 2001 From: chirantan Date: Fri, 17 Jul 2015 11:27:58 -0700 Subject: Return early if an AlarmTimer is stopped when it is not running The AlarmTimer calls Stop() in its destructor. If it turns out that the AlarmTimer was created but never used, which can happen during tests, and the MessageLoop on which the AlarmTimer was created is not a MessageLoopForIO, then the Stop() function will end up creating a thread just to call Stop(). Instead, we can just return early from Stop() if the AlarmTimer isn't actually running. BUG=509138 Review URL: https://codereview.chromium.org/1237833004 Cr-Commit-Position: refs/heads/master@{#339287} --- components/timers/alarm_timer_chromeos.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'components') diff --git a/components/timers/alarm_timer_chromeos.cc b/components/timers/alarm_timer_chromeos.cc index ebef8ca..8797345 100644 --- a/components/timers/alarm_timer_chromeos.cc +++ b/components/timers/alarm_timer_chromeos.cc @@ -351,6 +351,9 @@ void AlarmTimer::Init() { } void AlarmTimer::Stop() { + if (!base::Timer::is_running()) + return; + if (!can_wake_from_suspend_) { base::Timer::Stop(); return; -- cgit v1.1