Commit 5ddbfd5b authored by Xiaochu Liu's avatar Xiaochu Liu Committed by Commit Bot

Install cros components to own path naming space

To avoid path conflicts, we install chrome os components (only) to
dedicated path naming space (cros_components/[component name]).

Since the components currently used are small (printer drivers), the
cost to migrate it small. It's a good idea to migrate now.

BUG=chromium:789726
TEST=update (ignore old locations)/install printer driver component on device.

Change-Id: I3276f73eaab50ec562d247d06eedb5c96ba183bf
Reviewed-on: https://chromium-review.googlesource.com/798225
Commit-Queue: Xiaochu Liu <xiaochu@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522020}
parent 904d1dfc
......@@ -46,6 +46,8 @@
{"sha2hashstr", \
"5714811c04f0a63aac96b39096faa759ace4c04e9b68291e7c9716128f5a2722"}}}};
#define COMPONENTS_ROOT_PATH "cros-components"
using content::BrowserThread;
namespace component_updater {
......@@ -79,10 +81,23 @@ bool CrOSComponentInstallerPolicy::RequiresNetworkEncryption() const {
return true;
}
void CleanupOldInstalls(const std::string& name) {
// Clean up components installed at old path.
base::FilePath path;
if (!PathService::Get(DIR_COMPONENT_USER, &path))
return;
path = path.Append(name);
if (base::PathExists(path))
base::DeleteFile(path, true);
}
update_client::CrxInstaller::Result
CrOSComponentInstallerPolicy::OnCustomInstall(
const base::DictionaryValue& manifest,
const base::FilePath& install_dir) {
// TODO(xiaochu): remove this at M66 (crbug.com/792203).
CleanupOldInstalls(name);
return update_client::CrxInstaller::Result(update_client::InstallError::NONE);
}
......@@ -109,7 +124,8 @@ bool CrOSComponentInstallerPolicy::VerifyInstallation(
}
base::FilePath CrOSComponentInstallerPolicy::GetRelativeInstallDir() const {
return base::FilePath(name);
base::FilePath path = base::FilePath(COMPONENTS_ROOT_PATH);
return path.Append(name);
}
void CrOSComponentInstallerPolicy::GetHash(std::vector<uint8_t>* hash) const {
......@@ -242,6 +258,7 @@ std::vector<ComponentConfig> CrOSComponent::GetInstalledComponents() {
if (!PathService::Get(DIR_COMPONENT_USER, &root))
return configs;
root = root.Append(COMPONENTS_ROOT_PATH);
const ConfigMap components = CONFIG_MAP_CONTENT;
for (auto it : components) {
const std::string& name = it.first;
......
......@@ -274,10 +274,11 @@ void ComponentInstaller::StartRegistration(
// Then check for a higher-versioned user-wide installation.
base::FilePath latest_path;
std::unique_ptr<base::DictionaryValue> latest_manifest;
base::FilePath base_dir;
if (!PathService::Get(DIR_COMPONENT_USER, &base_dir))
base::FilePath base_component_dir;
if (!PathService::Get(DIR_COMPONENT_USER, &base_component_dir))
return;
base_dir = base_dir.Append(installer_policy_->GetRelativeInstallDir());
base::FilePath base_dir =
base_component_dir.Append(installer_policy_->GetRelativeInstallDir());
if (!base::PathExists(base_dir) && !base::CreateDirectory(base_dir)) {
PLOG(ERROR) << "Could not create the base directory for "
<< installer_policy_->GetName() << " ("
......@@ -286,10 +287,16 @@ void ComponentInstaller::StartRegistration(
}
#if defined(OS_CHROMEOS)
if (!base::SetPosixFilePermissions(base_dir, 0755)) {
base::FilePath base_dir_ = base_component_dir;
std::vector<base::FilePath::StringType> components;
installer_policy_->GetRelativeInstallDir().GetComponents(&components);
for (const base::FilePath::StringType component : components) {
base_dir_ = base_dir_.Append(component);
if (!base::SetPosixFilePermissions(base_dir_, 0755)) {
PLOG(ERROR) << "SetPosixFilePermissions failed: " << base_dir.value();
return;
}
}
#endif // defined(OS_CHROMEOS)
std::vector<base::FilePath> older_paths;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment