Chromium Code Reviews| Index: chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc |
| diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc b/chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc |
| index 0b789f9062236c74140938f249477d0a1dde24d0..1e8fae0d32b9641952b53d288630a4b79173e437 100644 |
| --- a/chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc |
| +++ b/chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc |
| @@ -6,6 +6,10 @@ |
| #include "base/logging.h" |
| #include "chrome/browser/app_mode/app_mode_utils.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/browser_process_platform_part_chromeos.h" |
| +#include "chrome/browser/chromeos/system/automatic_reboot_manager.h" |
| +#include "chrome/browser/extensions/api/runtime/runtime_api.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/extensions/extension_system.h" |
| #include "chrome/browser/extensions/extension_system_factory.h" |
| @@ -22,17 +26,43 @@ const int kForceRestartWaitTimeMs = 24 * 3600 * 1000; // 24 hours. |
| } // namespace |
| -KioskAppUpdateService::KioskAppUpdateService(Profile* profile) |
| - : profile_(profile) { |
| +KioskAppUpdateService::KioskAppUpdateService( |
| + Profile* profile, |
| + system::AutomaticRebootManager* automatic_reboot_manager) |
| + : profile_(profile), |
| + automatic_reboot_manager_(automatic_reboot_manager) { |
| ExtensionService* service = |
| extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| if (service) |
| service->AddUpdateObserver(this); |
| + |
| + if (automatic_reboot_manager_) |
| + automatic_reboot_manager_->AddObserver(this); |
| } |
| KioskAppUpdateService::~KioskAppUpdateService() { |
| } |
| +void KioskAppUpdateService::StartRestartTimer() { |
| + if (restart_timer_.IsRunning()) |
| + return; |
| + |
| + // Setup timer to force restart once the wait period expires. |
| + restart_timer_.Start( |
| + FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), |
| + this, &KioskAppUpdateService::ForceRestart); |
| +} |
| + |
| +void KioskAppUpdateService::ForceRestart() { |
| + // This method is invoked after the app update grace period has passed. |
|
bartfab (slow)
2013/06/21 18:18:13
Nit: "after the app update grace period" is still
xiyuan
2013/06/21 18:33:18
The timer in this class is only started for app up
bartfab (slow)
2013/06/21 18:47:09
Makes sense. But in that case, the comment changes
xiyuan
2013/06/21 19:07:05
Restored.
StartRestartTimer -> StartAppUpdateRest
|
| + // However, depending on what is pending (app update, OS update or periodic |
| + // reboot), it will cause either a browser restart or a device restart. |
| + LOG(WARNING) << "Closing all browsers. Depends on the pending restart " |
|
bartfab (slow)
2013/06/21 18:18:13
Nit: s/Depends/Depending/
xiyuan
2013/06/21 18:33:18
Done.
|
| + "signal, either a browser restart or a device restart will " |
| + "happen."; |
| + chrome::CloseAllBrowsers(); |
| +} |
| + |
| void KioskAppUpdateService::Shutdown() { |
| ExtensionService* service = profile_->GetExtensionService(); |
| if (service) |
| @@ -44,23 +74,36 @@ void KioskAppUpdateService::OnAppUpdateAvailable(const std::string& app_id) { |
| if (app_id != app_id_) |
| return; |
| + extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| + profile_, |
| + app_id_, |
| + extensions::RuntimeEventRouter::RESTART_REASON_APP_UPDATE); |
| + |
| StartRestartTimer(); |
| } |
| -void KioskAppUpdateService::StartRestartTimer() { |
| - if (restart_timer_.IsRunning()) |
| - return; |
| - |
| - // Setup timer to force restart once the wait period expires. |
| - restart_timer_.Start( |
| - FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), |
| - this, &KioskAppUpdateService::ForceRestart); |
| +void KioskAppUpdateService::OnRebootScheduled(Reason reason) { |
| + extensions::RuntimeEventRouter::RestartReason restart_reason = |
| + extensions::RuntimeEventRouter::RESTART_REASON_UNKNOWN; |
| + switch (reason) { |
| + case REBOOT_REASON_OS_UPDATE: |
| + restart_reason = extensions::RuntimeEventRouter::RESTART_REASON_OS_UPDATE; |
| + break; |
| + case REBOOT_REASON_PERIODIC: |
| + restart_reason = extensions::RuntimeEventRouter::RESTART_REASON_PERIODIC; |
| + break; |
| + default: |
| + NOTREACHED() << "Unknown reboot reason=" << reason; |
| + return; |
| + } |
| + |
| + extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| + profile_, app_id_, restart_reason); |
| } |
| -void KioskAppUpdateService::ForceRestart() { |
| - // Force a chrome restart (not a logout or reboot) by closing all browsers. |
| - LOG(WARNING) << "Force closing all browsers to update kiosk app."; |
| - chrome::CloseAllBrowsers(); |
| +void KioskAppUpdateService::WillDestroyAutomaticRebootManager() { |
| + automatic_reboot_manager_->RemoveObserver(this); |
| + automatic_reboot_manager_ = NULL; |
| } |
| KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory() |
| @@ -92,8 +135,10 @@ KioskAppUpdateServiceFactory* KioskAppUpdateServiceFactory::GetInstance() { |
| BrowserContextKeyedService* |
| KioskAppUpdateServiceFactory::BuildServiceInstanceFor( |
| - content::BrowserContext* profile) const { |
| - return new KioskAppUpdateService(static_cast<Profile*>(profile)); |
| + content::BrowserContext* context) const { |
| + return new KioskAppUpdateService( |
| + Profile::FromBrowserContext(context), |
| + g_browser_process->platform_part()->automatic_reboot_manager()); |
| } |
| } // namespace chromeos |