Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/timer.h" | 13 #include "base/timer.h" |
| 14 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h" | |
| 14 #include "chrome/browser/extensions/update_observer.h" | 15 #include "chrome/browser/extensions/update_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 .h" |
| 16 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" | 17 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" |
| 17 | 18 |
| 18 class Profile; | 19 class Profile; |
| 19 | 20 |
| 20 namespace chromeos { | 21 namespace chromeos { |
| 21 | 22 |
| 23 class KioskAppUpdateServiceTest; | |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: This is not needed. Specifying the class as a
xiyuan
2013/06/21 16:50:56
Done.
| |
| 24 | |
| 25 namespace system { | |
| 26 class AutomaticRebootManager; | |
| 27 } | |
| 28 | |
| 22 // This class enforces automatic restart on app and Chrome updates in app mode. | 29 // This class enforces automatic restart on app and Chrome updates in app mode. |
| 23 class KioskAppUpdateService : public BrowserContextKeyedService, | 30 class KioskAppUpdateService : public BrowserContextKeyedService, |
| 24 public extensions::UpdateObserver { | 31 public extensions::UpdateObserver, |
| 32 public system::AutomaticRebootManagerObserver { | |
| 25 public: | 33 public: |
| 26 explicit KioskAppUpdateService(Profile* profile); | 34 KioskAppUpdateService( |
| 35 Profile* profile, | |
| 36 system::AutomaticRebootManager* automatic_reboot_manager); | |
| 27 virtual ~KioskAppUpdateService(); | 37 virtual ~KioskAppUpdateService(); |
| 28 | 38 |
| 29 void set_app_id(const std::string& app_id) { app_id_ = app_id; } | 39 void set_app_id(const std::string& app_id) { app_id_ = app_id; } |
| 30 std::string get_app_id() const { return app_id_; } | 40 std::string get_app_id() const { return app_id_; } |
| 31 | 41 |
| 32 private: | 42 private: |
| 43 friend class KioskAppUpdateServiceTest; | |
| 44 | |
| 33 void StartRestartTimer(); | 45 void StartRestartTimer(); |
| 34 void ForceRestart(); | 46 void ForceRestart(); |
| 35 | 47 |
| 48 // BrowserContextKeyedService overrides: | |
| 49 virtual void Shutdown() OVERRIDE; | |
| 50 | |
| 36 // extensions::UpdateObserver overrides: | 51 // extensions::UpdateObserver overrides: |
| 37 virtual void OnAppUpdateAvailable(const std::string& app_id) OVERRIDE; | 52 virtual void OnAppUpdateAvailable(const std::string& app_id) OVERRIDE; |
| 38 virtual void OnChromeUpdateAvailable() OVERRIDE {} | 53 virtual void OnChromeUpdateAvailable() OVERRIDE {} |
| 39 | 54 |
| 40 // BrowserContextKeyedService overrides: | 55 // system::AutomaticRebootManagerObserver overrides: |
| 41 virtual void Shutdown() OVERRIDE; | 56 virtual void OnRebootScheduled(Reason reason) OVERRIDE; |
| 57 virtual void willShutdownAutomaticRebootManager() OVERRIDE; | |
| 42 | 58 |
| 43 private: | |
| 44 Profile* profile_; | 59 Profile* profile_; |
| 45 std::string app_id_; | 60 std::string app_id_; |
| 46 | 61 |
| 47 // After we detect an upgrade we start a one-short timer to force restart. | 62 // After we detect an upgrade we start a one-short timer to force restart. |
| 48 base::OneShotTimer<KioskAppUpdateService> restart_timer_; | 63 base::OneShotTimer<KioskAppUpdateService> restart_timer_; |
| 49 | 64 |
| 65 system::AutomaticRebootManager* automatic_reboot_manager_; // Not owned. | |
| 66 | |
| 50 DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateService); | 67 DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateService); |
| 51 }; | 68 }; |
| 52 | 69 |
| 53 // Singleton that owns all KioskAppUpdateServices and associates them with | 70 // Singleton that owns all KioskAppUpdateServices and associates them with |
| 54 // profiles. | 71 // profiles. |
| 55 class KioskAppUpdateServiceFactory : public BrowserContextKeyedServiceFactory { | 72 class KioskAppUpdateServiceFactory : public BrowserContextKeyedServiceFactory { |
| 56 public: | 73 public: |
| 57 // Returns the KioskAppUpdateService for |profile|, creating it if it is not | 74 // Returns the KioskAppUpdateService for |profile|, creating it if it is not |
| 58 // yet created. | 75 // yet created. |
| 59 static KioskAppUpdateService* GetForProfile(Profile* profile); | 76 static KioskAppUpdateService* GetForProfile(Profile* profile); |
| 60 | 77 |
| 61 // Returns the KioskAppUpdateServiceFactory instance. | 78 // Returns the KioskAppUpdateServiceFactory instance. |
| 62 static KioskAppUpdateServiceFactory* GetInstance(); | 79 static KioskAppUpdateServiceFactory* GetInstance(); |
| 63 | 80 |
| 64 private: | 81 private: |
| 65 friend struct DefaultSingletonTraits<KioskAppUpdateServiceFactory>; | 82 friend struct DefaultSingletonTraits<KioskAppUpdateServiceFactory>; |
| 66 | 83 |
| 67 KioskAppUpdateServiceFactory(); | 84 KioskAppUpdateServiceFactory(); |
| 68 virtual ~KioskAppUpdateServiceFactory(); | 85 virtual ~KioskAppUpdateServiceFactory(); |
| 69 | 86 |
| 70 // BrowserContextKeyedServiceFactory overrides: | 87 // BrowserContextKeyedServiceFactory overrides: |
| 71 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 88 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
| 72 content::BrowserContext* profile) const OVERRIDE; | 89 content::BrowserContext* profile) const OVERRIDE; |
| 73 }; | 90 }; |
| 74 | 91 |
| 75 } // namespace chromeos | 92 } // namespace chromeos |
| 76 | 93 |
| 77 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_ | 94 #endif // CHROME_BROWSER_CHROMEOS_APP_MODE_KIOSK_APP_UPDATE_SERVICE_H_ |
| OLD | NEW |