summaryrefslogtreecommitdiffstats
path: root/components/component_updater/default_component_installer.cc
diff options
context:
space:
mode:
authorbauerb <bauerb@chromium.org>2015-02-08 16:00:27 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-09 00:01:15 +0000
commit1f6657e7f1cf36e7a490c494c0794b124c86b6ec (patch)
treea7d54dc73cb55c5f5136fd6237bf7d0cb9a977cc /components/component_updater/default_component_installer.cc
parentcce3cff79038a60aab74990acd2974de518d5c9f (diff)
downloadchromium_src-1f6657e7f1cf36e7a490c494c0794b124c86b6ec.zip
chromium_src-1f6657e7f1cf36e7a490c494c0794b124c86b6ec.tar.gz
chromium_src-1f6657e7f1cf36e7a490c494c0794b124c86b6ec.tar.bz2
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}
Diffstat (limited to 'components/component_updater/default_component_installer.cc')
-rw-r--r--components/component_updater/default_component_installer.cc41
1 files changed, 39 insertions, 2 deletions
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());