| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 164 notification_registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 165 content::NotificationService::AllSources()); | 165 content::NotificationService::AllSources()); |
| 166 | 166 |
| 167 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); | 167 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); |
| 168 dbus_thread_manager->GetPowerManagerClient()->AddObserver(this); | 168 dbus_thread_manager->GetPowerManagerClient()->AddObserver(this); |
| 169 dbus_thread_manager->GetUpdateEngineClient()->AddObserver(this); | 169 dbus_thread_manager->GetUpdateEngineClient()->AddObserver(this); |
| 170 | 170 |
| 171 // If no user is logged in, a reboot may be performed whenever the user is | 171 // If no user is logged in, a reboot may be performed whenever the user is |
| 172 // idle. Start listening for user activity to determine whether the user is | 172 // idle. Start listening for user activity to determine whether the user is |
| 173 // idle or not. | 173 // idle or not. |
| 174 if (!UserManager::Get()->IsUserLoggedIn()) { | 174 if (!GetUserManager()->IsUserLoggedIn()) { |
| 175 if (ash::Shell::HasInstance()) | 175 if (ash::Shell::HasInstance()) |
| 176 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); | 176 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); |
| 177 notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 177 notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 178 content::NotificationService::AllSources()); | 178 content::NotificationService::AllSources()); |
| 179 login_screen_idle_timer_.reset( | 179 login_screen_idle_timer_.reset( |
| 180 new base::OneShotTimer<AutomaticRebootManager>); | 180 new base::OneShotTimer<AutomaticRebootManager>); |
| 181 OnUserActivity(NULL); | 181 OnUserActivity(NULL); |
| 182 } | 182 } |
| 183 | 183 |
| 184 // In a regular browser, base::ThreadTaskRunnerHandle::Get() and | 184 // In a regular browser, base::ThreadTaskRunnerHandle::Get() and |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 base::Bind(&AutomaticRebootManager::MaybeReboot, | 255 base::Bind(&AutomaticRebootManager::MaybeReboot, |
| 256 base::Unretained(this), | 256 base::Unretained(this), |
| 257 false)); | 257 false)); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void AutomaticRebootManager::Observe( | 260 void AutomaticRebootManager::Observe( |
| 261 int type, | 261 int type, |
| 262 const content::NotificationSource& source, | 262 const content::NotificationSource& source, |
| 263 const content::NotificationDetails& details) { | 263 const content::NotificationDetails& details) { |
| 264 if (type == chrome::NOTIFICATION_APP_TERMINATING) { | 264 if (type == chrome::NOTIFICATION_APP_TERMINATING) { |
| 265 if (UserManager::Get()->IsUserLoggedIn()) { | 265 if (GetUserManager()->IsUserLoggedIn()) { |
| 266 // The browser is terminating during a session, either because the session | 266 // The browser is terminating during a session, either because the session |
| 267 // is ending or because the browser is being restarted. | 267 // is ending or because the browser is being restarted. |
| 268 MaybeReboot(true); | 268 MaybeReboot(true); |
| 269 } | 269 } |
| 270 } else if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { | 270 } else if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { |
| 271 // A session is starting. Stop listening for user activity as it no longer | 271 // A session is starting. Stop listening for user activity as it no longer |
| 272 // is a relevant criterion. | 272 // is a relevant criterion. |
| 273 if (ash::Shell::HasInstance()) | 273 if (ash::Shell::HasInstance()) |
| 274 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 274 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
| 275 notification_registrar_.Remove( | 275 notification_registrar_.Remove( |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 MaybeReboot(false); | 388 MaybeReboot(false); |
| 389 } | 389 } |
| 390 | 390 |
| 391 void AutomaticRebootManager::MaybeReboot(bool ignore_session) { | 391 void AutomaticRebootManager::MaybeReboot(bool ignore_session) { |
| 392 // Do not reboot if any of the following applies: | 392 // Do not reboot if any of the following applies: |
| 393 // * No reboot has been requested. | 393 // * No reboot has been requested. |
| 394 // * A user is interacting with the login screen. | 394 // * A user is interacting with the login screen. |
| 395 // * A session is in progress and |ignore_session| is not set. | 395 // * A session is in progress and |ignore_session| is not set. |
| 396 if (!reboot_requested_ || | 396 if (!reboot_requested_ || |
| 397 (login_screen_idle_timer_ && login_screen_idle_timer_->IsRunning()) || | 397 (login_screen_idle_timer_ && login_screen_idle_timer_->IsRunning()) || |
| 398 (!ignore_session && UserManager::Get()->IsUserLoggedIn())) { | 398 (!ignore_session && GetUserManager()->IsUserLoggedIn())) { |
| 399 return; | 399 return; |
| 400 } | 400 } |
| 401 | 401 |
| 402 Reboot(); | 402 Reboot(); |
| 403 } | 403 } |
| 404 | 404 |
| 405 void AutomaticRebootManager::Reboot() { | 405 void AutomaticRebootManager::Reboot() { |
| 406 // If a non-kiosk-app session is in progress, do not reboot. | 406 // If a non-kiosk-app session is in progress, do not reboot. |
| 407 if (UserManager::Get()->IsUserLoggedIn() && | 407 if (GetUserManager()->IsUserLoggedIn() && |
| 408 !UserManager::Get()->IsLoggedInAsKioskApp()) { | 408 !GetUserManager()->IsLoggedInAsKioskApp()) { |
| 409 return; | 409 return; |
| 410 } | 410 } |
| 411 | 411 |
| 412 login_screen_idle_timer_.reset(); | 412 login_screen_idle_timer_.reset(); |
| 413 grace_start_timer_.reset(); | 413 grace_start_timer_.reset(); |
| 414 grace_end_timer_.reset(); | 414 grace_end_timer_.reset(); |
| 415 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 415 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); |
| 416 } | 416 } |
| 417 | 417 |
| 418 } // namespace system | 418 } // namespace system |
| 419 } // namespace chromeos | 419 } // namespace chromeos |
| OLD | NEW |