#ifndef APPS_APP_LIFETIME_MONITOR_H_
#define APPS_APP_LIFETIME_MONITOR_H_
#include <string>
#include <vector>
#include "apps/app_window_registry.h"
#include "base/observer_list.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
namespace extensions {
class Extension;
}
class Profile;
namespace apps {
class AppLifetimeMonitor : public KeyedService,
public content::NotificationObserver,
public AppWindowRegistry::Observer {
public:
class Observer {
public:
virtual void OnAppStart(Profile* profile, const std::string& app_id) = 0;
virtual void OnAppActivated(Profile* profile,
const std::string& app_id) = 0;
virtual void OnAppDeactivated(Profile* profile,
const std::string& app_id) = 0;
virtual void OnAppStop(Profile* profile, const std::string& app_id) = 0;
virtual void OnChromeTerminating() = 0;
protected:
virtual ~Observer() {}
};
explicit AppLifetimeMonitor(Profile* profile);
virtual ~AppLifetimeMonitor();
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
private:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
virtual void OnAppWindowAdded(AppWindow* app_window) OVERRIDE;
virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE;
virtual void OnAppWindowRemoved(AppWindow* app_window) OVERRIDE;
virtual void Shutdown() OVERRIDE;
void NotifyAppStart(const std::string& app_id);
void NotifyAppActivated(const std::string& app_id);
void NotifyAppDeactivated(const std::string& app_id);
void NotifyAppStop(const std::string& app_id);
void NotifyChromeTerminating();
content::NotificationRegistrar registrar_;
Profile* profile_;
ObserverList<Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(AppLifetimeMonitor);
};
}
#endif