Adding more webview tests to app_shell_browsertests.
[chromium-blink-merge.git] / apps / app_lifetime_monitor.h
blob9dfee75e6c1c16f705e810d57325b467b6321b8a
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. it opens a window.
36 virtual void OnAppActivated(Profile* profile, const std::string& app_id) {}
37 // Called when the app becomes inactive to the user.
38 virtual void OnAppDeactivated(Profile* profile, const std::string& app_id) {
40 // Called when the app stops running.
41 virtual void OnAppStop(Profile* profile, const std::string& app_id) {}
42 // Called when chrome is about to terminate. This gives observers a chance
43 // to do something before the apps shut down. This is a system-wide event
44 // so there is no associated profile and app id.
45 virtual void OnChromeTerminating() {}
47 protected:
48 virtual ~Observer() {}
51 explicit AppLifetimeMonitor(Profile* profile);
52 virtual ~AppLifetimeMonitor();
54 void AddObserver(Observer* observer);
55 void RemoveObserver(Observer* observer);
57 private:
58 // content::NotificationObserver overrides:
59 virtual void Observe(int type,
60 const content::NotificationSource& source,
61 const content::NotificationDetails& details) OVERRIDE;
63 // extensions::AppWindowRegistry::Observer overrides:
64 virtual void OnAppWindowRemoved(extensions::AppWindow* app_window) OVERRIDE;
65 virtual void OnAppWindowHidden(extensions::AppWindow* app_window) OVERRIDE;
66 virtual void OnAppWindowShown(extensions::AppWindow* app_window) OVERRIDE;
68 // KeyedService overrides:
69 virtual void Shutdown() OVERRIDE;
71 bool HasVisibleAppWindows(extensions::AppWindow* app_window) const;
73 void NotifyAppStart(const std::string& app_id);
74 void NotifyAppActivated(const std::string& app_id);
75 void NotifyAppDeactivated(const std::string& app_id);
76 void NotifyAppStop(const std::string& app_id);
77 void NotifyChromeTerminating();
79 content::NotificationRegistrar registrar_;
80 Profile* profile_;
81 ObserverList<Observer> observers_;
83 DISALLOW_COPY_AND_ASSIGN(AppLifetimeMonitor);
86 } // namespace apps
88 #endif // APPS_APP_LIFETIME_MONITOR_H_