| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_ |
| 6 #define CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_ | 6 #define CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/scoped_observer.h" |
| 11 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" | 13 #include "components/keyed_service/core/keyed_service.h" |
| 13 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 16 #include "extensions/browser/extension_registry_observer.h" |
| 15 | 17 |
| 16 class Profile; | 18 class Profile; |
| 17 | 19 |
| 18 namespace extensions { | 20 namespace extensions { |
| 19 class Extension; | 21 class Extension; |
| 22 class ExtensionRegistry; |
| 20 } // namespace extensions | 23 } // namespace extensions |
| 21 | 24 |
| 22 // Performs the background garbage collection of ephemeral apps. | 25 // Performs the background garbage collection of ephemeral apps. |
| 23 class EphemeralAppService : public KeyedService, | 26 class EphemeralAppService : public KeyedService, |
| 24 public content::NotificationObserver { | 27 public content::NotificationObserver, |
| 28 public extensions::ExtensionRegistryObserver { |
| 25 public: | 29 public: |
| 26 // Returns the instance for the given profile. This is a convenience wrapper | 30 // Returns the instance for the given profile. This is a convenience wrapper |
| 27 // around EphemeralAppServiceFactory::GetForProfile. | 31 // around EphemeralAppServiceFactory::GetForProfile. |
| 28 static EphemeralAppService* Get(Profile* profile); | 32 static EphemeralAppService* Get(Profile* profile); |
| 29 | 33 |
| 30 explicit EphemeralAppService(Profile* profile); | 34 explicit EphemeralAppService(Profile* profile); |
| 31 virtual ~EphemeralAppService(); | 35 virtual ~EphemeralAppService(); |
| 32 | 36 |
| 33 // Constants exposed for testing purposes: | 37 // Constants exposed for testing purposes: |
| 34 | 38 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 | 49 |
| 46 private: | 50 private: |
| 47 // A map used to order the ephemeral apps by their last launch time. | 51 // A map used to order the ephemeral apps by their last launch time. |
| 48 typedef std::multimap<base::Time, std::string> LaunchTimeAppMap; | 52 typedef std::multimap<base::Time, std::string> LaunchTimeAppMap; |
| 49 | 53 |
| 50 // content::NotificationObserver implementation. | 54 // content::NotificationObserver implementation. |
| 51 virtual void Observe(int type, | 55 virtual void Observe(int type, |
| 52 const content::NotificationSource& source, | 56 const content::NotificationSource& source, |
| 53 const content::NotificationDetails& details) OVERRIDE; | 57 const content::NotificationDetails& details) OVERRIDE; |
| 54 | 58 |
| 59 // extensions::ExtensionRegistryObserver. |
| 60 virtual void OnExtensionWillBeInstalled( |
| 61 content::BrowserContext* browser_context, |
| 62 const extensions::Extension* extension, |
| 63 bool is_update, |
| 64 const std::string& old_name) OVERRIDE; |
| 65 virtual void OnExtensionUninstalled( |
| 66 content::BrowserContext* browser_context, |
| 67 const extensions::Extension* extension) OVERRIDE; |
| 68 |
| 55 void Init(); | 69 void Init(); |
| 56 void InitEphemeralAppCount(); | 70 void InitEphemeralAppCount(); |
| 57 | 71 |
| 58 // Garbage collect ephemeral apps. | 72 // Garbage collect ephemeral apps. |
| 59 void TriggerGarbageCollect(const base::TimeDelta& delay); | 73 void TriggerGarbageCollect(const base::TimeDelta& delay); |
| 60 void GarbageCollectApps(); | 74 void GarbageCollectApps(); |
| 61 static void GetAppsToRemove(int app_count, | 75 static void GetAppsToRemove(int app_count, |
| 62 const LaunchTimeAppMap& app_launch_times, | 76 const LaunchTimeAppMap& app_launch_times, |
| 63 std::set<std::string>* remove_app_ids); | 77 std::set<std::string>* remove_app_ids); |
| 64 | 78 |
| 65 // Garbage collect the data of ephemeral apps that have been evicted and | 79 // Garbage collect the data of ephemeral apps that have been evicted and |
| 66 // inactive for a long period of time. | 80 // inactive for a long period of time. |
| 67 void GarbageCollectData(); | 81 void GarbageCollectData(); |
| 68 | 82 |
| 69 Profile* profile_; | 83 Profile* profile_; |
| 70 | 84 |
| 71 content::NotificationRegistrar registrar_; | 85 content::NotificationRegistrar registrar_; |
| 72 | 86 |
| 87 ScopedObserver<extensions::ExtensionRegistry, |
| 88 extensions::ExtensionRegistryObserver> |
| 89 extension_registry_observer_; |
| 90 |
| 73 base::OneShotTimer<EphemeralAppService> garbage_collect_apps_timer_; | 91 base::OneShotTimer<EphemeralAppService> garbage_collect_apps_timer_; |
| 74 base::OneShotTimer<EphemeralAppService> garbage_collect_data_timer_; | 92 base::OneShotTimer<EphemeralAppService> garbage_collect_data_timer_; |
| 75 | 93 |
| 76 // The count of cached ephemeral apps. | 94 // The count of cached ephemeral apps. |
| 77 int ephemeral_app_count_; | 95 int ephemeral_app_count_; |
| 78 | 96 |
| 79 friend class EphemeralAppBrowserTest; | 97 friend class EphemeralAppBrowserTest; |
| 80 friend class EphemeralAppServiceTest; | 98 friend class EphemeralAppServiceTest; |
| 81 friend class EphemeralAppServiceBrowserTest; | 99 friend class EphemeralAppServiceBrowserTest; |
| 82 | 100 |
| 83 DISALLOW_COPY_AND_ASSIGN(EphemeralAppService); | 101 DISALLOW_COPY_AND_ASSIGN(EphemeralAppService); |
| 84 }; | 102 }; |
| 85 | 103 |
| 86 #endif // CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_ | 104 #endif // CHROME_BROWSER_APPS_EPHEMERAL_APP_SERVICE_H_ |
| OLD | NEW |