Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / app_mode / kiosk_app_update_service.h
blob491647c79b21948000cc9d198c5c511fbd9a1cba
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_
8 #include <string>
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"
19 class Profile;
21 namespace extensions {
22 class Extension;
25 namespace chromeos {
27 namespace system {
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 {
35 public:
36 KioskAppUpdateService(
37 Profile* profile,
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_; }
44 private:
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;
62 Profile* profile_;
63 std::string app_id_;
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
74 // profiles.
75 class KioskAppUpdateServiceFactory : public BrowserContextKeyedServiceFactory {
76 public:
77 // Returns the KioskAppUpdateService for |profile|, creating it if it is not
78 // yet created.
79 static KioskAppUpdateService* GetForProfile(Profile* profile);
81 // Returns the KioskAppUpdateServiceFactory instance.
82 static KioskAppUpdateServiceFactory* GetInstance();
84 private:
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_