Commit 845e1e05 authored by Xiaochu Liu's avatar Xiaochu Liu Committed by Commit Bot

component updater:: allow force update for crostini

Component updater does not force an update if an compatible component is
installed. We provide an option in the Load API to support forced update
check.

BUG=chromium:850798,chromium:859573
TEST=platform_AddPrinter.epson

Change-Id: I1649e0ce641089cd57d4910155fc93e660967df1
Reviewed-on: https://chromium-review.googlesource.com/1119199Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Reviewed-by: default avatarToni Barzic <tbarzic@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Commit-Queue: Xiaochu Liu <xiaochu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573512}
parent 70189979
......@@ -160,6 +160,7 @@ class CrostiniRestarter : public base::RefCountedThreadSafe<CrostiniRestarter> {
cros_component_manager->Load(
"cros-termina",
component_updater::CrOSComponentManager::MountPolicy::kMount,
component_updater::CrOSComponentManager::UpdatePolicy::kDontForce,
base::BindOnce(&CrostiniRestarter::InstallImageLoaderFinished,
base::WrapRefCounted(this)));
}
......
......@@ -112,6 +112,7 @@ void ComponentUpdaterServiceProvider::LoadComponent(
mount
? component_updater::CrOSComponentManager::MountPolicy::kMount
: component_updater::CrOSComponentManager::MountPolicy::kDontMount,
component_updater::CrOSComponentManager::UpdatePolicy::kDontForce,
base::Bind(&ComponentUpdaterServiceProvider::OnLoadComponent,
weak_ptr_factory_.GetWeakPtr(), method_call,
response_sender));
......
......@@ -230,6 +230,7 @@ class PrinterConfigurerImpl : public PrinterConfigurer {
g_browser_process->platform_part()->cros_component_manager()->Load(
component_name,
component_updater::CrOSComponentManager::MountPolicy::kMount,
component_updater::CrOSComponentManager::UpdatePolicy::kDontForce,
base::BindOnce(&PrinterConfigurerImpl::OnComponentLoad,
weak_factory_.GetWeakPtr(), printer, ppd_contents,
std::move(cb)));
......
......@@ -18,7 +18,6 @@
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/image_loader_client.h"
#include "components/component_updater/component_updater_paths.h"
#include "components/component_updater/component_updater_service.h"
#include "components/crx_file/id_util.h"
#include "content/public/browser/browser_thread.h"
#include "crypto/sha2.h"
......@@ -212,11 +211,20 @@ void CrOSComponentManager::SetDelegate(Delegate* delegate) {
void CrOSComponentManager::Load(const std::string& name,
MountPolicy mount_policy,
UpdatePolicy update_policy,
LoadCallback load_callback) {
if (!IsCompatible(name)) {
// A compatible component is not installed, start installation process.
// A compatible component is not installed.
// Start installation process.
auto* const cus = g_browser_process->component_updater();
Install(cus, name, mount_policy, std::move(load_callback));
Install(cus, name, OnDemandUpdater::Priority::FOREGROUND, mount_policy,
std::move(load_callback));
} else if (update_policy == UpdatePolicy::kForce) {
// Caller forces update check.
// Start update process.
auto* const cus = g_browser_process->component_updater();
Install(cus, name, OnDemandUpdater::Priority::BACKGROUND, mount_policy,
std::move(load_callback));
} else if (mount_policy == MountPolicy::kMount) {
// A compatible component is installed, load it.
LoadInternal(name, std::move(load_callback));
......@@ -277,6 +285,7 @@ void CrOSComponentManager::Register(ComponentUpdateService* cus,
void CrOSComponentManager::Install(ComponentUpdateService* cus,
const std::string& name,
OnDemandUpdater::Priority priority,
MountPolicy mount_policy,
LoadCallback load_callback) {
const ComponentConfig* config = FindConfig(name);
......@@ -287,21 +296,22 @@ void CrOSComponentManager::Install(ComponentUpdateService* cus,
base::FilePath()));
return;
}
Register(
cus, *config,
base::BindOnce(&CrOSComponentManager::StartInstall,
base::Unretained(this), cus, GenerateId(config->sha2hash),
base::BindOnce(&CrOSComponentManager::FinishInstall,
base::Unretained(this), name, mount_policy,
std::move(load_callback))));
Register(cus, *config,
base::BindOnce(
&CrOSComponentManager::StartInstall, base::Unretained(this), cus,
GenerateId(config->sha2hash), priority,
base::BindOnce(&CrOSComponentManager::FinishInstall,
base::Unretained(this), name, mount_policy,
std::move(load_callback))));
}
void CrOSComponentManager::StartInstall(
ComponentUpdateService* cus,
const std::string& id,
OnDemandUpdater::Priority priority,
update_client::Callback install_callback) {
cus->GetOnDemandUpdater().OnDemandUpdate(
id, OnDemandUpdater::Priority::FOREGROUND, std::move(install_callback));
cus->GetOnDemandUpdater().OnDemandUpdate(id, priority,
std::move(install_callback));
}
void CrOSComponentManager::FinishInstall(const std::string& name,
......
......@@ -13,6 +13,7 @@
#include "base/gtest_prod_util.h"
#include "base/optional.h"
#include "components/component_updater/component_installer.h"
#include "components/component_updater/component_updater_service.h"
#include "components/update_client/update_client.h"
namespace component_updater {
......@@ -84,10 +85,20 @@ class CrOSComponentManager {
// |path|, or an empty |path| otherwise.
using LoadCallback =
base::OnceCallback<void(Error error, const base::FilePath& path)>;
// Policy on mount operation.
enum class MountPolicy {
// Mount the component if installed.
kMount,
// Skip the mount operation.
kDontMount,
};
// Policy on update operation.
enum class UpdatePolicy {
// Force component update.
kForce,
// Do not update if a compatible component is installed.
kDontForce,
};
class Delegate {
public:
......@@ -104,6 +115,7 @@ class CrOSComponentManager {
// Installs a component and keeps it up-to-date.
void Load(const std::string& name,
MountPolicy mount_policy,
UpdatePolicy update_policy,
LoadCallback load_callback);
// Stops updating and removes a component.
......@@ -147,6 +159,7 @@ class CrOSComponentManager {
// Installs a component with a dedicated ComponentUpdateService instance.
void Install(ComponentUpdateService* cus,
const std::string& name,
OnDemandUpdater::Priority priority,
MountPolicy mount_policy,
LoadCallback load_callback);
......@@ -154,6 +167,7 @@ class CrOSComponentManager {
// |id| is the component id generated from its sha2 hash.
void StartInstall(ComponentUpdateService* cus,
const std::string& id,
OnDemandUpdater::Priority priority,
update_client::Callback install_callback);
// Calls LoadInternal to load the installed component.
......
......@@ -55,6 +55,7 @@ void MediaPerceptionAPIDelegateChromeOS::LoadCrOSComponent(
g_browser_process->platform_part()->cros_component_manager()->Load(
GetComponentNameForComponentType(type),
component_updater::CrOSComponentManager::MountPolicy::kMount,
component_updater::CrOSComponentManager::UpdatePolicy::kDontForce,
base::BindOnce(OnLoadComponent, std::move(load_callback)));
}
......
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