Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / apps / ephemeral_app_service.h
blob2ea34f15cdb151f59ade404396b84063e89a1ef1
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 CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_
6 #define CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_
8 #include <map>
9 #include <set>
11 #include "base/timer/timer.h"
12 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
16 class Profile;
18 namespace extensions {
19 class Extension;
20 } // namespace extensions
22 // Performs the background garbage collection of ephemeral apps.
23 class EphemeralAppService : public BrowserContextKeyedService,
24 public content::NotificationObserver {
25 public:
26 // Returns the instance for the given profile. This is a convenience wrapper
27 // around EphemeralAppServiceFactory::GetForProfile.
28 static EphemeralAppService* Get(Profile* profile);
30 explicit EphemeralAppService(Profile* profile);
31 virtual ~EphemeralAppService();
33 // Constants exposed for testing purposes.
34 static const int kAppInactiveThreshold;
35 static const int kAppKeepThreshold;
36 static const int kMaxEphemeralAppsCount;
38 private:
39 // A map used to order the ephemeral apps by their last launch time.
40 typedef std::multimap<base::Time, std::string> LaunchTimeAppMap;
42 // content::NotificationObserver implementation.
43 virtual void Observe(int type,
44 const content::NotificationSource& source,
45 const content::NotificationDetails& details) OVERRIDE;
47 void Init();
48 void InitEphemeralAppCount();
50 // Garbage collect ephemeral apps.
51 void TriggerGarbageCollect(const base::TimeDelta& delay);
52 void GarbageCollectApps();
53 static void GetAppsToRemove(int app_count,
54 const LaunchTimeAppMap& app_launch_times,
55 std::set<std::string>* remove_app_ids);
57 Profile* profile_;
59 content::NotificationRegistrar registrar_;
61 base::OneShotTimer<EphemeralAppService> garbage_collect_timer_;
63 // The count of cached ephemeral apps.
64 int ephemeral_app_count_;
66 friend class EphemeralAppServiceTest;
67 friend class EphemeralAppServiceBrowserTest;
69 DISALLOW_COPY_AND_ASSIGN(EphemeralAppService);
72 #endif // CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_