Commit fe40bbc7 authored by Michael Giuffrida's avatar Michael Giuffrida Committed by Commit Bot

Move Demo Resources logic to new class

Creates the DemoResources class, removing the nitty-gritty details of
component loading from the global DemoSession instance.

This will make it simpler to update the offline-enrolled mode to use the
offline version of the Demo Mode Resources component. It will also allow
us to check for the existence of Demo Mode resources without starting a
a DemoSession, eg from OOBE.

DemoResources avoids using the term "offline resources" except in the
context of the preinstalled resources used in offline-enrolled Demo
Mode. General Demo Mode resources will just be called "Demo Resources"
or similar.

A follow-up change will update calls to
DemoSession::EnsureOfflineResourcesLoaded() to instead call a similar
function on DemoResources.

Bug: 904641
Change-Id: Ia931721511fac4efb9e796052bd760a87c952be9
Reviewed-on: https://chromium-review.googlesource.com/c/1333112
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarWenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608213}
parent 895bd797
...@@ -1006,6 +1006,8 @@ source_set("chromeos") { ...@@ -1006,6 +1006,8 @@ source_set("chromeos") {
"login/demo_mode/demo_mode_detector.h", "login/demo_mode/demo_mode_detector.h",
"login/demo_mode/demo_mode_resources_remover.cc", "login/demo_mode/demo_mode_resources_remover.cc",
"login/demo_mode/demo_mode_resources_remover.h", "login/demo_mode/demo_mode_resources_remover.h",
"login/demo_mode/demo_resources.cc",
"login/demo_mode/demo_resources.h",
"login/demo_mode/demo_session.cc", "login/demo_mode/demo_session.cc",
"login/demo_mode/demo_session.h", "login/demo_mode/demo_session.h",
"login/demo_mode/demo_setup_controller.cc", "login/demo_mode/demo_setup_controller.cc",
...@@ -2213,6 +2215,7 @@ source_set("unit_tests") { ...@@ -2213,6 +2215,7 @@ source_set("unit_tests") {
"login/demo_mode/demo_extensions_external_loader_unittest.cc", "login/demo_mode/demo_extensions_external_loader_unittest.cc",
"login/demo_mode/demo_mode_detector_unittest.cc", "login/demo_mode/demo_mode_detector_unittest.cc",
"login/demo_mode/demo_mode_resources_remover_unittest.cc", "login/demo_mode/demo_mode_resources_remover_unittest.cc",
"login/demo_mode/demo_resources_unittest.cc",
"login/demo_mode/demo_session_unittest.cc", "login/demo_mode/demo_session_unittest.cc",
"login/demo_mode/demo_setup_controller_unittest.cc", "login/demo_mode/demo_setup_controller_unittest.cc",
"login/demo_mode/demo_setup_test_utils.cc", "login/demo_mode/demo_setup_test_utils.cc",
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotiator.h" #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotiator.h"
#include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator.h" #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator.h"
#include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_resources.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h" #include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/lifetime/application_lifetime.h"
...@@ -1011,9 +1012,9 @@ void ArcSessionManager::StartArc() { ...@@ -1011,9 +1012,9 @@ void ArcSessionManager::StartArc() {
const chromeos::DemoSession* demo_session = chromeos::DemoSession::Get(); const chromeos::DemoSession* demo_session = chromeos::DemoSession::Get();
params.is_demo_session = demo_session && demo_session->started(); params.is_demo_session = demo_session && demo_session->started();
if (params.is_demo_session) { if (params.is_demo_session) {
DCHECK(demo_session->offline_resources_loaded()); DCHECK(demo_session->resources()->loaded());
base::FilePath demo_session_apps_path; params.demo_session_apps_path =
params.demo_session_apps_path = demo_session->GetDemoAppsPath(); demo_session->resources()->GetDemoAppsPath();
} }
params.supervision_transition = GetSupervisionTransition(profile_); params.supervision_transition = GetSupervisionTransition(profile_);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/extensions/external_cache_impl.h" #include "chrome/browser/chromeos/extensions/external_cache_impl.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_resources.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h" #include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/external_provider_impl.h" #include "chrome/browser/extensions/external_provider_impl.h"
...@@ -126,10 +127,10 @@ std::string DemoExtensionsExternalLoader::GetInstalledExtensionVersion( ...@@ -126,10 +127,10 @@ std::string DemoExtensionsExternalLoader::GetInstalledExtensionVersion(
void DemoExtensionsExternalLoader::StartLoadingFromOfflineDemoResources() { void DemoExtensionsExternalLoader::StartLoadingFromOfflineDemoResources() {
DemoSession* demo_session = DemoSession::Get(); DemoSession* demo_session = DemoSession::Get();
DCHECK(demo_session->offline_resources_loaded()); DCHECK(demo_session->resources()->loaded());
base::FilePath demo_extension_list = base::FilePath demo_extension_list =
demo_session->GetExternalExtensionsPrefsPath(); demo_session->resources()->GetExternalExtensionsPrefsPath();
if (demo_extension_list.empty()) { if (demo_extension_list.empty()) {
LoadFinished(std::make_unique<base::DictionaryValue>()); LoadFinished(std::make_unique<base::DictionaryValue>());
return; return;
...@@ -180,8 +181,8 @@ void DemoExtensionsExternalLoader::DemoExternalExtensionsPrefsLoaded( ...@@ -180,8 +181,8 @@ void DemoExtensionsExternalLoader::DemoExternalExtensionsPrefsLoaded(
dict_item.second.SetKey( dict_item.second.SetKey(
extensions::ExternalProviderImpl::kExternalCrx, extensions::ExternalProviderImpl::kExternalCrx,
base::Value(demo_session->GetOfflineResourceAbsolutePath(relative_path) base::Value(
.value())); demo_session->resources()->GetAbsolutePath(relative_path).value()));
} }
LoadFinished(base::DictionaryValue::From( LoadFinished(base::DictionaryValue::From(
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/idle_detector.h" #include "chrome/browser/chromeos/idle_detector.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_resources.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h" #include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/chromeos/login/users/chrome_user_manager.h" #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
...@@ -234,8 +235,7 @@ void DemoModeResourcesRemover::AttemptRemoval(RemovalReason reason, ...@@ -234,8 +235,7 @@ void DemoModeResourcesRemover::AttemptRemoval(RemovalReason reason,
base::PostTaskWithTraitsAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, FROM_HERE,
{base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}, {base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
base::BindOnce(&RemoveDirectory, base::BindOnce(&RemoveDirectory, DemoResources::GetPreInstalledPath()),
DemoSession::GetPreInstalledDemoResourcesPath()),
base::BindOnce(&DemoModeResourcesRemover::OnRemovalDone, base::BindOnce(&DemoModeResourcesRemover::OnRemovalDone,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/test/scoped_path_override.h" #include "base/test/scoped_path_override.h"
#include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_resources.h"
#include "chrome/browser/component_updater/fake_cros_component_manager.h" #include "chrome/browser/component_updater/fake_cros_component_manager.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chromeos/chromeos_paths.h" #include "chromeos/chromeos_paths.h"
...@@ -70,7 +71,7 @@ void DemoModeTestHelper::InitializeSessionWithPendingComponent( ...@@ -70,7 +71,7 @@ void DemoModeTestHelper::InitializeSessionWithPendingComponent(
base::FilePath DemoModeTestHelper::GetDemoResourcesPath() { base::FilePath DemoModeTestHelper::GetDemoResourcesPath() {
return components_temp_dir_.GetPath() return components_temp_dir_.GetPath()
.AppendASCII("cros-components") .AppendASCII("cros-components")
.AppendASCII(DemoSession::kDemoModeResourcesComponentName); .AppendASCII(DemoResources::kDemoModeResourcesComponentName);
} }
void DemoModeTestHelper::InitializeCrosComponentManager() { void DemoModeTestHelper::InitializeCrosComponentManager() {
...@@ -82,7 +83,7 @@ void DemoModeTestHelper::InitializeCrosComponentManager() { ...@@ -82,7 +83,7 @@ void DemoModeTestHelper::InitializeCrosComponentManager() {
// so components don't load instantly. // so components don't load instantly.
cros_component_manager->set_queue_load_requests(true); cros_component_manager->set_queue_load_requests(true);
cros_component_manager->set_supported_components( cros_component_manager->set_supported_components(
{DemoSession::kDemoModeResourcesComponentName}); {DemoResources::kDemoModeResourcesComponentName});
browser_process_platform_part_test_api_.InitializeCrosComponentManager( browser_process_platform_part_test_api_.InitializeCrosComponentManager(
std::move(cros_component_manager)); std::move(cros_component_manager));
...@@ -95,13 +96,13 @@ void DemoModeTestHelper::FinishLoadingComponent() { ...@@ -95,13 +96,13 @@ void DemoModeTestHelper::FinishLoadingComponent() {
// TODO(michaelpg): Update once offline Demo Mode also uses a CrOS component. // TODO(michaelpg): Update once offline Demo Mode also uses a CrOS component.
if (DemoSession::GetDemoConfig() == DemoSession::DemoModeConfig::kOnline) { if (DemoSession::GetDemoConfig() == DemoSession::DemoModeConfig::kOnline) {
CHECK(fake_cros_component_manager_->FinishLoadRequest( CHECK(fake_cros_component_manager_->FinishLoadRequest(
DemoSession::kDemoModeResourcesComponentName, DemoResources::kDemoModeResourcesComponentName,
component_updater::FakeCrOSComponentManager::ComponentInfo( component_updater::FakeCrOSComponentManager::ComponentInfo(
component_updater::CrOSComponentManager::Error::NONE, component_updater::CrOSComponentManager::Error::NONE,
base::FilePath("/dev/null"), GetDemoResourcesPath()))); base::FilePath("/dev/null"), GetDemoResourcesPath())));
} else { } else {
CHECK(!fake_cros_component_manager_->HasPendingInstall( CHECK(!fake_cros_component_manager_->HasPendingInstall(
DemoSession::kDemoModeResourcesComponentName)); DemoResources::kDemoModeResourcesComponentName));
} }
run_loop.Run(); run_loop.Run();
...@@ -114,7 +115,7 @@ void DemoModeTestHelper::FailLoadingComponent() { ...@@ -114,7 +115,7 @@ void DemoModeTestHelper::FailLoadingComponent() {
// TODO(michaelpg): Update once offline Demo Mode also uses a CrOS component. // TODO(michaelpg): Update once offline Demo Mode also uses a CrOS component.
if (DemoSession::GetDemoConfig() == DemoSession::DemoModeConfig::kOnline) { if (DemoSession::GetDemoConfig() == DemoSession::DemoModeConfig::kOnline) {
CHECK(fake_cros_component_manager_->FinishLoadRequest( CHECK(fake_cros_component_manager_->FinishLoadRequest(
DemoSession::kDemoModeResourcesComponentName, DemoResources::kDemoModeResourcesComponentName,
component_updater::FakeCrOSComponentManager::ComponentInfo( component_updater::FakeCrOSComponentManager::ComponentInfo(
component_updater::CrOSComponentManager::Error::INSTALL_FAILURE, component_updater::CrOSComponentManager::Error::INSTALL_FAILURE,
base::FilePath(), base::FilePath()))); base::FilePath(), base::FilePath())));
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/demo_mode/demo_resources.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/image_loader_client.h"
namespace chromeos {
namespace {
// Path relative to the path at which demo resources are loaded that
// contains image with demo Android apps.
constexpr base::FilePath::CharType kDemoAppsPath[] =
FILE_PATH_LITERAL("android_demo_apps.squash");
constexpr base::FilePath::CharType kExternalExtensionsPrefsPath[] =
FILE_PATH_LITERAL("demo_extensions.json");
} // namespace
// static
const char DemoResources::kDemoModeResourcesComponentName[] =
"demo-mode-resources";
// static
base::FilePath DemoResources::GetPreInstalledPath() {
base::FilePath preinstalled_components_root;
base::PathService::Get(DIR_PREINSTALLED_COMPONENTS,
&preinstalled_components_root);
return preinstalled_components_root.AppendASCII("cros-components")
.AppendASCII(kDemoModeResourcesComponentName);
}
DemoResources::DemoResources(DemoSession::DemoModeConfig config)
: config_(config), weak_ptr_factory_(this) {
DCHECK_NE(config_, DemoSession::DemoModeConfig::kNone);
}
DemoResources::~DemoResources() = default;
base::FilePath DemoResources::GetAbsolutePath(
const base::FilePath& relative_path) const {
if (path_.empty())
return base::FilePath();
if (relative_path.ReferencesParent())
return base::FilePath();
return path_.Append(relative_path);
}
base::FilePath DemoResources::GetDemoAppsPath() const {
if (path_.empty())
return base::FilePath();
return path_.Append(kDemoAppsPath);
}
base::FilePath DemoResources::GetExternalExtensionsPrefsPath() const {
if (path_.empty())
return base::FilePath();
return path_.Append(kExternalExtensionsPrefsPath);
}
void DemoResources::EnsureLoaded(base::OnceClosure load_callback) {
if (loaded_) {
if (load_callback)
std::move(load_callback).Run();
return;
}
if (load_callback)
load_callbacks_.emplace_back(std::move(load_callback));
if (load_requested_)
return;
load_requested_ = true;
if (config_ == DemoSession::DemoModeConfig::kOffline) {
LoadPreinstalledOfflineResources();
return;
}
component_updater::CrOSComponentManager* cros_component_manager =
g_browser_process->platform_part()->cros_component_manager();
// In unit tests, DemoModeTestHelper should set up a fake
// CrOSComponentManager.
DCHECK(cros_component_manager);
g_browser_process->platform_part()->cros_component_manager()->Load(
kDemoModeResourcesComponentName,
component_updater::CrOSComponentManager::MountPolicy::kMount,
component_updater::CrOSComponentManager::UpdatePolicy::kSkip,
base::BindOnce(&DemoResources::InstalledComponentLoaded,
weak_ptr_factory_.GetWeakPtr()));
}
void DemoResources::SetLoadedForTesting(const base::FilePath& path) {
OnDemoResourcesLoaded(path);
}
void DemoResources::InstalledComponentLoaded(
component_updater::CrOSComponentManager::Error error,
const base::FilePath& path) {
if (error == component_updater::CrOSComponentManager::Error::NONE) {
OnDemoResourcesLoaded(base::make_optional(path));
return;
}
LoadPreinstalledOfflineResources();
}
void DemoResources::LoadPreinstalledOfflineResources() {
chromeos::DBusThreadManager::Get()
->GetImageLoaderClient()
->LoadComponentAtPath(
kDemoModeResourcesComponentName, GetPreInstalledPath(),
base::BindOnce(&DemoResources::OnDemoResourcesLoaded,
weak_ptr_factory_.GetWeakPtr()));
}
void DemoResources::OnDemoResourcesLoaded(
base::Optional<base::FilePath> mounted_path) {
loaded_ = true;
if (mounted_path.has_value())
path_ = mounted_path.value();
std::list<base::OnceClosure> load_callbacks;
load_callbacks.swap(load_callbacks_);
for (auto& callback : load_callbacks)
std::move(callback).Run();
}
} // namespace chromeos
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_DEMO_MODE_DEMO_RESOURCES_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_DEMO_MODE_DEMO_RESOURCES_H_
#include <list>
#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/component_updater/cros_component_installer_chromeos.h"
namespace chromeos {
class DemoResources {
public:
// The name of the demo mode resources CrOS component or preinstalled
// imageloader image.
static const char kDemoModeResourcesComponentName[];
// Location on disk where pre-installed demo mode resources are expected to be
// found.
static base::FilePath GetPreInstalledPath();
explicit DemoResources(DemoSession::DemoModeConfig config);
~DemoResources();
// Converts a relative path to an absolute path under the demo
// resources mount. Returns an empty string if the demo resources are
// not loaded.
base::FilePath GetAbsolutePath(const base::FilePath& relative_path) const;
// Gets the path of the image containing demo session Android apps. The path
// will be set when the demo resources get loaded.
base::FilePath GetDemoAppsPath() const;
// Gets the path under demo resources mount point that contains
// external extensions prefs (JSON containing set of extensions to be loaded
// as external extensions into demo sessions - expected to map extension IDs
// to the associated CRX path and version).
base::FilePath GetExternalExtensionsPrefsPath() const;
// Ensures that the load of demo session resources is requested.
// |load_callback| will be run once the resources finish loading.
void EnsureLoaded(base::OnceClosure load_callback);
// Fakes demo session resources having been requested and mounted at
// the given path (or not mounted if |path| is empty).
void SetLoadedForTesting(const base::FilePath& path);
bool loaded() const { return loaded_; }
const base::FilePath& path() const { return path_; }
private:
// 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);
// Loads the preinstalled offline resources image.
void LoadPreinstalledOfflineResources();
// Callback for the component or image loader request to load demo resources.
// |mount_path| is the path at which the resources were loaded.
void OnDemoResourcesLoaded(base::Optional<base::FilePath> mounted_path);
// Which config the device is configured for. Determines which resources will
// be loaded.
DemoSession::DemoModeConfig config_;
bool load_requested_ = false;
bool loaded_ = false;
// Path at which demo mode resources were loaded.
base::FilePath path_;
// List of pending callbacks passed to EnsureLoaded().
std::list<base::OnceClosure> load_callbacks_;
base::WeakPtrFactory<DemoResources> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DemoResources);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_DEMO_MODE_DEMO_RESOURCES_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_resources.h"
#include "chrome/browser/component_updater/fake_cros_component_manager.h"
#include "chrome/test/base/browser_process_platform_part_test_api_chromeos.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
using component_updater::FakeCrOSComponentManager;
namespace chromeos {
namespace {
constexpr char kOfflineResourcesComponent[] = "demo-mode-resources";
constexpr char kTestDemoModeResourcesMountPoint[] =
"/run/imageloader/demo_mode_resources";
constexpr char kDemoAppsImageFile[] = "android_demo_apps.squash";
constexpr char kExternalExtensionsPrefsFile[] = "demo_extensions.json";
void SetBoolean(bool* value) {
*value = true;
}
} // namespace
class DemoResourcesTest : public testing::Test {
public:
DemoResourcesTest()
: browser_process_platform_part_test_api_(
g_browser_process->platform_part()) {}
~DemoResourcesTest() override = default;
void SetUp() override {
chromeos::DBusThreadManager::Initialize();
InitializeCrosComponentManager();
}
void TearDown() override {
chromeos::DBusThreadManager::Shutdown();
cros_component_manager_ = nullptr;
browser_process_platform_part_test_api_.ShutdownCrosComponentManager();
}
protected:
bool FinishResourcesComponentLoad(const base::FilePath& mount_path) {
EXPECT_TRUE(
cros_component_manager_->HasPendingInstall(kOfflineResourcesComponent));
EXPECT_FALSE(
cros_component_manager_->UpdateRequested(kOfflineResourcesComponent));
return cros_component_manager_->FinishLoadRequest(
kOfflineResourcesComponent,
FakeCrOSComponentManager::ComponentInfo(
component_updater::CrOSComponentManager::Error::NONE,
base::FilePath("/dev/null"), mount_path));
}
void InitializeCrosComponentManager() {
auto fake_cros_component_manager =
std::make_unique<FakeCrOSComponentManager>();
fake_cros_component_manager->set_queue_load_requests(true);
fake_cros_component_manager->set_supported_components(
{kOfflineResourcesComponent});
cros_component_manager_ = fake_cros_component_manager.get();
browser_process_platform_part_test_api_.InitializeCrosComponentManager(
std::move(fake_cros_component_manager));
}
FakeCrOSComponentManager* cros_component_manager_ = nullptr;
content::TestBrowserThreadBundle thread_bundle_;
private:
BrowserProcessPlatformPartTestApi browser_process_platform_part_test_api_;
DISALLOW_COPY_AND_ASSIGN(DemoResourcesTest);
};
TEST_F(DemoResourcesTest, GetPaths) {
DemoResources demo_resources(DemoSession::DemoModeConfig::kOnline);
demo_resources.EnsureLoaded(base::DoNothing());
EXPECT_FALSE(demo_resources.loaded());
const base::FilePath component_mount_point =
base::FilePath(kTestDemoModeResourcesMountPoint);
ASSERT_TRUE(FinishResourcesComponentLoad(component_mount_point));
EXPECT_TRUE(demo_resources.loaded());
EXPECT_EQ(component_mount_point.AppendASCII(kDemoAppsImageFile),
demo_resources.GetDemoAppsPath());
EXPECT_EQ(component_mount_point.AppendASCII(kExternalExtensionsPrefsFile),
demo_resources.GetExternalExtensionsPrefsPath());
EXPECT_EQ(component_mount_point.AppendASCII("foo.txt"),
demo_resources.GetAbsolutePath(base::FilePath("foo.txt")));
EXPECT_EQ(component_mount_point.AppendASCII("foo/bar.txt"),
demo_resources.GetAbsolutePath(base::FilePath("foo/bar.txt")));
EXPECT_EQ(component_mount_point.AppendASCII("foo/"),
demo_resources.GetAbsolutePath(base::FilePath("foo/")));
EXPECT_TRUE(
demo_resources.GetAbsolutePath(base::FilePath("../foo/")).empty());
EXPECT_TRUE(
demo_resources.GetAbsolutePath(base::FilePath("foo/../bar")).empty());
}
TEST_F(DemoResourcesTest, LoadResourcesOnline) {
DemoResources demo_resources(DemoSession::DemoModeConfig::kOnline);
demo_resources.EnsureLoaded(base::DoNothing());
EXPECT_FALSE(demo_resources.loaded());
ASSERT_TRUE(FinishResourcesComponentLoad(
base::FilePath(kTestDemoModeResourcesMountPoint)));
EXPECT_FALSE(
cros_component_manager_->HasPendingInstall(kOfflineResourcesComponent));
EXPECT_TRUE(demo_resources.loaded());
}
TEST_F(DemoResourcesTest, LoadResourcesOffline) {
DemoResources demo_resources(DemoSession::DemoModeConfig::kOffline);
demo_resources.EnsureLoaded(base::DoNothing());
EXPECT_FALSE(demo_resources.loaded());
EXPECT_FALSE(
cros_component_manager_->HasPendingInstall(kOfflineResourcesComponent));
demo_resources.SetLoadedForTesting(
base::FilePath(kTestDemoModeResourcesMountPoint));
EXPECT_TRUE(demo_resources.loaded());
}
TEST_F(DemoResourcesTest, EnsureLoadedRepeatedlyOnline) {
DemoResources demo_resources(DemoSession::DemoModeConfig::kOnline);
bool first_callback_called = false;
demo_resources.EnsureLoaded(
base::BindOnce(&SetBoolean, &first_callback_called));
bool second_callback_called = false;
demo_resources.EnsureLoaded(
base::BindOnce(&SetBoolean, &second_callback_called));
bool third_callback_called = false;
demo_resources.EnsureLoaded(
base::BindOnce(&SetBoolean, &third_callback_called));
EXPECT_FALSE(demo_resources.loaded());
EXPECT_FALSE(first_callback_called);
EXPECT_FALSE(second_callback_called);
EXPECT_FALSE(third_callback_called);
ASSERT_TRUE(FinishResourcesComponentLoad(
base::FilePath(kTestDemoModeResourcesMountPoint)));
EXPECT_FALSE(
cros_component_manager_->HasPendingInstall(kOfflineResourcesComponent));
EXPECT_TRUE(demo_resources.loaded());
EXPECT_TRUE(first_callback_called);
EXPECT_TRUE(second_callback_called);
EXPECT_TRUE(third_callback_called);
bool fourth_callback_called = false;
demo_resources.EnsureLoaded(
base::BindOnce(&SetBoolean, &fourth_callback_called));
EXPECT_TRUE(fourth_callback_called);
bool fifth_callback_called = false;
demo_resources.EnsureLoaded(
base::BindOnce(&SetBoolean, &fifth_callback_called));
EXPECT_TRUE(fifth_callback_called);
EXPECT_TRUE(demo_resources.loaded());
}
TEST_F(DemoResourcesTest, EnsureLoadedRepeatedlyOffline) {
DemoResources demo_resources(DemoSession::DemoModeConfig::kOffline);
bool first_callback_called = false;
demo_resources.EnsureLoaded(
base::BindOnce(&SetBoolean, &first_callback_called));
bool second_callback_called = false;
demo_resources.EnsureLoaded(
base::BindOnce(&SetBoolean, &second_callback_called));
bool third_callback_called = false;
demo_resources.EnsureLoaded(
base::BindOnce(&SetBoolean, &third_callback_called));
EXPECT_FALSE(demo_resources.loaded());
EXPECT_FALSE(first_callback_called);
EXPECT_FALSE(second_callback_called);
EXPECT_FALSE(third_callback_called);
const base::FilePath component_mount_point =
base::FilePath(kTestDemoModeResourcesMountPoint);
demo_resources.SetLoadedForTesting(component_mount_point);
EXPECT_TRUE(demo_resources.loaded());
EXPECT_TRUE(first_callback_called);
EXPECT_TRUE(second_callback_called);
EXPECT_TRUE(third_callback_called);
EXPECT_EQ(component_mount_point.AppendASCII(kDemoAppsImageFile),
demo_resources.GetDemoAppsPath());
EXPECT_EQ(component_mount_point.AppendASCII(kExternalExtensionsPrefsFile),
demo_resources.GetExternalExtensionsPrefsPath());
bool fourth_callback_called = false;
demo_resources.EnsureLoaded(
base::BindOnce(&SetBoolean, &fourth_callback_called));
EXPECT_TRUE(fourth_callback_called);
bool fifth_callback_called = false;
demo_resources.EnsureLoaded(
base::BindOnce(&SetBoolean, &fifth_callback_called));
EXPECT_TRUE(fifth_callback_called);
EXPECT_TRUE(demo_resources.loaded());
}
} // namespace chromeos
...@@ -10,9 +10,10 @@ ...@@ -10,9 +10,10 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/logging.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/path_service.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -20,17 +21,14 @@ ...@@ -20,17 +21,14 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/file_manager/path_util.h" #include "chrome/browser/chromeos/file_manager/path_util.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_resources.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_setup_controller.h" #include "chrome/browser/chromeos/login/demo_mode/demo_setup_controller.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/extensions/app_launch_params.h" #include "chrome/browser/ui/extensions/app_launch_params.h"
#include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/image_loader_client.h"
#include "chromeos/settings/install_attributes.h" #include "chromeos/settings/install_attributes.h"
#include "components/language/core/browser/pref_names.h" #include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
...@@ -53,14 +51,6 @@ DemoSession* g_demo_session = nullptr; ...@@ -53,14 +51,6 @@ DemoSession* g_demo_session = nullptr;
// Type of demo config forced on for tests. // Type of demo config forced on for tests.
base::Optional<DemoSession::DemoModeConfig> g_force_demo_config; base::Optional<DemoSession::DemoModeConfig> g_force_demo_config;
// Path relative to the path at which offline demo resources are loaded that
// contains image with demo Android apps.
constexpr base::FilePath::CharType kDemoAppsPath[] =
FILE_PATH_LITERAL("android_demo_apps.squash");
constexpr base::FilePath::CharType kExternalExtensionsPrefsPath[] =
FILE_PATH_LITERAL("demo_extensions.json");
// Path relative to the path at which offline demo resources are loaded that // Path relative to the path at which offline demo resources are loaded that
// contains the highlights app. // contains the highlights app.
constexpr char kHighlightsAppPath[] = "chrome_apps/highlights"; constexpr char kHighlightsAppPath[] = "chrome_apps/highlights";
...@@ -160,19 +150,6 @@ void RestoreDefaultLocaleForNextSession() { ...@@ -160,19 +150,6 @@ void RestoreDefaultLocaleForNextSession() {
} // namespace } // namespace
// static
const char DemoSession::kDemoModeResourcesComponentName[] =
"demo-mode-resources";
// static
base::FilePath DemoSession::GetPreInstalledDemoResourcesPath() {
base::FilePath preinstalled_components_root;
base::PathService::Get(DIR_PREINSTALLED_COMPONENTS,
&preinstalled_components_root);
return preinstalled_components_root.AppendASCII("cros-components")
.AppendASCII(kDemoModeResourcesComponentName);
}
// static // static
std::string DemoSession::DemoConfigToString( std::string DemoSession::DemoConfigToString(
DemoSession::DemoModeConfig config) { DemoSession::DemoModeConfig config) {
...@@ -316,62 +293,9 @@ void DemoSession::RegisterLocalStatePrefs(PrefRegistrySimple* registry) { ...@@ -316,62 +293,9 @@ void DemoSession::RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
void DemoSession::EnsureOfflineResourcesLoaded( void DemoSession::EnsureOfflineResourcesLoaded(
base::OnceClosure load_callback) { base::OnceClosure load_callback) {
if (offline_resources_loaded_) { if (!demo_resources_)
if (load_callback) demo_resources_ = std::make_unique<DemoResources>(GetDemoConfig());
std::move(load_callback).Run(); demo_resources_->EnsureLoaded(std::move(load_callback));
return;
}
if (load_callback)
offline_resources_load_callbacks_.emplace_back(std::move(load_callback));
if (offline_resources_load_requested_)
return;
offline_resources_load_requested_ = true;
if (offline_enrolled_) {
LoadPreinstalledOfflineResources();
return;
}
component_updater::CrOSComponentManager* cros_component_manager =
g_browser_process->platform_part()->cros_component_manager();
// In unit tests, DemoModeTestHelper should set up a fake
// CrOSComponentManager.
DCHECK(cros_component_manager);
g_browser_process->platform_part()->cros_component_manager()->Load(
kDemoModeResourcesComponentName,
component_updater::CrOSComponentManager::MountPolicy::kMount,
component_updater::CrOSComponentManager::UpdatePolicy::kSkip,
base::BindOnce(&DemoSession::InstalledComponentLoaded,
weak_ptr_factory_.GetWeakPtr()));
}
void DemoSession::SetOfflineResourcesLoadedForTesting(
const base::FilePath& path) {
OnOfflineResourcesLoaded(path);
}
base::FilePath DemoSession::GetDemoAppsPath() const {
if (offline_resources_path_.empty())
return base::FilePath();
return offline_resources_path_.Append(kDemoAppsPath);
}
base::FilePath DemoSession::GetExternalExtensionsPrefsPath() const {
if (offline_resources_path_.empty())
return base::FilePath();
return offline_resources_path_.Append(kExternalExtensionsPrefsPath);
}
base::FilePath DemoSession::GetOfflineResourceAbsolutePath(
const base::FilePath& relative_path) const {
if (offline_resources_path_.empty())
return base::FilePath();
if (relative_path.ReferencesParent())
return base::FilePath();
return offline_resources_path_.Append(relative_path);
} }
bool DemoSession::ShouldIgnorePinPolicy(const std::string& app_id_or_package) { bool DemoSession::ShouldIgnorePinPolicy(const std::string& app_id_or_package) {
...@@ -413,51 +337,18 @@ DemoSession::DemoSession() ...@@ -413,51 +337,18 @@ DemoSession::DemoSession()
DemoSession::~DemoSession() = default; DemoSession::~DemoSession() = default;
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;
}
LoadPreinstalledOfflineResources();
}
void DemoSession::LoadPreinstalledOfflineResources() {
chromeos::DBusThreadManager::Get()
->GetImageLoaderClient()
->LoadComponentAtPath(
kDemoModeResourcesComponentName, GetPreInstalledDemoResourcesPath(),
base::BindOnce(&DemoSession::OnOfflineResourcesLoaded,
weak_ptr_factory_.GetWeakPtr()));
}
void DemoSession::OnOfflineResourcesLoaded(
base::Optional<base::FilePath> mounted_path) {
offline_resources_loaded_ = true;
if (mounted_path.has_value())
offline_resources_path_ = mounted_path.value();
std::list<base::OnceClosure> load_callbacks;
load_callbacks.swap(offline_resources_load_callbacks_);
for (auto& callback : load_callbacks)
std::move(callback).Run();
}
void DemoSession::InstallDemoResources() { void DemoSession::InstallDemoResources() {
DCHECK(offline_resources_loaded_); DCHECK(demo_resources_->loaded());
if (offline_enrolled_) if (offline_enrolled_)
LoadAndLaunchHighlightsApp(); LoadAndLaunchHighlightsApp();
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()}, FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()},
base::BindOnce(&InstallDemoMedia, offline_resources_path_)); base::BindOnce(&InstallDemoMedia, demo_resources_->path()));
} }
void DemoSession::LoadAndLaunchHighlightsApp() { void DemoSession::LoadAndLaunchHighlightsApp() {
DCHECK(offline_resources_loaded_); DCHECK(demo_resources_->loaded());
if (offline_resources_path_.empty()) { if (demo_resources_->path().empty()) {
LOG(ERROR) << "Offline resources not loaded - no highlights app available."; LOG(ERROR) << "Offline resources not loaded - no highlights app available.";
InstallAppFromUpdateUrl(GetHighlightsAppId()); InstallAppFromUpdateUrl(GetHighlightsAppId());
return; return;
...@@ -465,7 +356,7 @@ void DemoSession::LoadAndLaunchHighlightsApp() { ...@@ -465,7 +356,7 @@ void DemoSession::LoadAndLaunchHighlightsApp() {
Profile* profile = ProfileManager::GetActiveUserProfile(); Profile* profile = ProfileManager::GetActiveUserProfile();
DCHECK(profile); DCHECK(profile);
const base::FilePath resources_path = const base::FilePath resources_path =
offline_resources_path_.Append(kHighlightsAppPath); demo_resources_->path().Append(kHighlightsAppPath);
if (!apps::AppLoadService::Get(profile)->LoadAndLaunch( if (!apps::AppLoadService::Get(profile)->LoadAndLaunch(
resources_path, base::CommandLine(base::CommandLine::NO_PROGRAM), resources_path, base::CommandLine(base::CommandLine::NO_PROGRAM),
base::FilePath() /* cur_dir */)) { base::FilePath() /* cur_dir */)) {
......
...@@ -5,31 +5,30 @@ ...@@ -5,31 +5,30 @@
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_DEMO_MODE_DEMO_SESSION_H_ #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_DEMO_MODE_DEMO_SESSION_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_DEMO_MODE_DEMO_SESSION_H_ #define CHROME_BROWSER_CHROMEOS_LOGIN_DEMO_MODE_DEMO_SESSION_H_
#include <list>
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_extensions_external_loader.h" #include "chrome/browser/chromeos/login/demo_mode/demo_extensions_external_loader.h"
#include "chrome/browser/component_updater/cros_component_installer_chromeos.h"
#include "components/session_manager/core/session_manager_observer.h" #include "components/session_manager/core/session_manager_observer.h"
#include "extensions/browser/extension_registry_observer.h" #include "extensions/browser/extension_registry_observer.h"
class PrefRegistrySimple;
namespace session_manager { namespace session_manager {
class SessionManager; class SessionManager;
} }
namespace chromeos { namespace chromeos {
// Tracks global demo session state. For example, whether the demo session has class DemoResources;
// started, and whether the demo session offline resources have been loaded.
// TODO(michaelpg): Componentize the logic for providing offline resources. // Tracks global demo session state, such as whether the demo session has
// started and the state of demo mode resources.
class DemoSession : public session_manager::SessionManagerObserver, class DemoSession : public session_manager::SessionManagerObserver,
extensions::ExtensionRegistryObserver { extensions::ExtensionRegistryObserver {
public: public:
...@@ -49,14 +48,6 @@ class DemoSession : public session_manager::SessionManagerObserver, ...@@ -49,14 +48,6 @@ class DemoSession : public session_manager::SessionManagerObserver,
kLast = kOffline, kLast = kOffline,
}; };
// The name of the demo mode resources CrOS component or preinstalled
// imageloader image.
static const char kDemoModeResourcesComponentName[];
// Location on disk where pre-installed demo mode resources are expected to be
// found.
static base::FilePath GetPreInstalledDemoResourcesPath();
static std::string DemoConfigToString(DemoModeConfig config); static std::string DemoConfigToString(DemoModeConfig config);
// Whether the device is set up to run demo sessions. // Whether the device is set up to run demo sessions.
...@@ -102,26 +93,6 @@ class DemoSession : public session_manager::SessionManagerObserver, ...@@ -102,26 +93,6 @@ class DemoSession : public session_manager::SessionManagerObserver,
// |load_callback| will be run once the offline resource load finishes. // |load_callback| will be run once the offline resource load finishes.
void EnsureOfflineResourcesLoaded(base::OnceClosure load_callback); void EnsureOfflineResourcesLoaded(base::OnceClosure load_callback);
// Fakes offline demo session resources having been requested and mounted at
// the given path (or not mounted if |path| is empty).
void SetOfflineResourcesLoadedForTesting(const base::FilePath& path);
// Gets the path of the image containing demo session Android apps. The path
// will be set when the offline resources get loaded.
base::FilePath GetDemoAppsPath() const;
// Gets the path under offline demo resources mount point that contains
// external extensions prefs (JSON containing set of extensions to be loaded
// as external extensions into demo sessions - expected to map extension IDs
// to the associated CRX path and version).
base::FilePath GetExternalExtensionsPrefsPath() const;
// Converts a relative path to an absolute path under the offline demo
// resources mount. Returns an empty string if the offline demo resources are
// not loaded.
base::FilePath GetOfflineResourceAbsolutePath(
const base::FilePath& relative_path) const;
// Returns true if the Chrome app or ARC++ package, which is normally pinned // Returns true if the Chrome app or ARC++ package, which is normally pinned
// by policy, should actually not be force-pinned because the device is // by policy, should actually not be force-pinned because the device is
// in Demo Mode and offline. // in Demo Mode and offline.
...@@ -139,27 +110,12 @@ class DemoSession : public session_manager::SessionManagerObserver, ...@@ -139,27 +110,12 @@ class DemoSession : public session_manager::SessionManagerObserver,
bool started() const { return started_; } bool started() const { return started_; }
bool offline_resources_loaded() const { return offline_resources_loaded_; } const DemoResources* resources() const { return demo_resources_.get(); }
private: private:
DemoSession(); DemoSession();
~DemoSession() override; ~DemoSession() override;
// 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);
// Loads the preinstalled offline resources image.
void LoadPreinstalledOfflineResources();
// Callback for the image loader request to load offline demo mode resources.
// |mount_path| is the path at which the resources were loaded.
void OnOfflineResourcesLoaded(base::Optional<base::FilePath> mounted_path);
// Installs resources for Demo Mode from the offline demo mode resources, such // Installs resources for Demo Mode from the offline demo mode resources, such
// as apps and media. // as apps and media.
void InstallDemoResources(); void InstallDemoResources();
...@@ -188,17 +144,10 @@ class DemoSession : public session_manager::SessionManagerObserver, ...@@ -188,17 +144,10 @@ class DemoSession : public session_manager::SessionManagerObserver,
// Whether demo session has been started. // Whether demo session has been started.
bool started_ = false; bool started_ = false;
bool offline_resources_load_requested_ = false;
bool offline_resources_loaded_ = false;
// Path at which offline demo mode resources were loaded.
base::FilePath offline_resources_path_;
// Apps that ShouldIgnorePinPolicy() will check for if the device is offline. // Apps that ShouldIgnorePinPolicy() will check for if the device is offline.
std::vector<std::string> ignore_pin_policy_offline_apps_; std::vector<std::string> ignore_pin_policy_offline_apps_;
// List of pending callbacks passed to EnsureOfflineResourcesLoaded(). std::unique_ptr<DemoResources> demo_resources_;
std::list<base::OnceClosure> offline_resources_load_callbacks_;
ScopedObserver<session_manager::SessionManager, ScopedObserver<session_manager::SessionManager,
session_manager::SessionManagerObserver> session_manager::SessionManagerObserver>
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_resources.h"
#include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h"
#include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/chromeos/login/wizard_controller.h"
...@@ -545,7 +546,7 @@ void DemoSetupController::LoadDemoResourcesCrOSComponent() { ...@@ -545,7 +546,7 @@ void DemoSetupController::LoadDemoResourcesCrOSComponent() {
} }
cros_component_manager->Load( cros_component_manager->Load(
DemoSession::kDemoModeResourcesComponentName, DemoResources::kDemoModeResourcesComponentName,
component_updater::CrOSComponentManager::MountPolicy::kMount, component_updater::CrOSComponentManager::MountPolicy::kMount,
component_updater::CrOSComponentManager::UpdatePolicy::kDontForce, component_updater::CrOSComponentManager::UpdatePolicy::kDontForce,
base::BindOnce(&DemoSetupController::OnDemoResourcesCrOSComponentLoaded, base::BindOnce(&DemoSetupController::OnDemoResourcesCrOSComponentLoaded,
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chrome/browser/chromeos/child_accounts/screen_time_controller_factory.h" #include "chrome/browser/chromeos/child_accounts/screen_time_controller_factory.h"
#include "chrome/browser/chromeos/crostini/crostini_manager.h" #include "chrome/browser/chromeos/crostini/crostini_manager.h"
#include "chrome/browser/chromeos/lock_screen_apps/state_controller.h" #include "chrome/browser/chromeos/lock_screen_apps/state_controller.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_resources.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h" #include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/chromeos/login/lock/webui_screen_locker.h" #include "chrome/browser/chromeos/login/lock/webui_screen_locker.h"
#include "chrome/browser/chromeos/login/login_wizard.h" #include "chrome/browser/chromeos/login/login_wizard.h"
...@@ -124,7 +125,7 @@ void StartUserSession(Profile* user_profile, const std::string& login_user_id) { ...@@ -124,7 +125,7 @@ void StartUserSession(Profile* user_profile, const std::string& login_user_id) {
// In demo session, delay starting user session until the offline demo // In demo session, delay starting user session until the offline demo
// session resources have been loaded. // session resources have been loaded.
if (demo_session && demo_session->started() && if (demo_session && demo_session->started() &&
!demo_session->offline_resources_loaded()) { !demo_session->resources()->loaded()) {
demo_session->EnsureOfflineResourcesLoaded( demo_session->EnsureOfflineResourcesLoaded(
base::BindOnce(&StartUserSession, user_profile, login_user_id)); base::BindOnce(&StartUserSession, user_profile, login_user_id));
LOG(WARNING) << "Delay demo user session start until offline demo " LOG(WARNING) << "Delay demo user session start until offline demo "
......
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