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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/singleton.h"
13 #include "base/timer/timer.h"
14 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h"
15 #include "chrome/browser/extensions/update_observer.h"
16 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
17 #include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
24 class AutomaticRebootManager;
27 // This class enforces automatic restart on app and Chrome updates in app mode.
28 class KioskAppUpdateService : public BrowserContextKeyedService,
29 public extensions::UpdateObserver,
30 public system::AutomaticRebootManagerObserver {
32 KioskAppUpdateService(
34 system::AutomaticRebootManager* automatic_reboot_manager);
35 virtual ~KioskAppUpdateService();
37 void set_app_id(const std::string& app_id) { app_id_ = app_id; }
38 std::string get_app_id() const { return app_id_; }
41 friend class KioskAppUpdateServiceTest;
43 void StartAppUpdateRestartTimer();
44 void ForceAppUpdateRestart();
46 // BrowserContextKeyedService overrides:
47 virtual void Shutdown() OVERRIDE;
49 // extensions::UpdateObserver overrides:
50 virtual void OnAppUpdateAvailable(const std::string& app_id) OVERRIDE;
51 virtual void OnChromeUpdateAvailable() OVERRIDE {}
53 // system::AutomaticRebootManagerObserver overrides:
54 virtual void OnRebootScheduled(Reason reason) OVERRIDE;
55 virtual void WillDestroyAutomaticRebootManager() OVERRIDE;
60 // After we detect an upgrade we start a one-short timer to force restart.
61 base::OneShotTimer<KioskAppUpdateService> restart_timer_;
63 system::AutomaticRebootManager* automatic_reboot_manager_; // Not owned.
65 DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateService);
68 // Singleton that owns all KioskAppUpdateServices and associates them with
70 class KioskAppUpdateServiceFactory : public BrowserContextKeyedServiceFactory {
72 // Returns the KioskAppUpdateService for |profile|, creating it if it is not
74 static KioskAppUpdateService* GetForProfile(Profile* profile);
76 // Returns the KioskAppUpdateServiceFactory instance.
77 static KioskAppUpdateServiceFactory* GetInstance();
80 friend struct DefaultSingletonTraits<KioskAppUpdateServiceFactory>;
82 KioskAppUpdateServiceFactory();
83 virtual ~KioskAppUpdateServiceFactory();
85 // BrowserContextKeyedServiceFactory overrides:
86 virtual BrowserContextKeyedService* BuildServiceInstanceFor(
87 content::BrowserContext* profile) const OVERRIDE;
90 } // namespace chromeos
92 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_