[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | eb5c968 | 2013-03-04 02:55:00 | [diff] [blame] | 5 | #ifndef APPS_APP_RESTORE_SERVICE_H_ |
6 | #define APPS_APP_RESTORE_SERVICE_H_ | ||||
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 7 | |
[email protected] | c2e2b6d | 2013-01-22 02:23:29 | [diff] [blame] | 8 | #include <string> |
[email protected] | eb5c968 | 2013-03-04 02:55:00 | [diff] [blame] | 9 | #include <vector> |
[email protected] | c2e2b6d | 2013-01-22 02:23:29 | [diff] [blame] | 10 | |
[email protected] | 4b7111f2 | 2013-06-18 14:22:12 | [diff] [blame] | 11 | #include "apps/app_lifetime_monitor.h" |
[email protected] | f6d9b28 | 2013-08-09 11:03:20 | [diff] [blame] | 12 | #include "apps/shell_window_registry.h" |
[email protected] | 0dd6f203 | 2013-05-20 23:33:40 | [diff] [blame] | 13 | #include "components/browser_context_keyed_service/browser_context_keyed_service.h" |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 14 | |
[email protected] | b8816a4 | 2013-02-27 07:59:00 | [diff] [blame] | 15 | namespace extensions { |
16 | class Extension; | ||||
[email protected] | b897ff8 | 2013-02-27 19:50:13 | [diff] [blame] | 17 | } |
18 | |||||
19 | class Profile; | ||||
20 | |||||
[email protected] | c2e2b6d | 2013-01-22 02:23:29 | [diff] [blame] | 21 | namespace apps { |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 22 | |
23 | // Tracks what apps need to be restarted when the browser restarts. | ||||
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 24 | class AppRestoreService : public BrowserContextKeyedService, |
[email protected] | 4b7111f2 | 2013-06-18 14:22:12 | [diff] [blame] | 25 | public AppLifetimeMonitor::Observer { |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 26 | public: |
[email protected] | 24ced7dc0 | 2013-04-04 08:32:39 | [diff] [blame] | 27 | // Returns true if apps should be restored on the current platform, given |
28 | // whether this new browser process launched due to a restart. | ||||
29 | static bool ShouldRestoreApps(bool is_browser_restart); | ||||
30 | |||||
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 31 | explicit AppRestoreService(Profile* profile); |
32 | |||||
[email protected] | 11945462 | 2012-10-18 09:48:32 | [diff] [blame] | 33 | // Restart apps that need to be restarted and clear the "running" preference |
34 | // from apps to prevent them being restarted in subsequent restarts. | ||||
[email protected] | 300ba0c4 | 2012-12-06 06:57:17 | [diff] [blame] | 35 | void HandleStartup(bool should_restore_apps); |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 36 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 37 | // Returns whether this extension is running or, at startup, whether it was |
38 | // running when Chrome was last terminated. | ||||
39 | bool IsAppRestorable(const std::string& extension_id); | ||||
40 | |||||
41 | static AppRestoreService* Get(Profile* profile); | ||||
42 | |||||
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 43 | private: |
[email protected] | 4b7111f2 | 2013-06-18 14:22:12 | [diff] [blame] | 44 | // AppLifetimeMonitor::Observer. |
45 | virtual void OnAppStart(Profile* profile, const std::string& app_id) OVERRIDE; | ||||
46 | virtual void OnAppActivated(Profile* profile, | ||||
47 | const std::string& app_id) OVERRIDE; | ||||
48 | virtual void OnAppDeactivated(Profile* profile, | ||||
49 | const std::string& app_id) OVERRIDE; | ||||
50 | virtual void OnAppStop(Profile* profile, const std::string& app_id) OVERRIDE; | ||||
51 | virtual void OnChromeTerminating() OVERRIDE; | ||||
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 52 | |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 53 | // BrowserContextKeyedService. |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 54 | virtual void Shutdown() OVERRIDE; |
55 | |||||
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 56 | void RecordAppStart(const std::string& extension_id); |
57 | void RecordAppStop(const std::string& extension_id); | ||||
[email protected] | 4b7111f2 | 2013-06-18 14:22:12 | [diff] [blame] | 58 | void RecordAppActiveState(const std::string& id, bool is_active); |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 59 | |
[email protected] | 961745f | 2013-05-25 14:09:24 | [diff] [blame] | 60 | void RestoreApp(const extensions::Extension* extension); |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 61 | |
[email protected] | 4b7111f2 | 2013-06-18 14:22:12 | [diff] [blame] | 62 | void StartObservingAppLifetime(); |
63 | void StopObservingAppLifetime(); | ||||
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 64 | |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 65 | Profile* profile_; |
[email protected] | eb5c968 | 2013-03-04 02:55:00 | [diff] [blame] | 66 | |
67 | DISALLOW_COPY_AND_ASSIGN(AppRestoreService); | ||||
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 68 | }; |
69 | |||||
[email protected] | c2e2b6d | 2013-01-22 02:23:29 | [diff] [blame] | 70 | } // namespace apps |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 71 | |
[email protected] | eb5c968 | 2013-03-04 02:55:00 | [diff] [blame] | 72 | #endif // APPS_APP_RESTORE_SERVICE_H_ |