#ifndef CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_
#define CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_
#include <map>
#include <set>
#include "base/timer/timer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Profile;
namespace extensions {
class Extension;
}
class EphemeralAppService : public KeyedService,
public content::NotificationObserver {
public:
static EphemeralAppService* Get(Profile* profile);
explicit EphemeralAppService(Profile* profile);
virtual ~EphemeralAppService();
static const int kAppInactiveThreshold;
static const int kAppKeepThreshold;
static const int kMaxEphemeralAppsCount;
static const int kDataInactiveThreshold;
private:
typedef std::multimap<base::Time, std::string> LaunchTimeAppMap;
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void Init();
void InitEphemeralAppCount();
void TriggerGarbageCollect(const base::TimeDelta& delay);
void GarbageCollectApps();
static void GetAppsToRemove(int app_count,
const LaunchTimeAppMap& app_launch_times,
std::set<std::string>* remove_app_ids);
void GarbageCollectData();
Profile* profile_;
content::NotificationRegistrar registrar_;
base::OneShotTimer<EphemeralAppService> garbage_collect_apps_timer_;
base::OneShotTimer<EphemeralAppService> garbage_collect_data_timer_;
int ephemeral_app_count_;
friend class EphemeralAppBrowserTest;
friend class EphemeralAppServiceTest;
friend class EphemeralAppServiceBrowserTest;
DISALLOW_COPY_AND_ASSIGN(EphemeralAppService);
};
#endif