summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 21:06:44 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 21:06:44 +0000
commit522ddf38c881d5c0ca39f63b14360cb2d18bd9d6 (patch)
treedca8fded3c88a8b33f9d3e41eb21d29e0b103c93 /chrome/browser/extensions
parentecd6182d0a5325ce7f3f62b3b36157787f9d7699 (diff)
downloadchromium_src-522ddf38c881d5c0ca39f63b14360cb2d18bd9d6.zip
chromium_src-522ddf38c881d5c0ca39f63b14360cb2d18bd9d6.tar.gz
chromium_src-522ddf38c881d5c0ca39f63b14360cb2d18bd9d6.tar.bz2
Merge 33530 - Delete old version directories of installed extensions during garbage
collection. BUG=28884 Review URL: http://codereview.chromium.org/455026 TBR=mpcomplete@chromium.org Review URL: http://codereview.chromium.org/460024 git-svn-id: svn://svn.chromium.org/chrome/branches/249/src@33602 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-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 52c2c78..76a872c 100644
--- a/chrome/browser/extensions/extension_file_util.cc
+++ b/chrome/browser/extensions/extension_file_util.cc
@@ -309,8 +309,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;
@@ -335,7 +337,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;
@@ -344,6 +346,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 867fde5..141c49d 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -51,15 +51,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
@@ -532,7 +542,7 @@ void ExtensionsService::GarbageCollectExtensions() {
ChromeThread::FILE, FROM_HERE,
NewRunnableFunction(
&extension_file_util::GarbageCollectExtensions, install_directory_,
- installed.extensions()));
+ installed.extensions(), installed.versions()));
}
void ExtensionsService::OnLoadedInstalledExtensions() {