Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Unified Diff: chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc

Issue 16844020: app_mode: Add runtime.onRestartRequired event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments in #1, add test and remove onBrowserUpdateAvailable Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc
diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc b/chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc
index 0b789f9062236c74140938f249477d0a1dde24d0..ed61ee27c3d2227ef6e7b8751c518effeb880386 100644
--- a/chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc
+++ b/chrome/browser/chromeos/app_mode/kiosk_app_update_service.cc
@@ -6,6 +6,10 @@
#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/system/automatic_reboot_manager.h"
+#include "chrome/browser/extensions/api/runtime/runtime_api.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_system_factory.h"
@@ -22,17 +26,39 @@ const int kForceRestartWaitTimeMs = 24 * 3600 * 1000; // 24 hours.
} // namespace
-KioskAppUpdateService::KioskAppUpdateService(Profile* profile)
- : profile_(profile) {
+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::StartRestartTimer() {
+ if (restart_timer_.IsRunning())
+ return;
+
+ // Setup timer to force restart once the wait period expires.
+ restart_timer_.Start(
+ FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs),
+ this, &KioskAppUpdateService::ForceRestart);
+}
+
+void KioskAppUpdateService::ForceRestart() {
+ // 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.
+ LOG(WARNING) << "Force closing all browsers to update kiosk app.";
+ chrome::CloseAllBrowsers();
+}
+
void KioskAppUpdateService::Shutdown() {
ExtensionService* service = profile_->GetExtensionService();
if (service)
@@ -44,23 +70,35 @@ void KioskAppUpdateService::OnAppUpdateAvailable(const std::string& app_id) {
if (app_id != app_id_)
return;
+ extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent(
+ profile_,
+ app_id_,
+ extensions::RuntimeEventRouter::RESTART_REASON_APP_UPDATE);
+
StartRestartTimer();
}
-void KioskAppUpdateService::StartRestartTimer() {
- if (restart_timer_.IsRunning())
- return;
-
- // Setup timer to force restart once the wait period expires.
- restart_timer_.Start(
- FROM_HERE, base::TimeDelta::FromMilliseconds(kForceRestartWaitTimeMs),
- this, &KioskAppUpdateService::ForceRestart);
+void KioskAppUpdateService::OnRebootScheduled(Reason reason) {
+ 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.
+ switch (reason) {
+ case REBOOT_REASON_OS_UPDATE:
+ restart_reason = extensions::RuntimeEventRouter::RESTART_REASON_OS_UPDATE;
+ break;
+ case REBOOT_REASON_PERIODIC:
+ restart_reason = extensions::RuntimeEventRouter::RESTART_REASON_PERIODIC;
+ break;
+ default:
+ NOTREACHED() << "Unknown reboot reason=" << reason;
+ return;
+ }
+
+ extensions::RuntimeEventRouter::DispatchOnRestartRequiredEvent(
+ profile_, app_id_, restart_reason);
}
-void KioskAppUpdateService::ForceRestart() {
- // Force a chrome restart (not a logout or reboot) by closing all browsers.
- LOG(WARNING) << "Force closing all browsers to update kiosk app.";
- chrome::CloseAllBrowsers();
+void KioskAppUpdateService::willShutdownAutomaticRebootManager() {
+ automatic_reboot_manager_->RemoveObserver(this);
+ automatic_reboot_manager_ = NULL;
}
KioskAppUpdateServiceFactory::KioskAppUpdateServiceFactory()
@@ -92,8 +130,10 @@ KioskAppUpdateServiceFactory* KioskAppUpdateServiceFactory::GetInstance() {
BrowserContextKeyedService*
KioskAppUpdateServiceFactory::BuildServiceInstanceFor(
- content::BrowserContext* profile) const {
- return new KioskAppUpdateService(static_cast<Profile*>(profile));
+ content::BrowserContext* context) const {
+ return new KioskAppUpdateService(
+ Profile::FromBrowserContext(context),
+ g_browser_process->platform_part()->automatic_reboot_manager());
}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698