- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / app_mode / kiosk_app_update_service.h
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_
7
8 #include <string>
9
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"
18
19 class Profile;
20
21 namespace chromeos {
22
23 namespace system {
24 class AutomaticRebootManager;
25 }
26
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 {
31  public:
32   KioskAppUpdateService(
33       Profile* profile,
34       system::AutomaticRebootManager* automatic_reboot_manager);
35   virtual ~KioskAppUpdateService();
36
37   void set_app_id(const std::string& app_id) { app_id_ = app_id; }
38   std::string get_app_id() const { return app_id_; }
39
40  private:
41   friend class KioskAppUpdateServiceTest;
42
43   void StartAppUpdateRestartTimer();
44   void ForceAppUpdateRestart();
45
46   // BrowserContextKeyedService overrides:
47   virtual void Shutdown() OVERRIDE;
48
49   // extensions::UpdateObserver overrides:
50   virtual void OnAppUpdateAvailable(const std::string& app_id) OVERRIDE;
51   virtual void OnChromeUpdateAvailable() OVERRIDE {}
52
53   // system::AutomaticRebootManagerObserver overrides:
54   virtual void OnRebootScheduled(Reason reason) OVERRIDE;
55   virtual void WillDestroyAutomaticRebootManager() OVERRIDE;
56
57   Profile* profile_;
58   std::string app_id_;
59
60   // After we detect an upgrade we start a one-short timer to force restart.
61   base::OneShotTimer<KioskAppUpdateService> restart_timer_;
62
63   system::AutomaticRebootManager* automatic_reboot_manager_;  // Not owned.
64
65   DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateService);
66 };
67
68 // Singleton that owns all KioskAppUpdateServices and associates them with
69 // profiles.
70 class KioskAppUpdateServiceFactory : public BrowserContextKeyedServiceFactory {
71  public:
72   // Returns the KioskAppUpdateService for |profile|, creating it if it is not
73   // yet created.
74   static KioskAppUpdateService* GetForProfile(Profile* profile);
75
76   // Returns the KioskAppUpdateServiceFactory instance.
77   static KioskAppUpdateServiceFactory* GetInstance();
78
79  private:
80   friend struct DefaultSingletonTraits<KioskAppUpdateServiceFactory>;
81
82   KioskAppUpdateServiceFactory();
83   virtual ~KioskAppUpdateServiceFactory();
84
85   // BrowserContextKeyedServiceFactory overrides:
86   virtual BrowserContextKeyedService* BuildServiceInstanceFor(
87       content::BrowserContext* profile) const OVERRIDE;
88 };
89
90 }  // namespace chromeos
91
92 #endif  // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_