summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-28 18:28:07 +0000
committerrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-28 18:28:07 +0000
commitb2a3c073b8b5c367e5ca9fa5b05dc59e2400f18a (patch)
tree2b98e48475f1f4a4ad2604c9d0e928b6fd39ce05 /chrome/common
parent5faf328f60b55df3b62a687ccf4b2660460679ae (diff)
downloadchromium_src-b2a3c073b8b5c367e5ca9fa5b05dc59e2400f18a.zip
chromium_src-b2a3c073b8b5c367e5ca9fa5b05dc59e2400f18a.tar.gz
chromium_src-b2a3c073b8b5c367e5ca9fa5b05dc59e2400f18a.tar.bz2
Remove ExtensionService Garbage-Collecting methods.
Make a new class, ExtensionGarbageCollector, which performs: - ExtensionService::GarbageCollectExtensions(), - extension_file_util::GarbageCollectExtensions() (the file-thread impl of ExtensionService::GarbageCollectExtensions()), - ExtensionService::GarbageCollectIsolatedStorage() BUG=351891 TBR=rkc@chromium.org (for c/b/chromeos/kiosk_mode - no functional changes, but the TODO has moved from ExtensionService to ExtensionGarbageCollector). Review URL: https://codereview.chromium.org/204983020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260207 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/extensions/extension_file_util.cc86
-rw-r--r--chrome/common/extensions/extension_file_util.h20
-rw-r--r--chrome/common/extensions/extension_file_util_unittest.cc14
3 files changed, 7 insertions, 113 deletions
diff --git a/chrome/common/extensions/extension_file_util.cc b/chrome/common/extensions/extension_file_util.cc
index f186053..814dde5 100644
--- a/chrome/common/extensions/extension_file_util.cc
+++ b/chrome/common/extensions/extension_file_util.cc
@@ -9,7 +9,6 @@
#include "base/file_util.h"
#include "base/files/file_enumerator.h"
-#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_file_value_serializer.h"
#include "base/logging.h"
@@ -45,8 +44,6 @@ namespace errors = extensions::manifest_errors;
namespace {
-const base::FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp");
-
// Add the image paths contained in the |icon_set| to |image_paths|.
void AddPathsFromIconSet(const ExtensionIconSet& icon_set,
std::set<base::FilePath>* image_paths) {
@@ -62,6 +59,8 @@ void AddPathsFromIconSet(const ExtensionIconSet& icon_set,
namespace extension_file_util {
+const base::FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp");
+
base::FilePath InstallExtension(const base::FilePath& unpacked_source_dir,
const std::string& id,
const std::string& version,
@@ -122,7 +121,7 @@ void UninstallExtension(const base::FilePath& extensions_dir,
const std::string& id) {
// We don't care about the return value. If this fails (and it can, due to
// plugins that aren't unloaded yet), it will get cleaned up by
- // ExtensionService::GarbageCollectExtensions.
+ // ExtensionGarbageCollector::GarbageCollectExtensions.
base::DeleteFile(extensions_dir.AppendASCII(id), true); // recursive.
}
@@ -323,85 +322,6 @@ std::set<base::FilePath> GetBrowserImagePaths(const Extension* extension) {
return image_paths;
}
-void GarbageCollectExtensions(
- const base::FilePath& install_directory,
- const std::multimap<std::string, base::FilePath>& extension_paths,
- bool clean_temp_dir) {
- // Nothing to clean up if it doesn't exist.
- if (!base::DirectoryExists(install_directory))
- return;
-
- DVLOG(1) << "Garbage collecting extensions...";
- base::FileEnumerator enumerator(install_directory,
- false, // Not recursive.
- base::FileEnumerator::DIRECTORIES);
- base::FilePath extension_path;
- for (extension_path = enumerator.Next(); !extension_path.value().empty();
- extension_path = enumerator.Next()) {
- std::string extension_id;
-
- base::FilePath basename = extension_path.BaseName();
- // Clean up temporary files left if Chrome crashed or quit in the middle
- // of an extension install.
- if (basename.value() == kTempDirectoryName) {
- if (clean_temp_dir)
- base::DeleteFile(extension_path, true); // Recursive
- continue;
- }
-
- // Parse directory name as a potential extension ID.
- if (IsStringASCII(basename.value())) {
- extension_id = base::UTF16ToASCII(basename.LossyDisplayName());
- if (!Extension::IdIsValid(extension_id))
- extension_id.clear();
- }
-
- // Delete directories that aren't valid IDs.
- if (extension_id.empty()) {
- DLOG(WARNING) << "Invalid extension ID encountered in extensions "
- "directory: " << basename.value();
- DVLOG(1) << "Deleting invalid extension directory "
- << extension_path.value() << ".";
- base::DeleteFile(extension_path, true); // Recursive.
- continue;
- }
-
- typedef std::multimap<std::string, base::FilePath>::const_iterator Iter;
- std::pair<Iter, Iter> iter_pair = extension_paths.equal_range(extension_id);
-
- // If there is no entry in the prefs file, just delete the directory and
- // move on. This can legitimately happen when an uninstall does not
- // complete, for example, when a plugin is in use at uninstall time.
- if (iter_pair.first == iter_pair.second) {
- DVLOG(1) << "Deleting unreferenced install for directory "
- << extension_path.LossyDisplayName() << ".";
- base::DeleteFile(extension_path, true); // Recursive.
- continue;
- }
-
- // Clean up old version directories.
- base::FileEnumerator versions_enumerator(
- extension_path,
- false, // Not recursive.
- base::FileEnumerator::DIRECTORIES);
- for (base::FilePath version_dir = versions_enumerator.Next();
- !version_dir.value().empty();
- version_dir = versions_enumerator.Next()) {
- bool knownVersion = false;
- for (Iter it = iter_pair.first; it != iter_pair.second; ++it)
- if (version_dir.BaseName() == it->second.BaseName()) {
- knownVersion = true;
- break;
- }
- if (!knownVersion) {
- DVLOG(1) << "Deleting old version for directory "
- << version_dir.LossyDisplayName() << ".";
- base::DeleteFile(version_dir, true); // Recursive.
- }
- }
- }
-}
-
extensions::MessageBundle* LoadMessageBundle(
const base::FilePath& extension_path,
const std::string& default_locale,
diff --git a/chrome/common/extensions/extension_file_util.h b/chrome/common/extensions/extension_file_util.h
index 3e18f29d..7139600 100644
--- a/chrome/common/extensions/extension_file_util.h
+++ b/chrome/common/extensions/extension_file_util.h
@@ -8,6 +8,7 @@
#include <map>
#include <string>
+#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "chrome/common/extensions/message_bundle.h"
#include "extensions/common/manifest.h"
@@ -28,6 +29,8 @@ struct InstallWarning;
// Utilities for manipulating the on-disk storage of extensions.
namespace extension_file_util {
+extern const base::FilePath::CharType kTempDirectoryName[];
+
// Copies |unpacked_source_dir| into the right location under |extensions_dir|.
// The destination directory is returned on success, or empty path is returned
// on failure.
@@ -91,23 +94,6 @@ std::set<base::FilePath> GetBrowserImagePaths(
std::vector<base::FilePath> FindPrivateKeyFiles(
const base::FilePath& extension_dir);
-// Cleans up the extension install directory. It can end up with garbage in it
-// if extensions can't initially be removed when they are uninstalled (eg if a
-// file is in use).
-//
-// |extensions_dir| is the install directory to look in. |extension_paths| is a
-// map from extension id to full installation path.
-//
-// Obsolete version directories are removed, as are directories that aren't
-// found in |extension_paths|.
-//
-// The "Temp" directory that is used during extension installation only gets
-// removed if |clean_temp_dir| is true.
-void GarbageCollectExtensions(
- const base::FilePath& extensions_dir,
- const std::multimap<std::string, base::FilePath>& extension_paths,
- bool clean_temp_dir);
-
// Loads extension message catalogs and returns message bundle.
// Returns NULL on error, or if extension is not localized.
extensions::MessageBundle* LoadMessageBundle(
diff --git a/chrome/common/extensions/extension_file_util_unittest.cc b/chrome/common/extensions/extension_file_util_unittest.cc
index ff5595f..09e39ff 100644
--- a/chrome/common/extensions/extension_file_util_unittest.cc
+++ b/chrome/common/extensions/extension_file_util_unittest.cc
@@ -83,21 +83,9 @@ TEST_F(ExtensionFileUtilTest, InstallUninstallGarbageCollect) {
.value());
ASSERT_TRUE(base::DirectoryExists(version_3));
- // Collect garbage. Should remove first one.
- std::multimap<std::string, base::FilePath> extension_paths;
- extension_paths.insert(std::make_pair(extension_id,
- base::FilePath().AppendASCII(extension_id).Append(version_2.BaseName())));
- extension_paths.insert(std::make_pair(extension_id,
- base::FilePath().AppendASCII(extension_id).Append(version_3.BaseName())));
- extension_file_util::GarbageCollectExtensions(all_extensions,
- extension_paths,
- true);
- ASSERT_FALSE(base::DirectoryExists(version_1));
- ASSERT_TRUE(base::DirectoryExists(version_2));
- ASSERT_TRUE(base::DirectoryExists(version_3));
-
// Uninstall. Should remove entire extension subtree.
extension_file_util::UninstallExtension(all_extensions, extension_id);
+ ASSERT_FALSE(base::DirectoryExists(version_1.DirName()));
ASSERT_FALSE(base::DirectoryExists(version_2.DirName()));
ASSERT_FALSE(base::DirectoryExists(version_3.DirName()));
ASSERT_TRUE(base::DirectoryExists(all_extensions));