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 // Force a chrome restart (not a logout or reboot) by closing all browsers. | |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: Update comment and log message. Depending on
xiyuan
2013/06/21 16:50:56
Done.
| |
| 58 LOG(WARNING) << "Force closing all browsers to update kiosk app."; | |
| 59 chrome::CloseAllBrowsers(); | |
| 60 } | |
| 61 | |
| 36 void KioskAppUpdateService::Shutdown() { | 62 void KioskAppUpdateService::Shutdown() { |
| 37 ExtensionService* service = profile_->GetExtensionService(); | 63 ExtensionService* service = profile_->GetExtensionService(); |
| 38 if (service) | 64 if (service) |
| 39 service->RemoveUpdateObserver(this); | 65 service->RemoveUpdateObserver(this); |
| 40 } | 66 } |
| 41 | 67 |
| 42 void KioskAppUpdateService::OnAppUpdateAvailable(const std::string& app_id) { | 68 void KioskAppUpdateService::OnAppUpdateAvailable(const std::string& app_id) { |
| 43 DCHECK(!app_id_.empty()); | 69 DCHECK(!app_id_.empty()); |
| 44 if (app_id != app_id_) | 70 if (app_id != app_id_) |
| 45 return; | 71 return; |
| 46 | 72 |
| 73 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( | |
| 74 profile_, | |
| 75 app_id_, | |
| 76 extensions::RuntimeEventRouter::RESTART_REASON_APP_UPDATE); | |
| 77 | |
| 47 StartRestartTimer(); | 78 StartRestartTimer(); |
| 48 } | 79 } |
| 49 | 80 |
| 50 void KioskAppUpdateService::StartRestartTimer() { | 81 void KioskAppUpdateService::OnRebootScheduled(Reason reason) { |
| 51 if (restart_timer_.IsRunning()) | 82 extensions::RuntimeEventRouter::RestartReason restart_reason; |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: Initialize restart_reason to a fallback value
xiyuan
2013/06/21 16:50:56
Done.
| |
| 52 return; | 83 switch (reason) { |
| 84 case REBOOT_REASON_OS_UPDATE: | |
| 85 restart_reason = extensions::RuntimeEventRouter::RESTART_REASON_OS_UPDATE; | |
| 86 break; | |
| 87 case REBOOT_REASON_PERIODIC: | |
| 88 restart_reason = extensions::RuntimeEventRouter::RESTART_REASON_PERIODIC; | |
| 89 break; | |
| 90 default: | |
| 91 NOTREACHED() << "Unknown reboot reason=" << reason; | |
| 92 return; | |
| 93 } | |
| 53 | 94 |
| 54 // Setup timer to force restart once the wait period expires. | 95 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 55 restart_timer_.Start( | 96 profile_, app_id_, restart_reason); |
| 56 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), | |
| 57 this, &KioskAppUpdateService::ForceRestart); | |
| 58 } | 97 } |
| 59 | 98 |
| 60 void KioskAppUpdateService::ForceRestart() { | 99 void KioskAppUpdateService::willShutdownAutomaticRebootManager() { |
| 61 // Force a chrome restart (not a logout or reboot) by closing all browsers. | 100 automatic_reboot_manager_->RemoveObserver(this); |
| 62 LOG(WARNING) << "Force closing all browsers to update kiosk app."; | 101 automatic_reboot_manager_ = NULL; |
| 63 chrome::CloseAllBrowsers(); | |
| 64 } | 102 } |
| 65 | 103 |
| 66 KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory() | 104 KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory() |
| 67 : BrowserContextKeyedServiceFactory( | 105 : BrowserContextKeyedServiceFactory( |
| 68 "KioskAppUpdateService", | 106 "KioskAppUpdateService", |
| 69 BrowserContextDependencyManager::GetInstance()) { | 107 BrowserContextDependencyManager::GetInstance()) { |
| 70 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); | 108 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); |
| 71 } | 109 } |
| 72 | 110 |
| 73 KioskAppUpdateServiceFactory::~KioskAppUpdateServiceFactory() { | 111 KioskAppUpdateServiceFactory::~KioskAppUpdateServiceFactory() { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 85 GetInstance()->GetServiceForBrowserContext(profile, true)); | 123 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 86 } | 124 } |
| 87 | 125 |
| 88 // static | 126 // static |
| 89 KioskAppUpdateServiceFactory* KioskAppUpdateServiceFactory::GetInstance() { | 127 KioskAppUpdateServiceFactory* KioskAppUpdateServiceFactory::GetInstance() { |
| 90 return Singleton<KioskAppUpdateServiceFactory>::get(); | 128 return Singleton<KioskAppUpdateServiceFactory>::get(); |
| 91 } | 129 } |
| 92 | 130 |
| 93 BrowserContextKeyedService* | 131 BrowserContextKeyedService* |
| 94 KioskAppUpdateServiceFactory::BuildServiceInstanceFor( | 132 KioskAppUpdateServiceFactory::BuildServiceInstanceFor( |
| 95 content::BrowserContext* profile) const { | 133 content::BrowserContext* context) const { |
| 96 return new KioskAppUpdateService(static_cast<Profile*>(profile)); | 134 return new KioskAppUpdateService( |
| 135 Profile::FromBrowserContext(context), | |
| 136 g_browser_process->platform_part()->automatic_reboot_manager()); | |
| 97 } | 137 } |
| 98 | 138 |
| 99 } // namespace chromeos | 139 } // namespace chromeos |
| OLD | NEW |