kiosk_app_update_service.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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 "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"
18
19class Profile;
20
21namespace extensions {
22class Extension;
23}
24
25namespace chromeos {
26
27namespace system {
28class AutomaticRebootManager;
29}
30
31// This class enforces automatic restart on app and Chrome updates in app mode.
32class 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();
40
41  void set_app_id(const std::string& app_id) { app_id_ = app_id; }
42  std::string get_app_id() const { return app_id_; }
43
44 private:
45  friend class KioskAppUpdateServiceTest;
46
47  void StartAppUpdateRestartTimer();
48  void ForceAppUpdateRestart();
49
50  // BrowserContextKeyedService overrides:
51  virtual void Shutdown() OVERRIDE;
52
53  // extensions::UpdateObserver overrides:
54  virtual void OnAppUpdateAvailable(
55      const extensions::Extension* extension) OVERRIDE;
56  virtual void OnChromeUpdateAvailable() OVERRIDE {}
57
58  // system::AutomaticRebootManagerObserver overrides:
59  virtual void OnRebootScheduled(Reason reason) OVERRIDE;
60  virtual void WillDestroyAutomaticRebootManager() OVERRIDE;
61
62  Profile* profile_;
63  std::string app_id_;
64
65  // After we detect an upgrade we start a one-short timer to force restart.
66  base::OneShotTimer<KioskAppUpdateService> restart_timer_;
67
68  system::AutomaticRebootManager* automatic_reboot_manager_;  // Not owned.
69
70  DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateService);
71};
72
73// Singleton that owns all KioskAppUpdateServices and associates them with
74// profiles.
75class 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);
80
81  // Returns the KioskAppUpdateServiceFactory instance.
82  static KioskAppUpdateServiceFactory* GetInstance();
83
84 private:
85  friend struct DefaultSingletonTraits<KioskAppUpdateServiceFactory>;
86
87  KioskAppUpdateServiceFactory();
88  virtual ~KioskAppUpdateServiceFactory();
89
90  // BrowserContextKeyedServiceFactory overrides:
91  virtual BrowserContextKeyedService* BuildServiceInstanceFor(
92      content::BrowserContext* profile) const OVERRIDE;
93};
94
95}  // namespace chromeos
96
97#endif  // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_
98