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 "chrome/browser/chromeos/system/automatic_reboot_manager.h" | 5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 | 10 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 dbus_thread_manager->GetUpdateEngineClient()->AddObserver(this); | 171 dbus_thread_manager->GetUpdateEngineClient()->AddObserver(this); |
172 | 172 |
173 // If no user is logged in, a reboot may be performed whenever the user is | 173 // If no user is logged in, a reboot may be performed whenever the user is |
174 // idle. Start listening for user activity to determine whether the user is | 174 // idle. Start listening for user activity to determine whether the user is |
175 // idle or not. | 175 // idle or not. |
176 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) { | 176 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) { |
177 if (ui::UserActivityDetector::Get()) | 177 if (ui::UserActivityDetector::Get()) |
178 ui::UserActivityDetector::Get()->AddObserver(this); | 178 ui::UserActivityDetector::Get()->AddObserver(this); |
179 notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 179 notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
180 content::NotificationService::AllSources()); | 180 content::NotificationService::AllSources()); |
181 login_screen_idle_timer_.reset( | 181 login_screen_idle_timer_.reset(new base::OneShotTimer); |
182 new base::OneShotTimer<AutomaticRebootManager>); | |
183 OnUserActivity(NULL); | 182 OnUserActivity(NULL); |
184 } | 183 } |
185 | 184 |
186 // In a regular browser, base::ThreadTaskRunnerHandle::Get() and | 185 // In a regular browser, base::ThreadTaskRunnerHandle::Get() and |
187 // base::ThreadTaskRunnerHandle::Get() return pointers to the same object. | 186 // base::ThreadTaskRunnerHandle::Get() return pointers to the same object. |
188 // In unit tests, using base::ThreadTaskRunnerHandle::Get() has the advantage | 187 // In unit tests, using base::ThreadTaskRunnerHandle::Get() has the advantage |
189 // that it allows a custom base::SingleThreadTaskRunner to be injected. | 188 // that it allows a custom base::SingleThreadTaskRunner to be injected. |
190 base::SequencedWorkerPool* worker_pool = | 189 base::SequencedWorkerPool* worker_pool = |
191 content::BrowserThread::GetBlockingPool(); | 190 content::BrowserThread::GetBlockingPool(); |
192 worker_pool->PostSequencedWorkerTaskWithShutdownBehavior( | 191 worker_pool->PostSequencedWorkerTaskWithShutdownBehavior( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 Reschedule(); | 244 Reschedule(); |
246 } | 245 } |
247 | 246 |
248 void AutomaticRebootManager::OnUserActivity(const ui::Event* event) { | 247 void AutomaticRebootManager::OnUserActivity(const ui::Event* event) { |
249 if (!login_screen_idle_timer_) | 248 if (!login_screen_idle_timer_) |
250 return; | 249 return; |
251 | 250 |
252 // Destroying and re-creating the timer ensures that Start() posts a fresh | 251 // Destroying and re-creating the timer ensures that Start() posts a fresh |
253 // task with a delay of exactly |kLoginManagerIdleTimeoutMs|, ensuring that | 252 // task with a delay of exactly |kLoginManagerIdleTimeoutMs|, ensuring that |
254 // the timer fires predictably in tests. | 253 // the timer fires predictably in tests. |
255 login_screen_idle_timer_.reset( | 254 login_screen_idle_timer_.reset(new base::OneShotTimer); |
256 new base::OneShotTimer<AutomaticRebootManager>); | |
257 login_screen_idle_timer_->Start( | 255 login_screen_idle_timer_->Start( |
258 FROM_HERE, | 256 FROM_HERE, |
259 base::TimeDelta::FromMilliseconds(kLoginManagerIdleTimeoutMs), | 257 base::TimeDelta::FromMilliseconds(kLoginManagerIdleTimeoutMs), |
260 base::Bind(&AutomaticRebootManager::MaybeReboot, | 258 base::Bind(&AutomaticRebootManager::MaybeReboot, |
261 base::Unretained(this), | 259 base::Unretained(this), |
262 false)); | 260 false)); |
263 } | 261 } |
264 | 262 |
265 void AutomaticRebootManager::Observe( | 263 void AutomaticRebootManager::Observe( |
266 int type, | 264 int type, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 // Safeguard against reboot loops: Ensure that the uptime after which a reboot | 354 // Safeguard against reboot loops: Ensure that the uptime after which a reboot |
357 // is actually requested and the grace period begins is never less than | 355 // is actually requested and the grace period begins is never less than |
358 // |kMinRebootUptimeMs|. | 356 // |kMinRebootUptimeMs|. |
359 const base::TimeTicks now = clock_->NowTicks(); | 357 const base::TimeTicks now = clock_->NowTicks(); |
360 const base::TimeTicks grace_start_time = std::max(reboot_request_time, | 358 const base::TimeTicks grace_start_time = std::max(reboot_request_time, |
361 boot_time_ + base::TimeDelta::FromMilliseconds(kMinRebootUptimeMs)); | 359 boot_time_ + base::TimeDelta::FromMilliseconds(kMinRebootUptimeMs)); |
362 | 360 |
363 // Set up a timer for the start of the grace period. If the grace period | 361 // Set up a timer for the start of the grace period. If the grace period |
364 // started in the past, the timer is still used with its delay set to zero. | 362 // started in the past, the timer is still used with its delay set to zero. |
365 if (!grace_start_timer_) | 363 if (!grace_start_timer_) |
366 grace_start_timer_.reset(new base::OneShotTimer<AutomaticRebootManager>); | 364 grace_start_timer_.reset(new base::OneShotTimer); |
367 grace_start_timer_->Start(FROM_HERE, | 365 grace_start_timer_->Start(FROM_HERE, |
368 std::max(grace_start_time - now, kZeroTimeDelta), | 366 std::max(grace_start_time - now, kZeroTimeDelta), |
369 base::Bind(&AutomaticRebootManager::RequestReboot, | 367 base::Bind(&AutomaticRebootManager::RequestReboot, |
370 base::Unretained(this))); | 368 base::Unretained(this))); |
371 | 369 |
372 const base::TimeTicks grace_end_time = grace_start_time + | 370 const base::TimeTicks grace_end_time = grace_start_time + |
373 base::TimeDelta::FromMilliseconds(kGracePeriodMs); | 371 base::TimeDelta::FromMilliseconds(kGracePeriodMs); |
374 // Set up a timer for the end of the grace period. If the grace period ended | 372 // Set up a timer for the end of the grace period. If the grace period ended |
375 // in the past, the timer is still used with its delay set to zero. | 373 // in the past, the timer is still used with its delay set to zero. |
376 if (!grace_end_timer_) | 374 if (!grace_end_timer_) |
377 grace_end_timer_.reset(new base::OneShotTimer<AutomaticRebootManager>); | 375 grace_end_timer_.reset(new base::OneShotTimer); |
378 grace_end_timer_->Start(FROM_HERE, | 376 grace_end_timer_->Start(FROM_HERE, |
379 std::max(grace_end_time - now, kZeroTimeDelta), | 377 std::max(grace_end_time - now, kZeroTimeDelta), |
380 base::Bind(&AutomaticRebootManager::Reboot, | 378 base::Bind(&AutomaticRebootManager::Reboot, |
381 base::Unretained(this))); | 379 base::Unretained(this))); |
382 } | 380 } |
383 | 381 |
384 void AutomaticRebootManager::RequestReboot() { | 382 void AutomaticRebootManager::RequestReboot() { |
385 reboot_requested_ = true; | 383 reboot_requested_ = true; |
386 DCHECK_NE(AutomaticRebootManagerObserver::REBOOT_REASON_UNKNOWN, | 384 DCHECK_NE(AutomaticRebootManagerObserver::REBOOT_REASON_UNKNOWN, |
387 reboot_reason_); | 385 reboot_reason_); |
(...skipping 25 matching lines...) Expand all Loading... |
413 } | 411 } |
414 | 412 |
415 login_screen_idle_timer_.reset(); | 413 login_screen_idle_timer_.reset(); |
416 grace_start_timer_.reset(); | 414 grace_start_timer_.reset(); |
417 grace_end_timer_.reset(); | 415 grace_end_timer_.reset(); |
418 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 416 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
419 } | 417 } |
420 | 418 |
421 } // namespace system | 419 } // namespace system |
422 } // namespace chromeos | 420 } // namespace chromeos |
OLD | NEW |