From 1f6657e7f1cf36e7a490c494c0794b124c86b6ec Mon Sep 17 00:00:00 2001 From: bauerb Date: Sun, 8 Feb 2015 16:00:27 -0800 Subject: Add support for uninstalling components and use it in SupervisedUserWhitelistInstaller. TBR=agl@chromium.org BUG=436459 Review URL: https://codereview.chromium.org/879993005 Cr-Commit-Position: refs/heads/master@{#315246} --- .../default_component_installer.cc | 41 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'components/component_updater/default_component_installer.cc') diff --git a/components/component_updater/default_component_installer.cc b/components/component_updater/default_component_installer.cc index d73b4fc..027b1cb 100644 --- a/components/component_updater/default_component_installer.cc +++ b/components/component_updater/default_component_installer.cc @@ -17,16 +17,18 @@ #include "components/component_updater/component_updater_service.h" #include "components/component_updater/default_component_installer.h" #include "components/update_client/component_unpacker.h" -#include "components/update_client/update_client.h" +#include "components/update_client/utils.h" using update_client::CrxComponent; namespace component_updater { namespace { + // Version "0" corresponds to no installed version. By the server's conventions, // we represent it as a dotted quad. const char kNullVersion[] = "0.0.0.0"; + } // namespace ComponentInstallerTraits::~ComponentInstallerTraits() { @@ -40,7 +42,6 @@ DefaultComponentInstaller::DefaultComponentInstaller( } DefaultComponentInstaller::~DefaultComponentInstaller() { - DCHECK(thread_checker_.CalledOnValidThread()); } void DefaultComponentInstaller::Register(ComponentUpdateService* cus) { @@ -77,6 +78,8 @@ bool DefaultComponentInstaller::InstallHelper( bool DefaultComponentInstaller::Install(const base::DictionaryValue& manifest, const base::FilePath& unpack_path) { + DCHECK(task_runner_->RunsTasksOnCurrentThread()); + std::string manifest_version; manifest.GetStringASCII("version", &manifest_version); base::Version version(manifest_version.c_str()); @@ -119,6 +122,13 @@ bool DefaultComponentInstaller::GetInstalledFile( return true; } +bool DefaultComponentInstaller::Uninstall() { + task_runner_->PostTask( + FROM_HERE, + base::Bind(&DefaultComponentInstaller::UninstallOnTaskRunner, this)); + return true; +} + void DefaultComponentInstaller::StartRegistration(ComponentUpdateService* cus) { DCHECK(task_runner_.get()); DCHECK(task_runner_->RunsTasksOnCurrentThread()); @@ -196,6 +206,33 @@ void DefaultComponentInstaller::StartRegistration(ComponentUpdateService* cus) { this, cus)); } +void DefaultComponentInstaller::UninstallOnTaskRunner() { + DCHECK(task_runner_.get()); + DCHECK(task_runner_->RunsTasksOnCurrentThread()); + const base::FilePath base_dir = installer_traits_->GetBaseDirectory(); + + base::FileEnumerator file_enumerator(base_dir, false, + base::FileEnumerator::DIRECTORIES); + for (base::FilePath path = file_enumerator.Next(); !path.value().empty(); + path = file_enumerator.Next()) { + base::Version version(path.BaseName().MaybeAsASCII()); + + // Ignore folders that don't have valid version names. These folders are not + // managed by the component installer, so do not try to remove them. + if (!version.IsValid()) + continue; + + if (!base::DeleteFile(path, true)) + DLOG(ERROR) << "Couldn't delete " << path.value(); + } + + // Delete the base directory if it's empty now. + if (base::IsDirectoryEmpty(base_dir)) { + if (base::DeleteFile(base_dir, false)) + DLOG(ERROR) << "Couldn't delete " << base_dir.value(); + } +} + base::FilePath DefaultComponentInstaller::GetInstallDirectory() { return installer_traits_->GetBaseDirectory() .AppendASCII(current_version_.GetString()); -- cgit v1.1