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 @@ ...@@ -46,6 +46,8 @@
{"sha2hashstr", \ {"sha2hashstr", \
"5714811c04f0a63aac96b39096faa759ace4c04e9b68291e7c9716128f5a2722"}}}}; "5714811c04f0a63aac96b39096faa759ace4c04e9b68291e7c9716128f5a2722"}}}};
#define COMPONENTS_ROOT_PATH "cros-components"
using content::BrowserThread; using content::BrowserThread;
namespace component_updater { namespace component_updater {
...@@ -79,10 +81,23 @@ bool CrOSComponentInstallerPolicy::RequiresNetworkEncryption() const { ...@@ -79,10 +81,23 @@ bool CrOSComponentInstallerPolicy::RequiresNetworkEncryption() const {
return true; 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 update_client::CrxInstaller::Result
CrOSComponentInstallerPolicy::OnCustomInstall( CrOSComponentInstallerPolicy::OnCustomInstall(
const base::DictionaryValue& manifest, const base::DictionaryValue& manifest,
const base::FilePath& install_dir) { 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); return update_client::CrxInstaller::Result(update_client::InstallError::NONE);
} }
...@@ -109,7 +124,8 @@ bool CrOSComponentInstallerPolicy::VerifyInstallation( ...@@ -109,7 +124,8 @@ bool CrOSComponentInstallerPolicy::VerifyInstallation(
} }
base::FilePath CrOSComponentInstallerPolicy::GetRelativeInstallDir() const { 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 { void CrOSComponentInstallerPolicy::GetHash(std::vector<uint8_t>* hash) const {
...@@ -242,6 +258,7 @@ std::vector<ComponentConfig> CrOSComponent::GetInstalledComponents() { ...@@ -242,6 +258,7 @@ std::vector<ComponentConfig> CrOSComponent::GetInstalledComponents() {
if (!PathService::Get(DIR_COMPONENT_USER, &root)) if (!PathService::Get(DIR_COMPONENT_USER, &root))
return configs; return configs;
root = root.Append(COMPONENTS_ROOT_PATH);
const ConfigMap components = CONFIG_MAP_CONTENT; const ConfigMap components = CONFIG_MAP_CONTENT;
for (auto it : components) { for (auto it : components) {
const std::string& name = it.first; const std::string& name = it.first;
......
...@@ -274,10 +274,11 @@ void ComponentInstaller::StartRegistration( ...@@ -274,10 +274,11 @@ void ComponentInstaller::StartRegistration(
// Then check for a higher-versioned user-wide installation. // Then check for a higher-versioned user-wide installation.
base::FilePath latest_path; base::FilePath latest_path;
std::unique_ptr<base::DictionaryValue> latest_manifest; std::unique_ptr<base::DictionaryValue> latest_manifest;
base::FilePath base_dir; base::FilePath base_component_dir;
if (!PathService::Get(DIR_COMPONENT_USER, &base_dir)) if (!PathService::Get(DIR_COMPONENT_USER, &base_component_dir))
return; 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)) { if (!base::PathExists(base_dir) && !base::CreateDirectory(base_dir)) {
PLOG(ERROR) << "Could not create the base directory for " PLOG(ERROR) << "Could not create the base directory for "
<< installer_policy_->GetName() << " (" << installer_policy_->GetName() << " ("
...@@ -286,9 +287,15 @@ void ComponentInstaller::StartRegistration( ...@@ -286,9 +287,15 @@ void ComponentInstaller::StartRegistration(
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
if (!base::SetPosixFilePermissions(base_dir, 0755)) { base::FilePath base_dir_ = base_component_dir;
PLOG(ERROR) << "SetPosixFilePermissions failed: " << base_dir.value(); std::vector<base::FilePath::StringType> components;
return; 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) #endif // defined(OS_CHROMEOS)
......
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