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 "components/browser_context_keyed_service/browser_context_keyed_service.h"
16 #include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
17 #include "extensions/browser/update_observer.h"
21 namespace extensions
{
28 class AutomaticRebootManager
;
31 // This class enforces automatic restart on app and Chrome updates in app mode.
32 class KioskAppUpdateService
: public BrowserContextKeyedService
,
33 public extensions::UpdateObserver
,
34 public system::AutomaticRebootManagerObserver
{
36 KioskAppUpdateService(
38 system::AutomaticRebootManager
* automatic_reboot_manager
);
39 virtual ~KioskAppUpdateService();
41 void set_app_id(const std::string
& app_id
) { app_id_
= app_id
; }
42 std::string
get_app_id() const { return app_id_
; }
45 friend class KioskAppUpdateServiceTest
;
47 void StartAppUpdateRestartTimer();
48 void ForceAppUpdateRestart();
50 // BrowserContextKeyedService overrides:
51 virtual void Shutdown() OVERRIDE
;
53 // extensions::UpdateObserver overrides:
54 virtual void OnAppUpdateAvailable(
55 const extensions::Extension
* extension
) OVERRIDE
;
56 virtual void OnChromeUpdateAvailable() OVERRIDE
{}
58 // system::AutomaticRebootManagerObserver overrides:
59 virtual void OnRebootScheduled(Reason reason
) OVERRIDE
;
60 virtual void WillDestroyAutomaticRebootManager() OVERRIDE
;
65 // After we detect an upgrade we start a one-short timer to force restart.
66 base::OneShotTimer
<KioskAppUpdateService
> restart_timer_
;
68 system::AutomaticRebootManager
* automatic_reboot_manager_
; // Not owned.
70 DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateService
);
73 // Singleton that owns all KioskAppUpdateServices and associates them with
75 class KioskAppUpdateServiceFactory
: public BrowserContextKeyedServiceFactory
{
77 // Returns the KioskAppUpdateService for |profile|, creating it if it is not
79 static KioskAppUpdateService
* GetForProfile(Profile
* profile
);
81 // Returns the KioskAppUpdateServiceFactory instance.
82 static KioskAppUpdateServiceFactory
* GetInstance();
85 friend struct DefaultSingletonTraits
<KioskAppUpdateServiceFactory
>;
87 KioskAppUpdateServiceFactory();
88 virtual ~KioskAppUpdateServiceFactory();
90 // BrowserContextKeyedServiceFactory overrides:
91 virtual BrowserContextKeyedService
* BuildServiceInstanceFor(
92 content::BrowserContext
* profile
) const OVERRIDE
;
95 } // namespace chromeos
97 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_