Avi Drissman | da6cecbc | 2022-09-07 18:10:30 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 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" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 12 | #include "base/memory/raw_ptr.h" |
[email protected] | 12b7af3 | 2014-03-13 05:28:20 | [diff] [blame] | 13 | #include "components/keyed_service/core/keyed_service.h" |
hashimoto | ad3c687 | 2014-08-29 09:46:57 | [diff] [blame] | 14 | #include "extensions/browser/app_window/app_window_registry.h" |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 15 | |
[email protected] | b8816a4 | 2013-02-27 07:59:00 | [diff] [blame] | 16 | namespace extensions { |
17 | class Extension; | ||||
[email protected] | b897ff8 | 2013-02-27 19:50:13 | [diff] [blame] | 18 | } |
19 | |||||
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 20 | namespace content { |
21 | class BrowserContext; | ||||
22 | } | ||||
[email protected] | b897ff8 | 2013-02-27 19:50:13 | [diff] [blame] | 23 | |
[email protected] | c2e2b6d | 2013-01-22 02:23:29 | [diff] [blame] | 24 | namespace apps { |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 25 | |
26 | // Tracks what apps need to be restarted when the browser restarts. | ||||
[email protected] | 12b7af3 | 2014-03-13 05:28:20 | [diff] [blame] | 27 | class AppRestoreService : public KeyedService, |
[email protected] | 4b7111f2 | 2013-06-18 14:22:12 | [diff] [blame] | 28 | public AppLifetimeMonitor::Observer { |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 29 | public: |
[email protected] | 24ced7dc0 | 2013-04-04 08:32:39 | [diff] [blame] | 30 | // Returns true if apps should be restored on the current platform, given |
31 | // whether this new browser process launched due to a restart. | ||||
32 | static bool ShouldRestoreApps(bool is_browser_restart); | ||||
33 | |||||
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 34 | explicit AppRestoreService(content::BrowserContext* context); |
David Bienvenu | b4b5b57 | 2020-09-28 00:49:27 | [diff] [blame] | 35 | AppRestoreService(const AppRestoreService&) = delete; |
36 | AppRestoreService& operator=(const AppRestoreService&) = delete; | ||||
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 37 | |
[email protected] | 11945462 | 2012-10-18 09:48:32 | [diff] [blame] | 38 | // Restart apps that need to be restarted and clear the "running" preference |
39 | // from apps to prevent them being restarted in subsequent restarts. | ||||
[email protected] | 300ba0c4 | 2012-12-06 06:57:17 | [diff] [blame] | 40 | void HandleStartup(bool should_restore_apps); |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 41 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 42 | // Returns whether this extension is running or, at startup, whether it was |
43 | // running when Chrome was last terminated. | ||||
44 | bool IsAppRestorable(const std::string& extension_id); | ||||
45 | |||||
michaelpg | 2fc6af9 | 2017-01-13 19:54:18 | [diff] [blame] | 46 | // Called to notify that the application has begun to exit. |
47 | void OnApplicationTerminating(); | ||||
48 | |||||
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 49 | static AppRestoreService* Get(content::BrowserContext* context); |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame] | 50 | |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 51 | private: |
[email protected] | 4b7111f2 | 2013-06-18 14:22:12 | [diff] [blame] | 52 | // AppLifetimeMonitor::Observer. |
michaelpg | 4d80e56 | 2017-04-04 01:48:14 | [diff] [blame] | 53 | void OnAppStart(content::BrowserContext* context, |
54 | const std::string& app_id) override; | ||||
55 | void OnAppActivated(content::BrowserContext* context, | ||||
56 | const std::string& app_id) override; | ||||
57 | void OnAppDeactivated(content::BrowserContext* context, | ||||
58 | const std::string& app_id) override; | ||||
59 | void OnAppStop(content::BrowserContext* context, | ||||
60 | const std::string& app_id) override; | ||||
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 61 | |
[email protected] | 12b7af3 | 2014-03-13 05:28:20 | [diff] [blame] | 62 | // KeyedService. |
dcheng | 2f5be41 | 2014-10-22 01:46:08 | [diff] [blame] | 63 | void Shutdown() override; |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 64 | |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 65 | void RecordAppStart(const std::string& extension_id); |
66 | void RecordAppStop(const std::string& extension_id); | ||||
[email protected] | 4b7111f2 | 2013-06-18 14:22:12 | [diff] [blame] | 67 | void RecordAppActiveState(const std::string& id, bool is_active); |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 68 | |
[email protected] | 961745f | 2013-05-25 14:09:24 | [diff] [blame] | 69 | void RestoreApp(const extensions::Extension* extension); |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 70 | |
[email protected] | 4b7111f2 | 2013-06-18 14:22:12 | [diff] [blame] | 71 | void StartObservingAppLifetime(); |
72 | void StopObservingAppLifetime(); | ||||
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 73 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 74 | raw_ptr<content::BrowserContext> context_; |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 75 | }; |
76 | |||||
[email protected] | c2e2b6d | 2013-01-22 02:23:29 | [diff] [blame] | 77 | } // namespace apps |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 78 | |
[email protected] | eb5c968 | 2013-03-04 02:55:00 | [diff] [blame] | 79 | #endif // APPS_APP_RESTORE_SERVICE_H_ |