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/app_mode/kiosk_app_manager_observer.h"
15 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h"
16 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
17 #include "components/keyed_service/core/keyed_service.h"
18 #include "extensions/browser/update_observer.h"
22 namespace extensions
{
29 class AutomaticRebootManager
;
32 // This class enforces automatic restart on app and Chrome updates in app mode.
33 class KioskAppUpdateService
: public KeyedService
,
34 public extensions::UpdateObserver
,
35 public system::AutomaticRebootManagerObserver
,
36 public KioskAppManagerObserver
{
38 KioskAppUpdateService(
40 system::AutomaticRebootManager
* automatic_reboot_manager
);
41 ~KioskAppUpdateService() override
;
43 void Init(const std::string
& app_id
);
45 std::string
get_app_id() const { return app_id_
; }
48 friend class KioskAppUpdateServiceTest
;
50 void StartAppUpdateRestartTimer();
51 void ForceAppUpdateRestart();
53 // KeyedService overrides:
54 void Shutdown() override
;
56 // extensions::UpdateObserver overrides:
57 void OnAppUpdateAvailable(const extensions::Extension
* extension
) override
;
58 void OnChromeUpdateAvailable() override
{}
60 // system::AutomaticRebootManagerObserver overrides:
61 void OnRebootRequested(Reason reason
) override
;
62 void WillDestroyAutomaticRebootManager() override
;
64 // KioskAppManagerObserver overrides:
65 void OnKioskAppCacheUpdated(const std::string
& app_id
) override
;
70 // After we detect an upgrade we start a one-short timer to force restart.
71 base::OneShotTimer
<KioskAppUpdateService
> restart_timer_
;
73 system::AutomaticRebootManager
* automatic_reboot_manager_
; // Not owned.
75 DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateService
);
78 // Singleton that owns all KioskAppUpdateServices and associates them with
80 class KioskAppUpdateServiceFactory
: public BrowserContextKeyedServiceFactory
{
82 // Returns the KioskAppUpdateService for |profile|, creating it if it is not
84 static KioskAppUpdateService
* GetForProfile(Profile
* profile
);
86 // Returns the KioskAppUpdateServiceFactory instance.
87 static KioskAppUpdateServiceFactory
* GetInstance();
90 friend struct base::DefaultSingletonTraits
<KioskAppUpdateServiceFactory
>;
92 KioskAppUpdateServiceFactory();
93 ~KioskAppUpdateServiceFactory() override
;
95 // BrowserContextKeyedServiceFactory overrides:
96 KeyedService
* BuildServiceInstanceFor(
97 content::BrowserContext
* profile
) const override
;
100 } // namespace chromeos
102 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_