Commit 792fe60c authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Load installed demo resources component when starting demo session

When initializing demo session (or preloading demo resoruces), register
and attempt to load demo mode resources component.

If demo mode resources component is not installed, demo_session will
attempt to load demo resources from a preinstalled path on the stateful
partition (if that fails, the session will continue without offline
demo mode resources).

To avoid CrOSComponentManager::Load blocking on component update if the
component is not installed, add new UpdatePolicy - kSkip. If set,
CrOSComponentManager will report error if a compatible component version
is not found after component registration. CrOSComponentManager::Load
will srill register the component with component updated, which means that
the component will eventually get updated, but the updater will not be run
as part of the requested component load.

NOTE: Currently, demo-mode-resources component load is expected to fail,
as the component config has still not been added to the
cros_component_installer_chromeos (this is blocked on server changes).

BUG=869455

Change-Id: I2c3b18d60edc44ae8ddbde27d6f31e91092216dd
Reviewed-on: https://chromium-review.googlesource.com/1164577
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582790}
parent 6e40985c
...@@ -140,7 +140,7 @@ class DemoExtensionsExternalLoaderTest : public testing::Test { ...@@ -140,7 +140,7 @@ class DemoExtensionsExternalLoaderTest : public testing::Test {
bool wait_for_offline_resources_load) { bool wait_for_offline_resources_load) {
if (mount_demo_resources) { if (mount_demo_resources) {
image_loader_client_->SetMountPathForComponent( image_loader_client_->SetMountPathForComponent(
"demo_mode_resources", offline_demo_resources_.GetPath()); "demo-mode-resources", offline_demo_resources_.GetPath());
} }
ASSERT_TRUE(DemoSession::StartIfInDemoMode()); ASSERT_TRUE(DemoSession::StartIfInDemoMode());
......
...@@ -29,11 +29,11 @@ DemoSession::EnrollmentType g_force_enrollment_type = ...@@ -29,11 +29,11 @@ DemoSession::EnrollmentType g_force_enrollment_type =
DemoSession::EnrollmentType::kNone; DemoSession::EnrollmentType::kNone;
// The name of the offline demo resource image loader component. // The name of the offline demo resource image loader component.
constexpr char kOfflineResourcesComponentName[] = "demo_mode_resources"; constexpr char kDemoResourcesComponentName[] = "demo-mode-resources";
// The path from which the offline demo mode resources component should be // The path from which the offline demo mode resources component should be
// loaded by the image loader service. // loaded by the image loader service.
constexpr base::FilePath::CharType kOfflineResourcesComponentPath[] = constexpr base::FilePath::CharType kPreInstalledDemoResourcesComponentPath[] =
FILE_PATH_LITERAL( FILE_PATH_LITERAL(
"/mnt/stateful_partition/unencrypted/demo_mode_resources"); "/mnt/stateful_partition/unencrypted/demo_mode_resources");
...@@ -135,13 +135,40 @@ void DemoSession::EnsureOfflineResourcesLoaded( ...@@ -135,13 +135,40 @@ void DemoSession::EnsureOfflineResourcesLoaded(
if (offline_resources_load_requested_) if (offline_resources_load_requested_)
return; return;
offline_resources_load_requested_ = true; offline_resources_load_requested_ = true;
component_updater::CrOSComponentManager* cros_component_manager =
g_browser_process->platform_part()->cros_component_manager();
if (cros_component_manager) {
g_browser_process->platform_part()->cros_component_manager()->Load(
kDemoResourcesComponentName,
component_updater::CrOSComponentManager::MountPolicy::kMount,
component_updater::CrOSComponentManager::UpdatePolicy::kSkip,
base::BindOnce(&DemoSession::InstalledComponentLoaded,
weak_ptr_factory_.GetWeakPtr()));
} else {
// Cros component manager may be unset in tests - if that is the case,
// report component install failure, so DemoSession attempts loading the
// component directly from the pre-installed component path.
InstalledComponentLoaded(
component_updater::CrOSComponentManager::Error::INSTALL_FAILURE,
base::FilePath());
}
}
void DemoSession::InstalledComponentLoaded(
component_updater::CrOSComponentManager::Error error,
const base::FilePath& path) {
if (error == component_updater::CrOSComponentManager::Error::NONE) {
OnOfflineResourcesLoaded(base::make_optional(path));
return;
}
chromeos::DBusThreadManager::Get() chromeos::DBusThreadManager::Get()
->GetImageLoaderClient() ->GetImageLoaderClient()
->LoadComponentAtPath( ->LoadComponentAtPath(
kOfflineResourcesComponentName, kDemoResourcesComponentName,
base::FilePath(kOfflineResourcesComponentPath), base::FilePath(kPreInstalledDemoResourcesComponentPath),
base::BindOnce(&DemoSession::OnOfflineResourcesLoaded, base::BindOnce(&DemoSession::OnOfflineResourcesLoaded,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h" #include "base/optional.h"
#include "chrome/browser/component_updater/cros_component_installer_chromeos.h"
namespace chromeos { namespace chromeos {
...@@ -90,6 +91,14 @@ class DemoSession { ...@@ -90,6 +91,14 @@ class DemoSession {
DemoSession(); DemoSession();
~DemoSession(); ~DemoSession();
// Called after load of a currently installed (if any) demo mode resources
// component has finished.
// On success, |path| is expected to contain the path as which the component
// is loaded.
void InstalledComponentLoaded(
component_updater::CrOSComponentManager::Error error,
const base::FilePath& path);
// Callback for the image loader request to load offline demo mode resources. // Callback for the image loader request to load offline demo mode resources.
// |mount_path| is the path at which the resources were loaded. // |mount_path| is the path at which the resources were loaded.
void OnOfflineResourcesLoaded(base::Optional<base::FilePath> mounted_path); void OnOfflineResourcesLoaded(base::Optional<base::FilePath> mounted_path);
......
...@@ -22,7 +22,7 @@ namespace chromeos { ...@@ -22,7 +22,7 @@ namespace chromeos {
namespace { namespace {
constexpr char kOfflineResourcesComponent[] = "demo_mode_resources"; constexpr char kOfflineResourcesComponent[] = "demo-mode-resources";
constexpr char kTestDemoModeResourcesMountPoint[] = constexpr char kTestDemoModeResourcesMountPoint[] =
"/run/imageloader/demo_mode_resources"; "/run/imageloader/demo_mode_resources";
constexpr char kDemoAppsImageFile[] = "android_demo_apps.squash"; constexpr char kDemoAppsImageFile[] = "android_demo_apps.squash";
......
...@@ -320,7 +320,8 @@ void CrOSComponentManager::StartInstall( ...@@ -320,7 +320,8 @@ void CrOSComponentManager::StartInstall(
// Check whether an installed component was found during registration, and // Check whether an installed component was found during registration, and
// determine whether OnDemandUpdater should be started accordingly. // determine whether OnDemandUpdater should be started accordingly.
const bool is_compatible = IsCompatible(name); const bool is_compatible = IsCompatible(name);
if (is_compatible && update_policy != UpdatePolicy::kForce) { if (update_policy == UpdatePolicy::kSkip ||
(is_compatible && update_policy != UpdatePolicy::kForce)) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(install_callback), FROM_HERE, base::BindOnce(std::move(install_callback),
update_client::Error::NONE)); update_client::Error::NONE));
......
...@@ -98,6 +98,9 @@ class CrOSComponentManager { ...@@ -98,6 +98,9 @@ class CrOSComponentManager {
kForce, kForce,
// Do not update if a compatible component is installed. // Do not update if a compatible component is installed.
kDontForce, kDontForce,
// Do not run updater, even if a compatible component is not installed at
// the moment.
kSkip
}; };
class Delegate { class Delegate {
......
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