[M120 Migration][XWalkExtension] Support IME in xwalk exension
[platform/framework/web/chromium-efl.git] / apps / app_lifetime_monitor.h
1 // Copyright 2013 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_LIFETIME_MONITOR_H_
6 #define APPS_APP_LIFETIME_MONITOR_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/raw_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/scoped_observation.h"
14 #include "components/keyed_service/core/keyed_service.h"
15 #include "extensions/browser/app_window/app_window_registry.h"
16 #include "extensions/browser/extension_host_registry.h"
17
18 namespace content {
19 class BrowserContext;
20 }
21
22 namespace apps {
23
24 // Observes startup of apps and their windows and notifies observers of these
25 // events.
26 class AppLifetimeMonitor : public KeyedService,
27                            public extensions::AppWindowRegistry::Observer,
28                            public extensions::ExtensionHostRegistry::Observer {
29  public:
30   class Observer {
31    public:
32     // Called when the app starts running.
33     virtual void OnAppStart(content::BrowserContext* context,
34                             const std::string& app_id) {}
35     // Called when the app becomes active to the user, i.e. the first window
36     // becomes visible.
37     virtual void OnAppActivated(content::BrowserContext* context,
38                                 const std::string& app_id) {}
39     // Called when the app becomes inactive to the user, i.e. the last window is
40     // hidden or closed.
41     virtual void OnAppDeactivated(content::BrowserContext* context,
42                                   const std::string& app_id) {}
43     // Called when the app stops running.
44     virtual void OnAppStop(content::BrowserContext* context,
45                            const std::string& app_id) {}
46
47    protected:
48     virtual ~Observer() = default;
49   };
50
51   explicit AppLifetimeMonitor(content::BrowserContext* context);
52   AppLifetimeMonitor(const AppLifetimeMonitor&) = delete;
53   AppLifetimeMonitor& operator=(const AppLifetimeMonitor&) = delete;
54   ~AppLifetimeMonitor() override;
55
56   void AddObserver(Observer* observer);
57   void RemoveObserver(Observer* observer);
58
59  private:
60   // extensions::AppWindowRegistry::Observer overrides:
61   void OnAppWindowRemoved(extensions::AppWindow* app_window) override;
62   void OnAppWindowHidden(extensions::AppWindow* app_window) override;
63   void OnAppWindowShown(extensions::AppWindow* app_window,
64                         bool was_hidden) override;
65
66   // extensions::ExtensionHostRegistry::Observer:
67   void OnExtensionHostCompletedFirstLoad(
68       content::BrowserContext* browser_context,
69       extensions::ExtensionHost* host) override;
70   void OnExtensionHostDestroyed(content::BrowserContext* browser_context,
71                                 extensions::ExtensionHost* host) override;
72
73   // KeyedService overrides:
74   void Shutdown() override;
75
76   bool HasOtherVisibleAppWindows(extensions::AppWindow* app_window) const;
77
78   void NotifyAppStart(const std::string& app_id);
79   void NotifyAppActivated(const std::string& app_id);
80   void NotifyAppDeactivated(const std::string& app_id);
81   void NotifyAppStop(const std::string& app_id);
82
83   raw_ptr<content::BrowserContext> context_;
84   base::ObserverList<Observer>::Unchecked observers_;
85   base::ScopedObservation<extensions::ExtensionHostRegistry,
86                           extensions::ExtensionHostRegistry::Observer>
87       extension_host_registry_observation_{this};
88 };
89
90 }  // namespace apps
91
92 #endif  // APPS_APP_LIFETIME_MONITOR_H_