summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authortmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-21 12:58:34 +0000
committertmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-21 12:58:34 +0000
commitca033634a786022407b66ca4c65fc910eae58d39 (patch)
treead9728883852c1b0df65627237aaa1fd99cbea6e /extensions
parenta12f8b5e6ecd9ff97969bb7cb2037865d1d4f09e (diff)
downloadchromium_src-ca033634a786022407b66ca4c65fc910eae58d39.zip
chromium_src-ca033634a786022407b66ca4c65fc910eae58d39.tar.gz
chromium_src-ca033634a786022407b66ca4c65fc910eae58d39.tar.bz2
Retain local data of ephemeral apps after cache eviction
This patch prevents the local data of ephemeral apps from being deleted when they are evicted from the cache (i.e. uninstalled from extension system). The data is garbage collected by EphemeralAppService after a period of inactivity. BUG=339004 TEST=browser_tests (EphemeralAppBrowserTest.*) Review URL: https://codereview.chromium.org/202763005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258555 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions')
-rw-r--r--extensions/browser/extension_prefs.cc75
-rw-r--r--extensions/browser/extension_prefs.h11
2 files changed, 85 insertions, 1 deletions
diff --git a/extensions/browser/extension_prefs.cc b/extensions/browser/extension_prefs.cc
index d48a13bb..23513c8 100644
--- a/extensions/browser/extension_prefs.cc
+++ b/extensions/browser/extension_prefs.cc
@@ -179,6 +179,11 @@ const char kPrefGeometryCache[] = "geometry_cache";
// A preference that indicates when an extension is last launched.
const char kPrefLastLaunchTime[] = "last_launch_time";
+// A preference that marks an ephemeral app that was evicted from the cache.
+// Their data is retained and garbage collected when inactive for a long period
+// of time.
+const char kPrefEvictedEphemeralApp[] = "evicted_ephemeral_app";
+
// A list of installed ids and a signature.
const char kInstallSignature[] = "extensions.install_signature";
@@ -223,6 +228,11 @@ bool IsBlacklistBitSet(const base::DictionaryValue* ext) {
return ext->GetBoolean(kPrefBlacklist, &bool_value) && bool_value;
}
+bool IsEvictedEphemeralApp(const base::DictionaryValue* ext) {
+ bool bool_value;
+ return ext->GetBoolean(kPrefEvictedEphemeralApp, &bool_value) && bool_value;
+}
+
} // namespace
//
@@ -1134,7 +1144,14 @@ void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
extension_pref_value_map_->SetExtensionState(extension_id, false);
content_settings_store_->SetExtensionState(extension_id, false);
} else {
- DeleteExtensionPrefs(extension_id);
+ int creation_flags = GetCreationFlags(extension_id);
+ if (creation_flags & Extension::IS_EPHEMERAL) {
+ // Keep ephemeral apps around, but mark them as evicted.
+ UpdateExtensionPref(extension_id, kPrefEvictedEphemeralApp,
+ new base::FundamentalValue(true));
+ } else {
+ DeleteExtensionPrefs(extension_id);
+ }
}
}
@@ -1267,6 +1284,11 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo(
return scoped_ptr<ExtensionInfo>();
}
+ if (IsEvictedEphemeralApp(ext)) {
+ // Hide evicted ephemeral apps.
+ return scoped_ptr<ExtensionInfo>();
+ }
+
return GetInstalledInfoHelper(extension_id, ext);
}
@@ -1439,6 +1461,54 @@ scoped_ptr<ExtensionPrefs::ExtensionsInfo> ExtensionPrefs::
return extensions_info.Pass();
}
+scoped_ptr<ExtensionPrefs::ExtensionsInfo>
+ExtensionPrefs::GetEvictedEphemeralAppsInfo() const {
+ scoped_ptr<ExtensionsInfo> extensions_info(new ExtensionsInfo);
+
+ const base::DictionaryValue* extensions =
+ prefs_->GetDictionary(pref_names::kExtensions);
+ for (base::DictionaryValue::Iterator extension_id(*extensions);
+ !extension_id.IsAtEnd(); extension_id.Advance()) {
+ const base::DictionaryValue* ext = NULL;
+ if (!Extension::IdIsValid(extension_id.key()) ||
+ !extension_id.value().GetAsDictionary(&ext)) {
+ continue;
+ }
+
+ if (!IsEvictedEphemeralApp(ext))
+ continue;
+
+ scoped_ptr<ExtensionInfo> info =
+ GetInstalledInfoHelper(extension_id.key(), ext);
+ if (info)
+ extensions_info->push_back(linked_ptr<ExtensionInfo>(info.release()));
+ }
+
+ return extensions_info.Pass();
+}
+
+scoped_ptr<ExtensionInfo> ExtensionPrefs::GetEvictedEphemeralAppInfo(
+ const std::string& extension_id) const {
+ const base::DictionaryValue* extension_prefs = GetExtensionPref(extension_id);
+ if (!extension_prefs)
+ return scoped_ptr<ExtensionInfo>();
+
+ if (!IsEvictedEphemeralApp(extension_prefs))
+ return scoped_ptr<ExtensionInfo>();
+
+ return GetInstalledInfoHelper(extension_id, extension_prefs);
+}
+
+void ExtensionPrefs::RemoveEvictedEphemeralApp(
+ const std::string& extension_id) {
+ bool evicted_ephemeral_app = false;
+ if (ReadPrefAsBoolean(extension_id,
+ kPrefEvictedEphemeralApp,
+ &evicted_ephemeral_app) && evicted_ephemeral_app) {
+ DeleteExtensionPrefs(extension_id);
+ }
+}
+
bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) {
return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp);
}
@@ -1907,6 +1977,9 @@ void ExtensionPrefs::FinishExtensionInfoPrefs(
// Clear state that may be registered from a previous install.
extension_dict->Remove(EventRouter::kRegisteredEvents, NULL);
+ // When evicted ephemeral apps are re-installed, this flag must be reset.
+ extension_dict->Remove(kPrefEvictedEphemeralApp, NULL);
+
// FYI, all code below here races on sudden shutdown because |extension_dict|,
// |app_sorting_|, |extension_pref_value_map_|, and |content_settings_store_|
// are updated non-transactionally. This is probably not fixable without
diff --git a/extensions/browser/extension_prefs.h b/extensions/browser/extension_prefs.h
index 032c578..e288f94 100644
--- a/extensions/browser/extension_prefs.h
+++ b/extensions/browser/extension_prefs.h
@@ -437,6 +437,17 @@ class ExtensionPrefs : public ExtensionScopedPrefs, public KeyedService {
// information.
scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const;
+ // Returns information about evicted ephemeral apps.
+ scoped_ptr<ExtensionsInfo> GetEvictedEphemeralAppsInfo() const;
+
+ // Return information about a specific evicted ephemeral app. Can return NULL
+ // if no such evicted app exists or is currently installed.
+ scoped_ptr<ExtensionInfo> GetEvictedEphemeralAppInfo(
+ const std::string& extension_id) const;
+
+ // Permanently remove the preferences for an evicted ephemeral app.
+ void RemoveEvictedEphemeralApp(const std::string& extension_id);
+
// Returns true if the user repositioned the app on the app launcher via drag
// and drop.
bool WasAppDraggedByUser(const std::string& extension_id);