Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1715)

Unified Diff: chrome/browser/apps/ephemeral_app_service.cc

Issue 383703002: Clear the ephemeral app cache from Clear Browsing Data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments for tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/apps/ephemeral_app_service.cc
diff --git a/chrome/browser/apps/ephemeral_app_service.cc b/chrome/browser/apps/ephemeral_app_service.cc
index da4a5d19ab9b5b79956e6ffd82be4a38ea52e4de..de05309a3670c1d224e7d1c1167813b2d00d6ef1 100644
--- a/chrome/browser/apps/ephemeral_app_service.cc
+++ b/chrome/browser/apps/ephemeral_app_service.cc
@@ -23,6 +23,7 @@
using extensions::Extension;
using extensions::ExtensionPrefs;
+using extensions::ExtensionRegistry;
using extensions::ExtensionSet;
using extensions::ExtensionSystem;
@@ -60,8 +61,7 @@ EphemeralAppService::EphemeralAppService(Profile* profile)
switches::kEnableEphemeralApps))
return;
- extension_registry_observer_.Add(
- extensions::ExtensionRegistry::Get(profile_));
+ extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
@@ -71,6 +71,41 @@ EphemeralAppService::EphemeralAppService(Profile* profile)
EphemeralAppService::~EphemeralAppService() {
}
+void EphemeralAppService::ClearCachedApps() {
+ // Cancel any pending garbage collects.
+ garbage_collect_apps_timer_.Stop();
+
+ ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
+ DCHECK(registry);
+ ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
+ DCHECK(prefs);
+ ExtensionService* service =
+ ExtensionSystem::Get(profile_)->extension_service();
+ DCHECK(service);
+
+ scoped_ptr<ExtensionSet> extensions =
+ registry->GenerateInstalledExtensionsSet();
+
+ for (ExtensionSet::const_iterator it = extensions->begin();
+ it != extensions->end();
+ ++it) {
+ std::string extension_id = (*it)->id();
+ if (!prefs->IsEphemeralApp(extension_id))
+ continue;
+
+ // Do not remove apps that are running.
+ if (!extensions::util::IsExtensionIdle(extension_id, profile_))
+ continue;
+
+ DCHECK(registry->GetExtensionById(extension_id,
+ ExtensionRegistry::EVERYTHING));
+ service->UninstallExtension(
+ extension_id,
+ ExtensionService::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION,
+ NULL);
+ }
+}
+
void EphemeralAppService::Observe(
int type,
const content::NotificationSource& source,
@@ -127,8 +162,7 @@ void EphemeralAppService::Init() {
void EphemeralAppService::InitEphemeralAppCount() {
scoped_ptr<ExtensionSet> extensions =
- extensions::ExtensionRegistry::Get(profile_)
- ->GenerateInstalledExtensionsSet();
+ ExtensionRegistry::Get(profile_)->GenerateInstalledExtensionsSet();
ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
DCHECK(prefs);
@@ -152,12 +186,14 @@ void EphemeralAppService::TriggerGarbageCollect(const base::TimeDelta& delay) {
}
void EphemeralAppService::GarbageCollectApps() {
- scoped_ptr<ExtensionSet> extensions =
- extensions::ExtensionRegistry::Get(profile_)
- ->GenerateInstalledExtensionsSet();
+ ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
+ DCHECK(registry);
ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
DCHECK(prefs);
+ scoped_ptr<ExtensionSet> extensions =
+ registry->GenerateInstalledExtensionsSet();
+
int app_count = 0;
LaunchTimeAppMap app_launch_times;
std::set<std::string> remove_app_ids;
@@ -189,21 +225,22 @@ void EphemeralAppService::GarbageCollectApps() {
ExtensionService* service =
ExtensionSystem::Get(profile_)->extension_service();
DCHECK(service);
- // Execute the replacement policies and remove apps marked for deletion.
+ // Execute the eviction policies and remove apps marked for deletion.
if (!app_launch_times.empty()) {
GetAppsToRemove(app_count, app_launch_times, &remove_app_ids);
+
for (std::set<std::string>::const_iterator id = remove_app_ids.begin();
id != remove_app_ids.end(); ++id) {
- if (service->UninstallExtension(
- *id,
- ExtensionService::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION,
- NULL)) {
- --app_count;
- }
+ // Protect against cascading uninstalls.
+ if (!registry->GetExtensionById(*id, ExtensionRegistry::EVERYTHING))
+ continue;
+
+ service->UninstallExtension(
+ *id,
+ ExtensionService::UNINSTALL_REASON_ORPHANED_EPHEMERAL_EXTENSION,
+ NULL);
}
}
-
- ephemeral_app_count_ = app_count;
}
// static

Powered by Google App Engine
This is Rietveld 408576698