This source file includes following definitions.
- automatic_reboot_manager_
- StartAppUpdateRestartTimer
- ForceAppUpdateRestart
- Shutdown
- OnAppUpdateAvailable
- OnRebootScheduled
- WillDestroyAutomaticRebootManager
- GetForProfile
- GetInstance
- BuildServiceInstanceFor
#include "chrome/browser/chromeos/app_mode/kiosk_app_update_service.h"
#include "base/logging.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
#include "chrome/browser/extensions/api/runtime/runtime_api.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_system_provider.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/common/extension.h"
namespace chromeos {
namespace {
const int kForceRestartWaitTimeMs = 24 * 3600 * 1000;
}
KioskAppUpdateService::KioskAppUpdateService(
Profile* profile,
system::AutomaticRebootManager* automatic_reboot_manager)
: profile_(profile),
automatic_reboot_manager_(automatic_reboot_manager) {
ExtensionService* service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
if (service)
service->AddUpdateObserver(this);
if (automatic_reboot_manager_)
automatic_reboot_manager_->AddObserver(this);
}
KioskAppUpdateService::~KioskAppUpdateService() {
}
void KioskAppUpdateService::StartAppUpdateRestartTimer() {
if (restart_timer_.IsRunning())
return;
restart_timer_.Start(
FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs),
this, &KioskAppUpdateService::ForceAppUpdateRestart);
}
void KioskAppUpdateService::ForceAppUpdateRestart() {
LOG(WARNING) << "Force closing all browsers to update kiosk app.";
chrome::CloseAllBrowsersAndQuit();
}
void KioskAppUpdateService::Shutdown() {
ExtensionService* service = profile_->GetExtensionService();
if (service)
service->RemoveUpdateObserver(this);
}
void KioskAppUpdateService::OnAppUpdateAvailable(
const extensions::Extension* extension) {
if (extension->id() != app_id_)
return;
KioskAppManager::Get()->ClearAppData(app_id_);
KioskAppManager::Get()->UpdateAppDataFromProfile(
app_id_, profile_, extension);
extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent(
profile_,
app_id_,
extensions::api::runtime::OnRestartRequired::REASON_APP_UPDATE);
StartAppUpdateRestartTimer();
}
void KioskAppUpdateService::OnRebootScheduled(Reason reason) {
extensions::api::runtime::OnRestartRequired::Reason restart_reason =
extensions::api::runtime::OnRestartRequired::REASON_NONE;
switch (reason) {
case REBOOT_REASON_OS_UPDATE:
restart_reason =
extensions::api::runtime::OnRestartRequired::REASON_OS_UPDATE;
break;
case REBOOT_REASON_PERIODIC:
restart_reason =
extensions::api::runtime::OnRestartRequired::REASON_PERIODIC;
break;
default:
NOTREACHED() << "Unknown reboot reason=" << reason;
return;
}
extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent(
profile_, app_id_, restart_reason);
}
void KioskAppUpdateService::WillDestroyAutomaticRebootManager() {
automatic_reboot_manager_->RemoveObserver(this);
automatic_reboot_manager_ = NULL;
}
KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory()
: BrowserContextKeyedServiceFactory(
"KioskAppUpdateService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(
extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
}
KioskAppUpdateServiceFactory::~KioskAppUpdateServiceFactory() {
}
KioskAppUpdateService* KioskAppUpdateServiceFactory::GetForProfile(
Profile* profile) {
DCHECK(chrome::IsRunningInForcedAppMode());
if (!chrome::IsRunningInForcedAppMode())
return NULL;
return static_cast<KioskAppUpdateService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
KioskAppUpdateServiceFactory* KioskAppUpdateServiceFactory::GetInstance() {
return Singleton<KioskAppUpdateServiceFactory>::get();
}
KeyedService* KioskAppUpdateServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new KioskAppUpdateService(
Profile::FromBrowserContext(context),
g_browser_process->platform_part()->automatic_reboot_manager());
}
}