| 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" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 10 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // How low to wait after an update is available before we force a restart. | 27 // How low to wait after an update is available before we force a restart. |
| 28 const int kForceRestartWaitTimeMs = 24 * 3600 * 1000; // 24 hours. | 28 const int kForceRestartWaitTimeMs = 24 * 3600 * 1000; // 24 hours. |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 KioskAppUpdateService::KioskAppUpdateService( | 32 KioskAppUpdateService::KioskAppUpdateService( |
| 33 Profile* profile, | 33 Profile* profile, |
| 34 system::AutomaticRebootManager* automatic_reboot_manager) | 34 system::AutomaticRebootManager* automatic_reboot_manager) |
| 35 : profile_(profile), | 35 : profile_(profile), |
| 36 automatic_reboot_manager_(automatic_reboot_manager) { | 36 automatic_reboot_manager_(automatic_reboot_manager) { |
| 37 } | |
| 38 | |
| 39 KioskAppUpdateService::~KioskAppUpdateService() { | |
| 40 } | |
| 41 | |
| 42 void KioskAppUpdateService::Init(const std::string& app_id) { | |
| 43 DCHECK(app_id_.empty()); | |
| 44 app_id_ = app_id; | |
| 45 | |
| 46 ExtensionService* service = | 37 ExtensionService* service = |
| 47 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 38 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 48 if (service) | 39 if (service) |
| 49 service->AddUpdateObserver(this); | 40 service->AddUpdateObserver(this); |
| 50 | 41 |
| 51 if (automatic_reboot_manager_) | 42 if (automatic_reboot_manager_) |
| 52 automatic_reboot_manager_->AddObserver(this); | 43 automatic_reboot_manager_->AddObserver(this); |
| 53 | 44 |
| 54 if (KioskAppManager::Get()) | 45 if (KioskAppManager::Get()) |
| 55 KioskAppManager::Get()->AddObserver(this); | 46 KioskAppManager::Get()->AddObserver(this); |
| 47 } |
| 56 | 48 |
| 57 if (automatic_reboot_manager_->reboot_requested()) | 49 KioskAppUpdateService::~KioskAppUpdateService() { |
| 58 OnRebootRequested(automatic_reboot_manager_->reboot_reason()); | |
| 59 } | 50 } |
| 60 | 51 |
| 61 void KioskAppUpdateService::StartAppUpdateRestartTimer() { | 52 void KioskAppUpdateService::StartAppUpdateRestartTimer() { |
| 62 if (restart_timer_.IsRunning()) | 53 if (restart_timer_.IsRunning()) |
| 63 return; | 54 return; |
| 64 | 55 |
| 65 // Setup timer to force restart once the wait period expires. | 56 // Setup timer to force restart once the wait period expires. |
| 66 restart_timer_.Start( | 57 restart_timer_.Start( |
| 67 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), | 58 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), |
| 68 this, &KioskAppUpdateService::ForceAppUpdateRestart); | 59 this, &KioskAppUpdateService::ForceAppUpdateRestart); |
| 69 } | 60 } |
| 70 | 61 |
| 71 void KioskAppUpdateService::ForceAppUpdateRestart() { | 62 void KioskAppUpdateService::ForceAppUpdateRestart() { |
| 72 // Force a chrome restart (not a logout or reboot) by closing all browsers. | 63 // Force a chrome restart (not a logout or reboot) by closing all browsers. |
| 73 LOG(WARNING) << "Force closing all browsers to update kiosk app."; | 64 LOG(WARNING) << "Force closing all browsers to update kiosk app."; |
| 74 chrome::CloseAllBrowsersAndQuit(); | 65 chrome::CloseAllBrowsersAndQuit(); |
| 75 } | 66 } |
| 76 | 67 |
| 77 void KioskAppUpdateService::Shutdown() { | 68 void KioskAppUpdateService::Shutdown() { |
| 78 ExtensionService* service = | 69 ExtensionService* service = |
| 79 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 70 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 80 if (service) | 71 if (service) |
| 81 service->RemoveUpdateObserver(this); | 72 service->RemoveUpdateObserver(this); |
| 82 if (KioskAppManager::Get()) | 73 if (KioskAppManager::Get()) |
| 83 KioskAppManager::Get()->RemoveObserver(this); | 74 KioskAppManager::Get()->RemoveObserver(this); |
| 84 if (automatic_reboot_manager_) | |
| 85 automatic_reboot_manager_->RemoveObserver(this); | |
| 86 } | 75 } |
| 87 | 76 |
| 88 void KioskAppUpdateService::OnAppUpdateAvailable( | 77 void KioskAppUpdateService::OnAppUpdateAvailable( |
| 89 const extensions::Extension* extension) { | 78 const extensions::Extension* extension) { |
| 90 if (extension->id() != app_id_) | 79 if (extension->id() != app_id_) |
| 91 return; | 80 return; |
| 92 | 81 |
| 93 // Clears cached app data so that it will be reloaded if update from app | 82 // Clears cached app data so that it will be reloaded if update from app |
| 94 // does not finish in this run. | 83 // does not finish in this run. |
| 95 KioskAppManager::Get()->ClearAppData(app_id_); | 84 KioskAppManager::Get()->ClearAppData(app_id_); |
| 96 KioskAppManager::Get()->UpdateAppDataFromProfile( | 85 KioskAppManager::Get()->UpdateAppDataFromProfile( |
| 97 app_id_, profile_, extension); | 86 app_id_, profile_, extension); |
| 98 | 87 |
| 99 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( | 88 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 100 profile_, | 89 profile_, |
| 101 app_id_, | 90 app_id_, |
| 102 extensions::core_api::runtime::OnRestartRequired::REASON_APP_UPDATE); | 91 extensions::core_api::runtime::OnRestartRequired::REASON_APP_UPDATE); |
| 103 | 92 |
| 104 StartAppUpdateRestartTimer(); | 93 StartAppUpdateRestartTimer(); |
| 105 } | 94 } |
| 106 | 95 |
| 107 void KioskAppUpdateService::OnRebootRequested(Reason reason) { | 96 void KioskAppUpdateService::OnRebootScheduled(Reason reason) { |
| 108 extensions::core_api::runtime::OnRestartRequired::Reason restart_reason = | 97 extensions::core_api::runtime::OnRestartRequired::Reason restart_reason = |
| 109 extensions::core_api::runtime::OnRestartRequired::REASON_NONE; | 98 extensions::core_api::runtime::OnRestartRequired::REASON_NONE; |
| 110 switch (reason) { | 99 switch (reason) { |
| 111 case REBOOT_REASON_OS_UPDATE: | 100 case REBOOT_REASON_OS_UPDATE: |
| 112 restart_reason = | 101 restart_reason = |
| 113 extensions::core_api::runtime::OnRestartRequired::REASON_OS_UPDATE; | 102 extensions::core_api::runtime::OnRestartRequired::REASON_OS_UPDATE; |
| 114 break; | 103 break; |
| 115 case REBOOT_REASON_PERIODIC: | 104 case REBOOT_REASON_PERIODIC: |
| 116 restart_reason = | 105 restart_reason = |
| 117 extensions::core_api::runtime::OnRestartRequired::REASON_PERIODIC; | 106 extensions::core_api::runtime::OnRestartRequired::REASON_PERIODIC; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 160 } |
| 172 | 161 |
| 173 KeyedService* KioskAppUpdateServiceFactory::BuildServiceInstanceFor( | 162 KeyedService* KioskAppUpdateServiceFactory::BuildServiceInstanceFor( |
| 174 content::BrowserContext* context) const { | 163 content::BrowserContext* context) const { |
| 175 return new KioskAppUpdateService( | 164 return new KioskAppUpdateService( |
| 176 Profile::FromBrowserContext(context), | 165 Profile::FromBrowserContext(context), |
| 177 g_browser_process->platform_part()->automatic_reboot_manager()); | 166 g_browser_process->platform_part()->automatic_reboot_manager()); |
| 178 } | 167 } |
| 179 | 168 |
| 180 } // namespace chromeos | 169 } // namespace chromeos |
| OLD | NEW |