Remove existing Skia suppressions
[chromium-blink-merge.git] / apps / app_lifetime_monitor.h
blobdd2d7931a133a5a1e4711e0f59da9001f77ebf62
1 // Copyright 2013 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.
5 #ifndef APPS_APP_LIFETIME_MONITOR_H_
6 #define APPS_APP_LIFETIME_MONITOR_H_
8 #include <string>
9 #include <vector>
11 #include "base/observer_list.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "extensions/browser/app_window/app_window_registry.h"
17 namespace extensions {
18 class Extension;
21 class Profile;
23 namespace apps {
25 // Observes startup of apps and their windows and notifies observers of these
26 // events.
27 class AppLifetimeMonitor : public KeyedService,
28 public content::NotificationObserver,
29 public extensions::AppWindowRegistry::Observer {
30 public:
31 class Observer {
32 public:
33 // Called when the app starts running.
34 virtual void OnAppStart(Profile* profile, 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(Profile* profile, const std::string& app_id) {}
38 // Called when the app becomes inactive to the user, i.e. the last window is
39 // hidden or closed.
40 virtual void OnAppDeactivated(Profile* profile, const std::string& app_id) {
42 // Called when the app stops running.
43 virtual void OnAppStop(Profile* profile, const std::string& app_id) {}
44 // Called when chrome is about to terminate. This gives observers a chance
45 // to do something before the apps shut down. This is a system-wide event
46 // so there is no associated profile and app id.
47 virtual void OnChromeTerminating() {}
49 protected:
50 virtual ~Observer() {}
53 explicit AppLifetimeMonitor(Profile* profile);
54 ~AppLifetimeMonitor() override;
56 void AddObserver(Observer* observer);
57 void RemoveObserver(Observer* observer);
59 private:
60 // content::NotificationObserver overrides:
61 void Observe(int type,
62 const content::NotificationSource& source,
63 const content::NotificationDetails& details) override;
65 // extensions::AppWindowRegistry::Observer overrides:
66 void OnAppWindowRemoved(extensions::AppWindow* app_window) override;
67 void OnAppWindowHidden(extensions::AppWindow* app_window) override;
68 void OnAppWindowShown(extensions::AppWindow* app_window,
69 bool was_hidden) override;
71 // KeyedService overrides:
72 void Shutdown() override;
74 bool HasOtherVisibleAppWindows(extensions::AppWindow* app_window) const;
76 void NotifyAppStart(const std::string& app_id);
77 void NotifyAppActivated(const std::string& app_id);
78 void NotifyAppDeactivated(const std::string& app_id);
79 void NotifyAppStop(const std::string& app_id);
80 void NotifyChromeTerminating();
82 content::NotificationRegistrar registrar_;
83 Profile* profile_;
84 base::ObserverList<Observer> observers_;
86 DISALLOW_COPY_AND_ASSIGN(AppLifetimeMonitor);
89 } // namespace apps
91 #endif // APPS_APP_LIFETIME_MONITOR_H_