Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/app_mode/kiosk_app_update_service.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_update_service.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/app_mode/app_mode_utils.h" | 8 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/browser_process_platform_part_chromeos.h" | |
| 11 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" | |
| 12 #include "chrome/browser/extensions/api/runtime/runtime_api.h" | |
| 9 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
| 11 #include "chrome/browser/extensions/extension_system_factory.h" | 15 #include "chrome/browser/extensions/extension_system_factory.h" |
| 12 #include "chrome/browser/lifetime/application_lifetime.h" | 16 #include "chrome/browser/lifetime/application_lifetime.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 14 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 18 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" |
| 15 | 19 |
| 16 namespace chromeos { | 20 namespace chromeos { |
| 17 | 21 |
| 18 namespace { | 22 namespace { |
| 19 | 23 |
| 20 // How low to wait after an update is available before we force a restart. | 24 // How low to wait after an update is available before we force a restart. |
| 21 const int kForceRestartWaitTimeMs = 24 * 3600 * 1000; // 24 hours. | 25 const int kForceRestartWaitTimeMs = 24 * 3600 * 1000; // 24 hours. |
| 22 | 26 |
| 23 } // namespace | 27 } // namespace |
| 24 | 28 |
| 25 KioskAppUpdateService::KioskAppUpdateService(Profile* profile) | 29 KioskAppUpdateService::KioskAppUpdateService( |
| 26 : profile_(profile) { | 30 Profile* profile, |
| 31 system::AutomaticRebootManager* automatic_reboot_manager) | |
| 32 : profile_(profile), | |
| 33 automatic_reboot_manager_(automatic_reboot_manager) { | |
| 27 ExtensionService* service = | 34 ExtensionService* service = |
| 28 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 35 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 29 if (service) | 36 if (service) |
| 30 service->AddUpdateObserver(this); | 37 service->AddUpdateObserver(this); |
| 38 | |
| 39 if (automatic_reboot_manager_) | |
| 40 automatic_reboot_manager_->AddObserver(this); | |
| 31 } | 41 } |
| 32 | 42 |
| 33 KioskAppUpdateService::~KioskAppUpdateService() { | 43 KioskAppUpdateService::~KioskAppUpdateService() { |
| 34 } | 44 } |
| 35 | 45 |
| 46 void KioskAppUpdateService::StartRestartTimer() { | |
| 47 if (restart_timer_.IsRunning()) | |
| 48 return; | |
| 49 | |
| 50 // Setup timer to force restart once the wait period expires. | |
| 51 restart_timer_.Start( | |
| 52 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), | |
| 53 this, &KioskAppUpdateService::ForceRestart); | |
| 54 } | |
| 55 | |
| 56 void KioskAppUpdateService::ForceRestart() { | |
| 57 // 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
| |
| 58 // However, depending on what is pending (app update, OS update or periodic | |
| 59 // reboot), it will cause either a browser restart or a device restart. | |
| 60 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.
| |
| 61 "signal, either a browser restart or a device restart will " | |
| 62 "happen."; | |
| 63 chrome::CloseAllBrowsers(); | |
| 64 } | |
| 65 | |
| 36 void KioskAppUpdateService::Shutdown() { | 66 void KioskAppUpdateService::Shutdown() { |
| 37 ExtensionService* service = profile_->GetExtensionService(); | 67 ExtensionService* service = profile_->GetExtensionService(); |
| 38 if (service) | 68 if (service) |
| 39 service->RemoveUpdateObserver(this); | 69 service->RemoveUpdateObserver(this); |
| 40 } | 70 } |
| 41 | 71 |
| 42 void KioskAppUpdateService::OnAppUpdateAvailable(const std::string& app_id) { | 72 void KioskAppUpdateService::OnAppUpdateAvailable(const std::string& app_id) { |
| 43 DCHECK(!app_id_.empty()); | 73 DCHECK(!app_id_.empty()); |
| 44 if (app_id != app_id_) | 74 if (app_id != app_id_) |
| 45 return; | 75 return; |
| 46 | 76 |
| 77 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( | |
| 78 profile_, | |
| 79 app_id_, | |
| 80 extensions::RuntimeEventRouter::RESTART_REASON_APP_UPDATE); | |
| 81 | |
| 47 StartRestartTimer(); | 82 StartRestartTimer(); |
| 48 } | 83 } |
| 49 | 84 |
| 50 void KioskAppUpdateService::StartRestartTimer() { | 85 void KioskAppUpdateService::OnRebootScheduled(Reason reason) { |
| 51 if (restart_timer_.IsRunning()) | 86 extensions::RuntimeEventRouter::RestartReason restart_reason = |
| 52 return; | 87 extensions::RuntimeEventRouter::RESTART_REASON_UNKNOWN; |
| 88 switch (reason) { | |
| 89 case REBOOT_REASON_OS_UPDATE: | |
| 90 restart_reason = extensions::RuntimeEventRouter::RESTART_REASON_OS_UPDATE; | |
| 91 break; | |
| 92 case REBOOT_REASON_PERIODIC: | |
| 93 restart_reason = extensions::RuntimeEventRouter::RESTART_REASON_PERIODIC; | |
| 94 break; | |
| 95 default: | |
| 96 NOTREACHED() << "Unknown reboot reason=" << reason; | |
| 97 return; | |
| 98 } | |
| 53 | 99 |
| 54 // Setup timer to force restart once the wait period expires. | 100 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 55 restart_timer_.Start( | 101 profile_, app_id_, restart_reason); |
| 56 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), | |
| 57 this, &KioskAppUpdateService::ForceRestart); | |
| 58 } | 102 } |
| 59 | 103 |
| 60 void KioskAppUpdateService::ForceRestart() { | 104 void KioskAppUpdateService::WillDestroyAutomaticRebootManager() { |
| 61 // Force a chrome restart (not a logout or reboot) by closing all browsers. | 105 automatic_reboot_manager_->RemoveObserver(this); |
| 62 LOG(WARNING) << "Force closing all browsers to update kiosk app."; | 106 automatic_reboot_manager_ = NULL; |
| 63 chrome::CloseAllBrowsers(); | |
| 64 } | 107 } |
| 65 | 108 |
| 66 KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory() | 109 KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory() |
| 67 : BrowserContextKeyedServiceFactory( | 110 : BrowserContextKeyedServiceFactory( |
| 68 "KioskAppUpdateService", | 111 "KioskAppUpdateService", |
| 69 BrowserContextDependencyManager::GetInstance()) { | 112 BrowserContextDependencyManager::GetInstance()) { |
| 70 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); | 113 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); |
| 71 } | 114 } |
| 72 | 115 |
| 73 KioskAppUpdateServiceFactory::~KioskAppUpdateServiceFactory() { | 116 KioskAppUpdateServiceFactory::~KioskAppUpdateServiceFactory() { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 85 GetInstance()->GetServiceForBrowserContext(profile, true)); | 128 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 86 } | 129 } |
| 87 | 130 |
| 88 // static | 131 // static |
| 89 KioskAppUpdateServiceFactory* KioskAppUpdateServiceFactory::GetInstance() { | 132 KioskAppUpdateServiceFactory* KioskAppUpdateServiceFactory::GetInstance() { |
| 90 return Singleton<KioskAppUpdateServiceFactory>::get(); | 133 return Singleton<KioskAppUpdateServiceFactory>::get(); |
| 91 } | 134 } |
| 92 | 135 |
| 93 BrowserContextKeyedService* | 136 BrowserContextKeyedService* |
| 94 KioskAppUpdateServiceFactory::BuildServiceInstanceFor( | 137 KioskAppUpdateServiceFactory::BuildServiceInstanceFor( |
| 95 content::BrowserContext* profile) const { | 138 content::BrowserContext* context) const { |
| 96 return new KioskAppUpdateService(static_cast<Profile*>(profile)); | 139 return new KioskAppUpdateService( |
| 140 Profile::FromBrowserContext(context), | |
| 141 g_browser_process->platform_part()->automatic_reboot_manager()); | |
| 97 } | 142 } |
| 98 | 143 |
| 99 } // namespace chromeos | 144 } // namespace chromeos |
| OLD | NEW |