[M120 Migration][XWalkExtension] Support IME in xwalk exension
[platform/framework/web/chromium-efl.git] / apps / app_restore_service.h
1 // Copyright 2012 The Chromium Authors
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 "base/memory/raw_ptr.h"
13 #include "components/keyed_service/core/keyed_service.h"
14 #include "extensions/browser/app_window/app_window_registry.h"
15
16 namespace extensions {
17 class Extension;
18 }
19
20 namespace content {
21 class BrowserContext;
22 }
23
24 namespace apps {
25
26 // Tracks what apps need to be restarted when the browser restarts.
27 class AppRestoreService : public KeyedService,
28                           public AppLifetimeMonitor::Observer {
29  public:
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
34   explicit AppRestoreService(content::BrowserContext* context);
35   AppRestoreService(const AppRestoreService&) = delete;
36   AppRestoreService& operator=(const AppRestoreService&) = delete;
37
38   // Restart apps that need to be restarted and clear the "running" preference
39   // from apps to prevent them being restarted in subsequent restarts.
40   void HandleStartup(bool should_restore_apps);
41
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
46   // Called to notify that the application has begun to exit.
47   void OnApplicationTerminating();
48
49   static AppRestoreService* Get(content::BrowserContext* context);
50
51  private:
52   // AppLifetimeMonitor::Observer.
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;
61
62   // KeyedService.
63   void Shutdown() override;
64
65   void RecordAppStart(const std::string& extension_id);
66   void RecordAppStop(const std::string& extension_id);
67   void RecordAppActiveState(const std::string& id, bool is_active);
68
69   void RestoreApp(const extensions::Extension* extension);
70
71   void StartObservingAppLifetime();
72   void StopObservingAppLifetime();
73
74   raw_ptr<content::BrowserContext> context_;
75 };
76
77 }  // namespace apps
78
79 #endif  // APPS_APP_RESTORE_SERVICE_H_