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..e287c3d9d5268f0ac2ca3b148af5276d470f0e23 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" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/pref_names.h" |
| #include "chromeos/chromeos_paths.h" |
| @@ -121,6 +123,8 @@ void SaveUpdateRebootNeededUptime() { |
| update_reboot_needed_uptime.size()); |
| } |
| +AutomaticRebootManager* instance = NULL; |
|
bartfab (slow)
2013/06/17 23:30:59
Instead of creating more singletons with implicit
xiyuan
2013/06/20 02:17:12
Done.
|
| + |
| } // namespace |
| AutomaticRebootManager::SystemEventTimes::SystemEventTimes() |
| @@ -153,6 +157,9 @@ AutomaticRebootManager::AutomaticRebootManager( |
| have_update_reboot_needed_time_(false), |
| reboot_requested_(false), |
| weak_ptr_factory_(this) { |
| + DCHECK(!instance); |
|
bartfab (slow)
2013/06/17 23:30:59
This would require #include <base/logging.h>. Howe
xiyuan
2013/06/20 02:17:12
Code removed.
|
| + instance = this; |
| + |
| local_state_registrar_.Init(g_browser_process->local_state()); |
| local_state_registrar_.Add(prefs::kUptimeLimit, |
| base::Bind(&AutomaticRebootManager::Reschedule, |
| @@ -194,6 +201,9 @@ AutomaticRebootManager::AutomaticRebootManager( |
| } |
| AutomaticRebootManager::~AutomaticRebootManager() { |
| + DCHECK(instance == this); |
|
bartfab (slow)
2013/06/17 23:30:59
Nit: DCHECK_EQ()
xiyuan
2013/06/20 02:17:12
Code removed.
|
| + instance = NULL; |
| + |
| DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); |
| dbus_thread_manager->GetPowerManagerClient()->RemoveObserver(this); |
| dbus_thread_manager->GetUpdateEngineClient()->RemoveObserver(this); |
| @@ -201,6 +211,20 @@ AutomaticRebootManager::~AutomaticRebootManager() { |
| ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
| } |
| +AutomaticRebootManager* AutomaticRebootManager::Get() { |
| + return instance; |
| +} |
| + |
| +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 +327,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 +336,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 +349,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 +384,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() { |