| 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/chromeos/system/automatic_reboot_manager.h" |
| 10 #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 11 #include "chrome/browser/extensions/extension_system_factory.h" | 13 #include "chrome/browser/extensions/extension_system_factory.h" |
| 12 #include "chrome/browser/lifetime/application_lifetime.h" | 14 #include "chrome/browser/lifetime/application_lifetime.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 14 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 16 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 15 | 17 |
| 16 namespace chromeos { | 18 namespace chromeos { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 // How low to wait after an update is available before we force a restart. | 22 // How low to wait after an update is available before we force a restart. |
| 21 const int kForceRestartWaitTimeMs = 24 * 3600 * 1000; // 24 hours. | 23 const int kForceRestartWaitTimeMs = 24 * 3600 * 1000; // 24 hours. |
| 22 | 24 |
| 23 } // namespace | 25 } // namespace |
| 24 | 26 |
| 25 KioskAppUpdateService::KioskAppUpdateService(Profile* profile) | 27 KioskAppUpdateService::KioskAppUpdateService(Profile* profile) |
| 26 : profile_(profile) { | 28 : profile_(profile) { |
| 27 ExtensionService* service = | 29 ExtensionService* service = |
| 28 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 30 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 29 if (service) | 31 if (service) |
| 30 service->AddUpdateObserver(this); | 32 service->AddUpdateObserver(this); |
| 33 |
| 34 system::AutomaticRebootManager::Get()->AddObserver(this); |
| 31 } | 35 } |
| 32 | 36 |
| 33 KioskAppUpdateService::~KioskAppUpdateService() { | 37 KioskAppUpdateService::~KioskAppUpdateService() { |
| 34 } | 38 } |
| 35 | 39 |
| 36 void KioskAppUpdateService::Shutdown() { | |
| 37 ExtensionService* service = profile_->GetExtensionService(); | |
| 38 if (service) | |
| 39 service->RemoveUpdateObserver(this); | |
| 40 } | |
| 41 | |
| 42 void KioskAppUpdateService::OnAppUpdateAvailable(const std::string& app_id) { | |
| 43 DCHECK(!app_id_.empty()); | |
| 44 if (app_id != app_id_) | |
| 45 return; | |
| 46 | |
| 47 StartRestartTimer(); | |
| 48 } | |
| 49 | |
| 50 void KioskAppUpdateService::StartRestartTimer() { | 40 void KioskAppUpdateService::StartRestartTimer() { |
| 51 if (restart_timer_.IsRunning()) | 41 if (restart_timer_.IsRunning()) |
| 52 return; | 42 return; |
| 53 | 43 |
| 54 // Setup timer to force restart once the wait period expires. | 44 // Setup timer to force restart once the wait period expires. |
| 55 restart_timer_.Start( | 45 restart_timer_.Start( |
| 56 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), | 46 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), |
| 57 this, &KioskAppUpdateService::ForceRestart); | 47 this, &KioskAppUpdateService::ForceRestart); |
| 58 } | 48 } |
| 59 | 49 |
| 60 void KioskAppUpdateService::ForceRestart() { | 50 void KioskAppUpdateService::ForceRestart() { |
| 61 // Force a chrome restart (not a logout or reboot) by closing all browsers. | 51 // Force a chrome restart (not a logout or reboot) by closing all browsers. |
| 62 LOG(WARNING) << "Force closing all browsers to update kiosk app."; | 52 LOG(WARNING) << "Force closing all browsers to update kiosk app."; |
| 63 chrome::CloseAllBrowsers(); | 53 chrome::CloseAllBrowsers(); |
| 64 } | 54 } |
| 65 | 55 |
| 56 void KioskAppUpdateService::Shutdown() { |
| 57 ExtensionService* service = profile_->GetExtensionService(); |
| 58 if (service) |
| 59 service->RemoveUpdateObserver(this); |
| 60 |
| 61 system::AutomaticRebootManager::Get()->RemoveObserver(this); |
| 62 } |
| 63 |
| 64 void KioskAppUpdateService::OnAppUpdateAvailable(const std::string& app_id) { |
| 65 DCHECK(!app_id_.empty()); |
| 66 if (app_id != app_id_) |
| 67 return; |
| 68 |
| 69 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 70 profile_, |
| 71 app_id_, |
| 72 extensions::RuntimeEventRouter::RESTART_REASON_APP_UPDATE); |
| 73 |
| 74 StartRestartTimer(); |
| 75 } |
| 76 |
| 77 void KioskAppUpdateService::OnRebootScheduled(Reason reason) { |
| 78 extensions::RuntimeEventRouter::RestartReason restart_reason; |
| 79 switch (reason) { |
| 80 case REBOOT_REASON_OS_UPDATE: |
| 81 restart_reason = extensions::RuntimeEventRouter::RESTART_REASON_OS_UPDATE; |
| 82 break; |
| 83 case REBOOT_REASON_PERIODIC: |
| 84 restart_reason = extensions::RuntimeEventRouter::RESTART_REASON_PERIODIC; |
| 85 break; |
| 86 default: |
| 87 NOTREACHED() << "Unknown reboot reason=" << reason; |
| 88 return; |
| 89 } |
| 90 |
| 91 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 92 profile_, app_id_, restart_reason); |
| 93 } |
| 94 |
| 66 KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory() | 95 KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory() |
| 67 : BrowserContextKeyedServiceFactory( | 96 : BrowserContextKeyedServiceFactory( |
| 68 "KioskAppUpdateService", | 97 "KioskAppUpdateService", |
| 69 BrowserContextDependencyManager::GetInstance()) { | 98 BrowserContextDependencyManager::GetInstance()) { |
| 70 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); | 99 DependsOn(extensions::ExtensionSystemFactory::GetInstance()); |
| 71 } | 100 } |
| 72 | 101 |
| 73 KioskAppUpdateServiceFactory::~KioskAppUpdateServiceFactory() { | 102 KioskAppUpdateServiceFactory::~KioskAppUpdateServiceFactory() { |
| 74 } | 103 } |
| 75 | 104 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 90 return Singleton<KioskAppUpdateServiceFactory>::get(); | 119 return Singleton<KioskAppUpdateServiceFactory>::get(); |
| 91 } | 120 } |
| 92 | 121 |
| 93 BrowserContextKeyedService* | 122 BrowserContextKeyedService* |
| 94 KioskAppUpdateServiceFactory::BuildServiceInstanceFor( | 123 KioskAppUpdateServiceFactory::BuildServiceInstanceFor( |
| 95 content::BrowserContext* profile) const { | 124 content::BrowserContext* profile) const { |
| 96 return new KioskAppUpdateService(static_cast<Profile*>(profile)); | 125 return new KioskAppUpdateService(static_cast<Profile*>(profile)); |
| 97 } | 126 } |
| 98 | 127 |
| 99 } // namespace chromeos | 128 } // namespace chromeos |
| OLD | NEW |