Chromium Code Reviews| Index: chrome/browser/chromeos/system/automatic_reboot_manager.cc |
| diff --git a/chrome/browser/chromeos/system/automatic_reboot_manager.cc b/chrome/browser/chromeos/system/automatic_reboot_manager.cc |
| index b13db1ca7ea3a36e8640e387b6dc0d9b887a6cff..7e55ed48fda8e82d96665e831dcbfe9fed1d55d2 100644 |
| --- a/chrome/browser/chromeos/system/automatic_reboot_manager.cc |
| +++ b/chrome/browser/chromeos/system/automatic_reboot_manager.cc |
| @@ -33,6 +33,8 @@ |
| #include "base/time/tick_clock.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chromeos/login/user_manager.h" |
| +#include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: Not used.
xiyuan
2013/06/21 16:50:56
Done.
|
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/pref_names.h" |
| #include "chromeos/chromeos_paths.h" |
| @@ -194,6 +196,10 @@ AutomaticRebootManager::AutomaticRebootManager( |
| } |
| AutomaticRebootManager::~AutomaticRebootManager() { |
| + FOR_EACH_OBSERVER(AutomaticRebootManagerObserver, |
| + observers_, |
| + willShutdownAutomaticRebootManager()); |
| + |
| DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); |
| dbus_thread_manager->GetPowerManagerClient()->RemoveObserver(this); |
| dbus_thread_manager->GetUpdateEngineClient()->RemoveObserver(this); |
| @@ -201,6 +207,16 @@ AutomaticRebootManager::~AutomaticRebootManager() { |
| ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
| } |
| +void AutomaticRebootManager::AddObserver( |
| + AutomaticRebootManagerObserver* observer) { |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void AutomaticRebootManager::RemoveObserver( |
| + AutomaticRebootManagerObserver* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| void AutomaticRebootManager::SystemResumed( |
| const base::TimeDelta& sleep_duration) { |
| MaybeReboot(true); |
| @@ -303,6 +319,8 @@ void AutomaticRebootManager::Reschedule() { |
| reboot_requested_ = false; |
| const base::TimeDelta kZeroTimeDelta; |
| + AutomaticRebootManagerObserver::Reason reboot_reason = |
| + AutomaticRebootManagerObserver::REBOOT_REASON_UNKNOWN; |
| // If an uptime limit is set, calculate the time at which it should cause a |
| // reboot to be requested. |
| @@ -310,6 +328,8 @@ void AutomaticRebootManager::Reschedule() { |
| local_state_registrar_.prefs()->GetInteger(prefs::kUptimeLimit)); |
| base::TimeTicks reboot_request_time = boot_time_ + uptime_limit; |
| bool have_reboot_request_time = uptime_limit != kZeroTimeDelta; |
| + if (have_reboot_request_time) |
| + reboot_reason = AutomaticRebootManagerObserver::REBOOT_REASON_PERIODIC; |
| // If the policy to automatically reboot after an update is enabled and an |
| // update has been applied, set the time at which a reboot should be |
| @@ -321,6 +341,7 @@ void AutomaticRebootManager::Reschedule() { |
| update_reboot_needed_time_ < reboot_request_time)) { |
| reboot_request_time = update_reboot_needed_time_; |
| have_reboot_request_time = true; |
| + reboot_reason = AutomaticRebootManagerObserver::REBOOT_REASON_OS_UPDATE; |
| } |
| // If no reboot should be requested, remove any grace period. |
| @@ -355,6 +376,12 @@ void AutomaticRebootManager::Reschedule() { |
| std::max(grace_end_time - now, kZeroTimeDelta), |
| base::Bind(&AutomaticRebootManager::Reboot, |
| base::Unretained(this))); |
| + |
| + DCHECK_NE(AutomaticRebootManagerObserver::REBOOT_REASON_UNKNOWN, |
| + reboot_reason); |
| + FOR_EACH_OBSERVER(AutomaticRebootManagerObserver, |
| + observers_, |
| + OnRebootScheduled(reboot_reason)); |
| } |
| void AutomaticRebootManager::RequestReboot() { |