| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 APPS_APP_RESTORE_SERVICE_H_ | 5 #ifndef APPS_APP_RESTORE_SERVICE_H_ |
| 6 #define APPS_APP_RESTORE_SERVICE_H_ | 6 #define APPS_APP_RESTORE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "apps/app_lifetime_monitor.h" | 11 #include "apps/app_lifetime_monitor.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
| 13 #include "extensions/browser/app_window/app_window_registry.h" | 13 #include "extensions/browser/app_window/app_window_registry.h" |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 class Extension; | 16 class Extension; |
| 17 } | 17 } |
| 18 | 18 |
| 19 class Profile; | 19 namespace content { |
| 20 class BrowserContext; |
| 21 } |
| 20 | 22 |
| 21 namespace apps { | 23 namespace apps { |
| 22 | 24 |
| 23 // Tracks what apps need to be restarted when the browser restarts. | 25 // Tracks what apps need to be restarted when the browser restarts. |
| 24 class AppRestoreService : public KeyedService, | 26 class AppRestoreService : public KeyedService, |
| 25 public AppLifetimeMonitor::Observer { | 27 public AppLifetimeMonitor::Observer { |
| 26 public: | 28 public: |
| 27 // Returns true if apps should be restored on the current platform, given | 29 // Returns true if apps should be restored on the current platform, given |
| 28 // whether this new browser process launched due to a restart. | 30 // whether this new browser process launched due to a restart. |
| 29 static bool ShouldRestoreApps(bool is_browser_restart); | 31 static bool ShouldRestoreApps(bool is_browser_restart); |
| 30 | 32 |
| 31 explicit AppRestoreService(Profile* profile); | 33 explicit AppRestoreService(content::BrowserContext* context); |
| 32 | 34 |
| 33 // Restart apps that need to be restarted and clear the "running" preference | 35 // Restart apps that need to be restarted and clear the "running" preference |
| 34 // from apps to prevent them being restarted in subsequent restarts. | 36 // from apps to prevent them being restarted in subsequent restarts. |
| 35 void HandleStartup(bool should_restore_apps); | 37 void HandleStartup(bool should_restore_apps); |
| 36 | 38 |
| 37 // Returns whether this extension is running or, at startup, whether it was | 39 // Returns whether this extension is running or, at startup, whether it was |
| 38 // running when Chrome was last terminated. | 40 // running when Chrome was last terminated. |
| 39 bool IsAppRestorable(const std::string& extension_id); | 41 bool IsAppRestorable(const std::string& extension_id); |
| 40 | 42 |
| 41 // Called to notify that the application has begun to exit. | 43 // Called to notify that the application has begun to exit. |
| 42 void OnApplicationTerminating(); | 44 void OnApplicationTerminating(); |
| 43 | 45 |
| 44 static AppRestoreService* Get(Profile* profile); | 46 static AppRestoreService* Get(content::BrowserContext* context); |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 // AppLifetimeMonitor::Observer. | 49 // AppLifetimeMonitor::Observer. |
| 48 void OnAppStart(Profile* profile, const std::string& app_id) override; | 50 void OnAppStart(content::BrowserContext* context, |
| 49 void OnAppActivated(Profile* profile, const std::string& app_id) override; | 51 const std::string& app_id) override; |
| 50 void OnAppDeactivated(Profile* profile, const std::string& app_id) override; | 52 void OnAppActivated(content::BrowserContext* context, |
| 51 void OnAppStop(Profile* profile, const std::string& app_id) override; | 53 const std::string& app_id) override; |
| 54 void OnAppDeactivated(content::BrowserContext* context, |
| 55 const std::string& app_id) override; |
| 56 void OnAppStop(content::BrowserContext* context, |
| 57 const std::string& app_id) override; |
| 52 | 58 |
| 53 // KeyedService. | 59 // KeyedService. |
| 54 void Shutdown() override; | 60 void Shutdown() override; |
| 55 | 61 |
| 56 void RecordAppStart(const std::string& extension_id); | 62 void RecordAppStart(const std::string& extension_id); |
| 57 void RecordAppStop(const std::string& extension_id); | 63 void RecordAppStop(const std::string& extension_id); |
| 58 void RecordAppActiveState(const std::string& id, bool is_active); | 64 void RecordAppActiveState(const std::string& id, bool is_active); |
| 59 | 65 |
| 60 void RestoreApp(const extensions::Extension* extension); | 66 void RestoreApp(const extensions::Extension* extension); |
| 61 | 67 |
| 62 void StartObservingAppLifetime(); | 68 void StartObservingAppLifetime(); |
| 63 void StopObservingAppLifetime(); | 69 void StopObservingAppLifetime(); |
| 64 | 70 |
| 65 Profile* profile_; | 71 content::BrowserContext* context_; |
| 66 | 72 |
| 67 DISALLOW_COPY_AND_ASSIGN(AppRestoreService); | 73 DISALLOW_COPY_AND_ASSIGN(AppRestoreService); |
| 68 }; | 74 }; |
| 69 | 75 |
| 70 } // namespace apps | 76 } // namespace apps |
| 71 | 77 |
| 72 #endif // APPS_APP_RESTORE_SERVICE_H_ | 78 #endif // APPS_APP_RESTORE_SERVICE_H_ |
| OLD | NEW |