[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] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 11 | #include "chrome/browser/extensions/shell_window_registry.h" |
[email protected] | 0dd6f203 | 2013-05-20 23:33:40 | [diff] [blame] | 12 | #include "components/browser_context_keyed_service/browser_context_keyed_service.h" |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 13 | #include "content/public/browser/notification_observer.h" |
14 | #include "content/public/browser/notification_registrar.h" | ||||
15 | |||||
[email protected] | b8816a4 | 2013-02-27 07:59:00 | [diff] [blame] | 16 | namespace extensions { |
17 | class Extension; | ||||
[email protected] | b897ff87 | 2013-02-27 19:50:13 | [diff] [blame] | 18 | } |
19 | |||||
20 | class Profile; | ||||
21 | |||||
[email protected] | c2e2b6d | 2013-01-22 02:23:29 | [diff] [blame] | 22 | namespace apps { |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 23 | |
24 | // Tracks what apps need to be restarted when the browser restarts. | ||||
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 25 | class AppRestoreService : public BrowserContextKeyedService, |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 26 | public content::NotificationObserver, |
[email protected] | 4abde49 | 2013-06-06 14:13:00 | [diff] [blame] | 27 | public extensions::ShellWindowRegistry::Observer { |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 28 | public: |
[email protected] | 24ced7dc0 | 2013-04-04 08:32:39 | [diff] [blame] | 29 | // Returns true if apps should be restored on the current platform, given |
30 | // whether this new browser process launched due to a restart. | ||||
31 | static bool ShouldRestoreApps(bool is_browser_restart); | ||||
32 | |||||
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 33 | explicit AppRestoreService(Profile* profile); |
34 | |||||
[email protected] | 11945462 | 2012-10-18 09:48:32 | [diff] [blame] | 35 | // Restart apps that need to be restarted and clear the "running" preference |
36 | // from apps to prevent them being restarted in subsequent restarts. | ||||
[email protected] | 300ba0c4 | 2012-12-06 06:57:17 | [diff] [blame] | 37 | void HandleStartup(bool should_restore_apps); |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 38 | |
[email protected] | a2886e8b | 2013-06-08 05:15:02 | [diff] [blame^] | 39 | // Returns whether this extension is running or, at startup, whether it was |
40 | // running when Chrome was last terminated. | ||||
41 | bool IsAppRestorable(const std::string& extension_id); | ||||
42 | |||||
43 | static AppRestoreService* Get(Profile* profile); | ||||
44 | |||||
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 45 | private: |
46 | // content::NotificationObserver. | ||||
47 | virtual void Observe(int type, | ||||
48 | const content::NotificationSource& source, | ||||
49 | const content::NotificationDetails& details) OVERRIDE; | ||||
50 | |||||
[email protected] | 4abde49 | 2013-06-06 14:13:00 | [diff] [blame] | 51 | // extensions::ShellWindowRegistry::Observer. |
52 | virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE; | ||||
53 | virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE; | ||||
54 | virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE; | ||||
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 55 | |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 56 | // BrowserContextKeyedService. |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 57 | virtual void Shutdown() OVERRIDE; |
58 | |||||
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 59 | void RecordAppStart(const std::string& extension_id); |
60 | void RecordAppStop(const std::string& extension_id); | ||||
[email protected] | 4abde49 | 2013-06-06 14:13:00 | [diff] [blame] | 61 | void RecordIfAppHasWindows(const std::string& id); |
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 62 | |
[email protected] | 961745f | 2013-05-25 14:09:24 | [diff] [blame] | 63 | void RestoreApp(const extensions::Extension* extension); |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 64 | |
[email protected] | 4abde49 | 2013-06-06 14:13:00 | [diff] [blame] | 65 | void StartObservingShellWindows(); |
66 | void StopObservingShellWindows(); | ||||
[email protected] | 771c8d27 | 2013-05-17 09:47:40 | [diff] [blame] | 67 | |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 68 | content::NotificationRegistrar registrar_; |
69 | Profile* profile_; | ||||
[email protected] | eb5c968 | 2013-03-04 02:55:00 | [diff] [blame] | 70 | |
71 | DISALLOW_COPY_AND_ASSIGN(AppRestoreService); | ||||
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 72 | }; |
73 | |||||
[email protected] | c2e2b6d | 2013-01-22 02:23:29 | [diff] [blame] | 74 | } // namespace apps |
[email protected] | 28c3eeb | 2012-10-15 05:47:53 | [diff] [blame] | 75 | |
[email protected] | eb5c968 | 2013-03-04 02:55:00 | [diff] [blame] | 76 | #endif // APPS_APP_RESTORE_SERVICE_H_ |