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" | 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 | |
| 37 ExtensionService* service = | 46 ExtensionService* service = |
| 38 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 47 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 39 if (service) | 48 if (service) |
| 40 service->AddUpdateObserver(this); | 49 service->AddUpdateObserver(this); |
| 41 | 50 |
| 42 if (automatic_reboot_manager_) | 51 if (automatic_reboot_manager_) |
| 43 automatic_reboot_manager_->AddObserver(this); | 52 automatic_reboot_manager_->AddObserver(this); |
| 44 | 53 |
| 45 if (KioskAppManager::Get()) | 54 if (KioskAppManager::Get()) |
| 46 KioskAppManager::Get()->AddObserver(this); | 55 KioskAppManager::Get()->AddObserver(this); |
| 47 } | |
| 48 | 56 |
| 49 KioskAppUpdateService::~KioskAppUpdateService() { | 57 if (automatic_reboot_manager_->reboot_requested()) |
| 58 OnRebootRequested(automatic_reboot_manager_->reboot_reason()); | |
| 50 } | 59 } |
| 51 | 60 |
| 52 void KioskAppUpdateService::StartAppUpdateRestartTimer() { | 61 void KioskAppUpdateService::StartAppUpdateRestartTimer() { |
| 53 if (restart_timer_.IsRunning()) | 62 if (restart_timer_.IsRunning()) |
| 54 return; | 63 return; |
| 55 | 64 |
| 56 // Setup timer to force restart once the wait period expires. | 65 // Setup timer to force restart once the wait period expires. |
| 57 restart_timer_.Start( | 66 restart_timer_.Start( |
| 58 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), | 67 FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs), |
| 59 this, &KioskAppUpdateService::ForceAppUpdateRestart); | 68 this, &KioskAppUpdateService::ForceAppUpdateRestart); |
| 60 } | 69 } |
| 61 | 70 |
| 62 void KioskAppUpdateService::ForceAppUpdateRestart() { | 71 void KioskAppUpdateService::ForceAppUpdateRestart() { |
| 63 // Force a chrome restart (not a logout or reboot) by closing all browsers. | 72 // Force a chrome restart (not a logout or reboot) by closing all browsers. |
| 64 LOG(WARNING) << "Force closing all browsers to update kiosk app."; | 73 LOG(WARNING) << "Force closing all browsers to update kiosk app."; |
| 65 chrome::CloseAllBrowsersAndQuit(); | 74 chrome::CloseAllBrowsersAndQuit(); |
| 66 } | 75 } |
| 67 | 76 |
| 68 void KioskAppUpdateService::Shutdown() { | 77 void KioskAppUpdateService::Shutdown() { |
| 69 ExtensionService* service = | 78 ExtensionService* service = |
| 70 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 79 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 71 if (service) | 80 if (service) |
| 72 service->RemoveUpdateObserver(this); | 81 service->RemoveUpdateObserver(this); |
| 73 if (KioskAppManager::Get()) | 82 if (KioskAppManager::Get()) |
| 74 KioskAppManager::Get()->RemoveObserver(this); | 83 KioskAppManager::Get()->RemoveObserver(this); |
| 75 } | 84 } |
|
xiyuan
2014/11/17 20:08:03
nit: unrelated to this CL but would you mind add
bartfab (slow)
2014/11/18 11:04:46
Done.
| |
| 76 | 85 |
| 77 void KioskAppUpdateService::OnAppUpdateAvailable( | 86 void KioskAppUpdateService::OnAppUpdateAvailable( |
| 78 const extensions::Extension* extension) { | 87 const extensions::Extension* extension) { |
| 79 if (extension->id() != app_id_) | 88 if (extension->id() != app_id_) |
| 80 return; | 89 return; |
| 81 | 90 |
| 82 // Clears cached app data so that it will be reloaded if update from app | 91 // Clears cached app data so that it will be reloaded if update from app |
| 83 // does not finish in this run. | 92 // does not finish in this run. |
| 84 KioskAppManager::Get()->ClearAppData(app_id_); | 93 KioskAppManager::Get()->ClearAppData(app_id_); |
| 85 KioskAppManager::Get()->UpdateAppDataFromProfile( | 94 KioskAppManager::Get()->UpdateAppDataFromProfile( |
| 86 app_id_, profile_, extension); | 95 app_id_, profile_, extension); |
| 87 | 96 |
| 88 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( | 97 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 89 profile_, | 98 profile_, |
| 90 app_id_, | 99 app_id_, |
| 91 extensions::core_api::runtime::OnRestartRequired::REASON_APP_UPDATE); | 100 extensions::core_api::runtime::OnRestartRequired::REASON_APP_UPDATE); |
| 92 | 101 |
| 93 StartAppUpdateRestartTimer(); | 102 StartAppUpdateRestartTimer(); |
| 94 } | 103 } |
| 95 | 104 |
| 96 void KioskAppUpdateService::OnRebootScheduled(Reason reason) { | 105 void KioskAppUpdateService::OnRebootRequested(Reason reason) { |
| 97 extensions::core_api::runtime::OnRestartRequired::Reason restart_reason = | 106 extensions::core_api::runtime::OnRestartRequired::Reason restart_reason = |
| 98 extensions::core_api::runtime::OnRestartRequired::REASON_NONE; | 107 extensions::core_api::runtime::OnRestartRequired::REASON_NONE; |
| 99 switch (reason) { | 108 switch (reason) { |
| 100 case REBOOT_REASON_OS_UPDATE: | 109 case REBOOT_REASON_OS_UPDATE: |
| 101 restart_reason = | 110 restart_reason = |
| 102 extensions::core_api::runtime::OnRestartRequired::REASON_OS_UPDATE; | 111 extensions::core_api::runtime::OnRestartRequired::REASON_OS_UPDATE; |
| 103 break; | 112 break; |
| 104 case REBOOT_REASON_PERIODIC: | 113 case REBOOT_REASON_PERIODIC: |
| 105 restart_reason = | 114 restart_reason = |
| 106 extensions::core_api::runtime::OnRestartRequired::REASON_PERIODIC; | 115 extensions::core_api::runtime::OnRestartRequired::REASON_PERIODIC; |
| 107 break; | 116 break; |
| 108 default: | 117 default: |
| 109 NOTREACHED() << "Unknown reboot reason=" << reason; | 118 NOTREACHED() << "Unknown reboot reason=" << reason; |
| 110 return; | 119 return; |
| 111 } | 120 } |
| 112 | 121 |
| 113 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( | 122 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 114 profile_, app_id_, restart_reason); | 123 profile_, app_id_, restart_reason); |
| 115 } | 124 } |
| 116 | 125 |
| 117 void KioskAppUpdateService::WillDestroyAutomaticRebootManager() { | 126 void KioskAppUpdateService::WillDestroyAutomaticRebootManager() { |
| 118 automatic_reboot_manager_->RemoveObserver(this); | |
| 119 automatic_reboot_manager_ = NULL; | 127 automatic_reboot_manager_ = NULL; |
| 120 } | 128 } |
| 121 | 129 |
| 122 void KioskAppUpdateService::OnKioskAppCacheUpdated(const std::string& app_id) { | 130 void KioskAppUpdateService::OnKioskAppCacheUpdated(const std::string& app_id) { |
| 123 if (app_id != app_id_) | 131 if (app_id != app_id_) |
| 124 return; | 132 return; |
| 125 | 133 |
| 126 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( | 134 extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent( |
| 127 profile_, | 135 profile_, |
| 128 app_id_, | 136 app_id_, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 } | 168 } |
| 161 | 169 |
| 162 KeyedService* KioskAppUpdateServiceFactory::BuildServiceInstanceFor( | 170 KeyedService* KioskAppUpdateServiceFactory::BuildServiceInstanceFor( |
| 163 content::BrowserContext* context) const { | 171 content::BrowserContext* context) const { |
| 164 return new KioskAppUpdateService( | 172 return new KioskAppUpdateService( |
| 165 Profile::FromBrowserContext(context), | 173 Profile::FromBrowserContext(context), |
| 166 g_browser_process->platform_part()->automatic_reboot_manager()); | 174 g_browser_process->platform_part()->automatic_reboot_manager()); |
| 167 } | 175 } |
| 168 | 176 |
| 169 } // namespace chromeos | 177 } // namespace chromeos |
| OLD | NEW |