diff options
author | tmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-16 21:52:23 +0000 |
---|---|---|
committer | tmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-16 21:52:23 +0000 |
commit | 3e15d1ec9375b797f673f98e8bec3b14a487f30f (patch) | |
tree | 284c9bb4908bbb893669a23d3408dab055c3c4e3 | |
parent | f507ede65ca78409c34b41ccc4756b0ded98e061 (diff) | |
download | chromium_src-3e15d1ec9375b797f673f98e8bec3b14a487f30f.zip chromium_src-3e15d1ec9375b797f673f98e8bec3b14a487f30f.tar.gz chromium_src-3e15d1ec9375b797f673f98e8bec3b14a487f30f.tar.bz2 |
Clear the ephemeral app cache from Clear Browsing Data
Selecting the "Cached images and files" in the Clear Browsing Data
dialog will now remove all idle ephemeral apps.
BUG=392007
TEST=browser_tests
Review URL: https://codereview.chromium.org/383703002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283529 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/apps/ephemeral_app_browsertest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/apps/ephemeral_app_browsertest.h | 1 | ||||
-rw-r--r-- | chrome/browser/apps/ephemeral_app_service.cc | 69 | ||||
-rw-r--r-- | chrome/browser/apps/ephemeral_app_service.h | 3 | ||||
-rw-r--r-- | chrome/browser/apps/ephemeral_app_service_browsertest.cc | 47 | ||||
-rw-r--r-- | chrome/browser/browsing_data/browsing_data_remover.cc | 6 |
6 files changed, 102 insertions, 27 deletions
diff --git a/chrome/browser/apps/ephemeral_app_browsertest.cc b/chrome/browser/apps/ephemeral_app_browsertest.cc index 7e77075..213c7c96 100644 --- a/chrome/browser/apps/ephemeral_app_browsertest.cc +++ b/chrome/browser/apps/ephemeral_app_browsertest.cc @@ -53,7 +53,6 @@ namespace { namespace alarms = extensions::api::alarms; -const char kDispatchEventTestApp[] = "ephemeral_apps/dispatch_event"; const char kNotificationsTestApp[] = "ephemeral_apps/notification_settings"; const char kFileSystemTestApp[] = "ephemeral_apps/filesystem_retain_entries"; @@ -123,6 +122,8 @@ const char EphemeralAppTestBase::kMessagingReceiverApp[] = "ephemeral_apps/messaging_receiver"; const char EphemeralAppTestBase::kMessagingReceiverAppV2[] = "ephemeral_apps/messaging_receiver2"; +const char EphemeralAppTestBase::kDispatchEventTestApp[] = + "ephemeral_apps/dispatch_event"; EphemeralAppTestBase::EphemeralAppTestBase() {} diff --git a/chrome/browser/apps/ephemeral_app_browsertest.h b/chrome/browser/apps/ephemeral_app_browsertest.h index 21a6d9a..30746ba 100644 --- a/chrome/browser/apps/ephemeral_app_browsertest.h +++ b/chrome/browser/apps/ephemeral_app_browsertest.h @@ -20,6 +20,7 @@ class EphemeralAppTestBase : public extensions::PlatformAppBrowserTest { public: static const char kMessagingReceiverApp[]; static const char kMessagingReceiverAppV2[]; + static const char kDispatchEventTestApp[]; EphemeralAppTestBase(); virtual ~EphemeralAppTestBase(); diff --git a/chrome/browser/apps/ephemeral_app_service.cc b/chrome/browser/apps/ephemeral_app_service.cc index da4a5d1..de05309 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 diff --git a/chrome/browser/apps/ephemeral_app_service.h b/chrome/browser/apps/ephemeral_app_service.h index ee4b9b1..367c554 100644 --- a/chrome/browser/apps/ephemeral_app_service.h +++ b/chrome/browser/apps/ephemeral_app_service.h @@ -34,6 +34,9 @@ class EphemeralAppService : public KeyedService, explicit EphemeralAppService(Profile* profile); virtual ~EphemeralAppService(); + // Clears the ephemeral app cache. Removes all idle ephemeral apps. + void ClearCachedApps(); + int ephemeral_app_count() const { return ephemeral_app_count_; } // Constants exposed for testing purposes: diff --git a/chrome/browser/apps/ephemeral_app_service_browsertest.cc b/chrome/browser/apps/ephemeral_app_service_browsertest.cc index 9ecf7a8..c1b8c2d 100644 --- a/chrome/browser/apps/ephemeral_app_service_browsertest.cc +++ b/chrome/browser/apps/ephemeral_app_service_browsertest.cc @@ -6,16 +6,15 @@ #include "chrome/browser/apps/ephemeral_app_browsertest.h" #include "chrome/browser/apps/ephemeral_app_service.h" -#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "content/public/test/test_utils.h" #include "extensions/browser/extension_prefs.h" -#include "extensions/browser/extension_system.h" +#include "extensions/browser/extension_registry.h" #include "extensions/common/manifest.h" using extensions::Extension; using extensions::ExtensionPrefs; -using extensions::ExtensionSystem; +using extensions::ExtensionRegistry; namespace { @@ -89,18 +88,18 @@ IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, GarbageCollectEphemeralApps(); uninstall_signal.Wait(); - ExtensionService* service = ExtensionSystem::Get(browser()->profile()) - ->extension_service(); - ASSERT_TRUE(service); - EXPECT_FALSE(service->GetInstalledExtension(inactive_app_id)); - EXPECT_TRUE(service->GetInstalledExtension(active_app_id)); + ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); + ASSERT_TRUE(registry); + EXPECT_FALSE(registry->GetExtensionById(inactive_app_id, + ExtensionRegistry::EVERYTHING)); + EXPECT_TRUE( + registry->GetExtensionById(active_app_id, ExtensionRegistry::EVERYTHING)); EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); } // Verify that the count of ephemeral apps is maintained correctly. -IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, - EphemeralAppCount) { +IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, EphemeralAppCount) { EphemeralAppService* ephemeral_service = EphemeralAppService::Get(browser()->profile()); ASSERT_TRUE(ephemeral_service); @@ -129,3 +128,31 @@ IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, PromoteEphemeralApp(app); EXPECT_EQ(0, ephemeral_service->ephemeral_app_count()); } + +// Verify that the cache of ephemeral apps is correctly cleared. Running apps +// should not be removed. +IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, ClearCachedApps) { + const Extension* running_app = + InstallAndLaunchEphemeralApp(kMessagingReceiverApp); + const Extension* inactive_app = + InstallAndLaunchEphemeralApp(kDispatchEventTestApp); + std::string inactive_app_id = inactive_app->id(); + std::string running_app_id = running_app->id(); + CloseApp(inactive_app_id); + + EphemeralAppService* ephemeral_service = + EphemeralAppService::Get(browser()->profile()); + ASSERT_TRUE(ephemeral_service); + EXPECT_EQ(2, ephemeral_service->ephemeral_app_count()); + + ephemeral_service->ClearCachedApps(); + + ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); + ASSERT_TRUE(registry); + EXPECT_FALSE(registry->GetExtensionById(inactive_app_id, + ExtensionRegistry::EVERYTHING)); + EXPECT_TRUE(registry->GetExtensionById(running_app_id, + ExtensionRegistry::EVERYTHING)); + + EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); +} diff --git a/chrome/browser/browsing_data/browsing_data_remover.cc b/chrome/browser/browsing_data/browsing_data_remover.cc index d9f4802..2cc1fcf 100644 --- a/chrome/browser/browsing_data/browsing_data_remover.cc +++ b/chrome/browser/browsing_data/browsing_data_remover.cc @@ -85,6 +85,7 @@ #endif #if defined(ENABLE_EXTENSIONS) +#include "chrome/browser/apps/ephemeral_app_service.h" #include "chrome/browser/extensions/activity_log/activity_log.h" #endif @@ -604,6 +605,11 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask, storage_partition_remove_mask |= content::StoragePartition::REMOVE_DATA_MASK_WEBRTC_IDENTITY; + +#if defined(ENABLE_EXTENSIONS) + // Clear the ephemeral apps cache. + EphemeralAppService::Get(profile_)->ClearCachedApps(); +#endif } if (storage_partition_remove_mask) { |