summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 01:42:41 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 01:42:41 +0000
commit4559a7d9c3eca928fc19b64b64f19c8032d0ee0f (patch)
treea754a4c898518478035d5e493518c900dcdca248 /chrome
parent9829d8d83608c54937e5187512f98a81b29f80bb (diff)
downloadchromium_src-4559a7d9c3eca928fc19b64b64f19c8032d0ee0f.zip
chromium_src-4559a7d9c3eca928fc19b64b64f19c8032d0ee0f.tar.gz
chromium_src-4559a7d9c3eca928fc19b64b64f19c8032d0ee0f.tar.bz2
Delete old version directories of installed extensions during garbage
collection. BUG=28884 Review URL: http://codereview.chromium.org/455026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33530 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_file_util.cc31
-rw-r--r--chrome/browser/extensions/extension_file_util.h8
-rw-r--r--chrome/browser/extensions/extensions_service.cc12
3 files changed, 43 insertions, 8 deletions
diff --git a/chrome/browser/extensions/extension_file_util.cc b/chrome/browser/extensions/extension_file_util.cc
index f61dfef..0bb2ff8 100644
--- a/chrome/browser/extensions/extension_file_util.cc
+++ b/chrome/browser/extensions/extension_file_util.cc
@@ -318,8 +318,10 @@ void UninstallExtension(const std::string& id, const FilePath& extensions_dir) {
LOG(WARNING) << "Could not delete directory for extension " << id;
}
-void GarbageCollectExtensions(const FilePath& install_directory,
- const std::set<std::string>& installed_ids) {
+void GarbageCollectExtensions(
+ const FilePath& install_directory,
+ const std::set<std::string>& installed_ids,
+ const std::map<std::string, std::string>& installed_versions) {
// Nothing to clean up if it doesn't exist.
if (!file_util::DirectoryExists(install_directory))
return;
@@ -344,7 +346,7 @@ void GarbageCollectExtensions(const FilePath& install_directory,
continue;
}
- // Ignore directories that aren't valid IDs.
+ // Delete directories that aren't valid IDs.
if (!Extension::IdIsValid(extension_id)) {
LOG(WARNING) << "Invalid extension ID encountered in extensions "
"directory: " << extension_id;
@@ -353,6 +355,29 @@ void GarbageCollectExtensions(const FilePath& install_directory,
file_util::Delete(extension_path, true); // Recursive.
continue;
}
+
+ // Clean up old version directories.
+ file_util::FileEnumerator versions_enumerator(
+ extension_path,
+ false, // Not recursive.
+ file_util::FileEnumerator::DIRECTORIES);
+ for (FilePath version_dir = versions_enumerator.Next();
+ !version_dir.value().empty();
+ version_dir = versions_enumerator.Next()) {
+ std::map<std::string, std::string>::const_iterator installed_version =
+ installed_versions.find(extension_id);
+ if (installed_version == installed_versions.end()) {
+ NOTREACHED() << "No installed version found for " << extension_id;
+ continue;
+ }
+
+ std::string version = WideToASCII(version_dir.BaseName().ToWStringHack());
+ if (version != installed_version->second) {
+ LOG(INFO) << "Deleting old version for directory "
+ << WideToASCII(version_dir.ToWStringHack()) << ".";
+ file_util::Delete(version_dir, true); // Recursive.
+ }
+ }
}
}
diff --git a/chrome/browser/extensions/extension_file_util.h b/chrome/browser/extensions/extension_file_util.h
index b6a737f..4cae8ec 100644
--- a/chrome/browser/extensions/extension_file_util.h
+++ b/chrome/browser/extensions/extension_file_util.h
@@ -81,10 +81,10 @@ bool ValidateExtension(Extension* extension, std::string* error);
void UninstallExtension(const std::string& id, const FilePath& extensions_dir);
// Clean up directories that aren't valid extensions from the install directory.
-// TODO(aa): Also consider passing in a list of known current extensions and
-// removing others?
-void GarbageCollectExtensions(const FilePath& extensions_dir,
- const std::set<std::string>& installed_ids);
+void GarbageCollectExtensions(
+ const FilePath& extensions_dir,
+ const std::set<std::string>& installed_ids,
+ const std::map<std::string, std::string>& installed_versions);
// Loads locale information if _locales folder is present.
// Returns message bundle if there were no errors. If _locales folder is not
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 09f964c..4fd65cf 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -52,15 +52,25 @@ class InstalledExtensionSet {
}
const std::set<std::string>& extensions() { return extensions_; }
+ const std::map<std::string, std::string>& versions() { return versions_; }
private:
void ExtensionVisited(
DictionaryValue* manifest, const std::string& id,
const FilePath& path, Extension::Location location) {
+ std::string version;
+ if (!manifest ||
+ !manifest->GetString(extension_manifest_keys::kVersion, &version)) {
+ // Without a version, the extension is invalid. Ignoring it here will
+ // cause it to get garbage collected.
+ return;
+ }
extensions_.insert(id);
+ versions_[id] = version;
}
std::set<std::string> extensions_;
+ std::map<std::string, std::string> versions_;
};
} // namespace
@@ -524,7 +534,7 @@ void ExtensionsService::GarbageCollectExtensions() {
ChromeThread::FILE, FROM_HERE,
NewRunnableFunction(
&extension_file_util::GarbageCollectExtensions, install_directory_,
- installed.extensions()));
+ installed.extensions(), installed.versions()));
}
void ExtensionsService::OnLoadedInstalledExtensions() {