Upload upstream chromium 76.0.3809.146
[platform/framework/web/chromium-efl.git] / apps / app_restore_service.h
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
5 #ifndef APPS_APP_RESTORE_SERVICE_H_
6 #define APPS_APP_RESTORE_SERVICE_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "apps/app_lifetime_monitor.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "extensions/browser/app_window/app_window_registry.h"
14
15 namespace extensions {
16 class Extension;
17 }
18
19 namespace content {
20 class BrowserContext;
21 }
22
23 namespace apps {
24
25 // Tracks what apps need to be restarted when the browser restarts.
26 class AppRestoreService : public KeyedService,
27                           public AppLifetimeMonitor::Observer {
28  public:
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
33   explicit AppRestoreService(content::BrowserContext* context);
34
35   // Restart apps that need to be restarted and clear the "running" preference
36   // from apps to prevent them being restarted in subsequent restarts.
37   void HandleStartup(bool should_restore_apps);
38
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   // Called to notify that the application has begun to exit.
44   void OnApplicationTerminating();
45
46   static AppRestoreService* Get(content::BrowserContext* context);
47
48  private:
49   // AppLifetimeMonitor::Observer.
50   void OnAppStart(content::BrowserContext* context,
51                   const std::string& app_id) override;
52   void OnAppActivated(content::BrowserContext* context,
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;
58
59   // KeyedService.
60   void Shutdown() override;
61
62   void RecordAppStart(const std::string& extension_id);
63   void RecordAppStop(const std::string& extension_id);
64   void RecordAppActiveState(const std::string& id, bool is_active);
65
66   void RestoreApp(const extensions::Extension* extension);
67
68   void StartObservingAppLifetime();
69   void StopObservingAppLifetime();
70
71   content::BrowserContext* context_;
72
73   DISALLOW_COPY_AND_ASSIGN(AppRestoreService);
74 };
75
76 }  // namespace apps
77
78 #endif  // APPS_APP_RESTORE_SERVICE_H_