Commit a252e066 authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

cros: Launch Highlights app upon demo session start

1. Launch the Highlights app with AppLoadService (which is a wrapper
   of UnpackedInstaller).

2. Observing session state should be a cleaner solution, because we
   don't have to launch it from two places (user_session_manager for
   regular login, and chrome_session_manager for crash/restart).
   Launching it from two places are okay because we already have
   demo-mode related code in both places, but it may not be necessary
   for the Highlights app.

Bug: 819404
Change-Id: I3879df729f02c2477ca25511947b23ebe26e5ed1
Reviewed-on: https://chromium-review.googlesource.com/1176183
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585300}
parent 0d2fc4e4
...@@ -58,6 +58,7 @@ source_set("chromeos") { ...@@ -58,6 +58,7 @@ source_set("chromeos") {
"//chrome/app:command_ids", "//chrome/app:command_ids",
"//chrome/app/vector_icons", "//chrome/app/vector_icons",
"//chrome/browser/apps/foundation/app_service:lib", "//chrome/browser/apps/foundation/app_service:lib",
"//chrome/browser/apps/platform_apps",
"//chrome/browser/chromeos/android_sms:android_sms_urls", "//chrome/browser/chromeos/android_sms:android_sms_urls",
"//chrome/browser/chromeos/power/ml:user_activity_ukm_logger_helpers", "//chrome/browser/chromeos/power/ml:user_activity_ukm_logger_helpers",
"//chrome/browser/chromeos/power/ml/smart_dim", "//chrome/browser/chromeos/power/ml/smart_dim",
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_image_loader_client.h" #include "chromeos/dbus/fake_image_loader_client.h"
#include "components/session_manager/core/session_manager.h"
#include "components/user_manager/scoped_user_manager.h" #include "components/user_manager/scoped_user_manager.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/browser/external_install_info.h" #include "extensions/browser/external_install_info.h"
...@@ -122,6 +123,7 @@ class DemoExtensionsExternalLoaderTest : public testing::Test { ...@@ -122,6 +123,7 @@ class DemoExtensionsExternalLoaderTest : public testing::Test {
image_loader_client_ = image_loader_client.get(); image_loader_client_ = image_loader_client.get();
DBusThreadManager::GetSetterForTesting()->SetImageLoaderClient( DBusThreadManager::GetSetterForTesting()->SetImageLoaderClient(
std::move(image_loader_client)); std::move(image_loader_client));
session_manager_ = std::make_unique<session_manager::SessionManager>();
} }
void TearDown() override { void TearDown() override {
...@@ -213,6 +215,8 @@ class DemoExtensionsExternalLoaderTest : public testing::Test { ...@@ -213,6 +215,8 @@ class DemoExtensionsExternalLoaderTest : public testing::Test {
base::ScopedTempDir offline_demo_resources_; base::ScopedTempDir offline_demo_resources_;
std::unique_ptr<session_manager::SessionManager> session_manager_;
DISALLOW_COPY_AND_ASSIGN(DemoExtensionsExternalLoaderTest); DISALLOW_COPY_AND_ASSIGN(DemoExtensionsExternalLoaderTest);
}; };
...@@ -444,6 +448,7 @@ class ShouldCreateDemoExtensionsExternalLoaderTest : public testing::Test { ...@@ -444,6 +448,7 @@ class ShouldCreateDemoExtensionsExternalLoaderTest : public testing::Test {
user_manager_ = fake_user_manager.get(); user_manager_ = fake_user_manager.get();
scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>( scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>(
std::move(fake_user_manager)); std::move(fake_user_manager));
session_manager_ = std::make_unique<session_manager::SessionManager>();
} }
~ShouldCreateDemoExtensionsExternalLoaderTest() override = default; ~ShouldCreateDemoExtensionsExternalLoaderTest() override = default;
...@@ -483,6 +488,7 @@ class ShouldCreateDemoExtensionsExternalLoaderTest : public testing::Test { ...@@ -483,6 +488,7 @@ class ShouldCreateDemoExtensionsExternalLoaderTest : public testing::Test {
private: private:
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<user_manager::ScopedUserManager> scoped_user_manager_; std::unique_ptr<user_manager::ScopedUserManager> scoped_user_manager_;
std::unique_ptr<session_manager::SessionManager> session_manager_;
DISALLOW_COPY_AND_ASSIGN(ShouldCreateDemoExtensionsExternalLoaderTest); DISALLOW_COPY_AND_ASSIGN(ShouldCreateDemoExtensionsExternalLoaderTest);
}; };
......
...@@ -8,13 +8,18 @@ ...@@ -8,13 +8,18 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/command_line.h"
#include "base/sys_info.h"
#include "chrome/browser/apps/platform_apps/app_load_service.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_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/chromeos/settings/install_attributes.h" #include "chrome/browser/chromeos/settings/install_attributes.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/image_loader_client.h" #include "chromeos/dbus/image_loader_client.h"
#include "components/session_manager/core/session_manager.h"
namespace chromeos { namespace chromeos {
...@@ -48,6 +53,14 @@ constexpr base::FilePath::CharType kDemoAppsPath[] = ...@@ -48,6 +53,14 @@ constexpr base::FilePath::CharType kDemoAppsPath[] =
constexpr base::FilePath::CharType kExternalExtensionsPrefsPath[] = constexpr base::FilePath::CharType kExternalExtensionsPrefsPath[] =
FILE_PATH_LITERAL("demo_extensions.json"); FILE_PATH_LITERAL("demo_extensions.json");
// Path relative to the path at which offline demo resources are loaded that
// contains the highlights app.
constexpr char kHighlightsAppPath[] = "chrome_apps/highlights/dist";
// The name of the subdirectory that contains the resources for the default
// highlights app, used when a board-specific version is not available.
constexpr char kDefaultHighlightsAppResourcesPath[] = "default";
bool IsDemoModeOfflineEnrolled() { bool IsDemoModeOfflineEnrolled() {
DCHECK(DemoSession::IsDeviceInDemoMode()); DCHECK(DemoSession::IsDeviceInDemoMode());
return DemoSession::GetEnrollmentType() == return DemoSession::GetEnrollmentType() ==
...@@ -207,7 +220,12 @@ base::FilePath DemoSession::GetOfflineResourceAbsolutePath( ...@@ -207,7 +220,12 @@ base::FilePath DemoSession::GetOfflineResourceAbsolutePath(
} }
DemoSession::DemoSession() DemoSession::DemoSession()
: offline_enrolled_(IsDemoModeOfflineEnrolled()), weak_ptr_factory_(this) {} : offline_enrolled_(IsDemoModeOfflineEnrolled()),
session_manager_observer_(this),
weak_ptr_factory_(this) {
session_manager_observer_.Add(session_manager::SessionManager::Get());
OnSessionStateChanged();
}
DemoSession::~DemoSession() = default; DemoSession::~DemoSession() = default;
...@@ -224,4 +242,42 @@ void DemoSession::OnOfflineResourcesLoaded( ...@@ -224,4 +242,42 @@ void DemoSession::OnOfflineResourcesLoaded(
std::move(callback).Run(); std::move(callback).Run();
} }
void DemoSession::LoadAndLaunchHighlightsApp() {
DCHECK(offline_resources_loaded_);
if (offline_resources_path_.empty()) {
LOG(ERROR) << "Offline resources not loaded - no highlights app available.";
return;
}
Profile* profile = ProfileManager::GetPrimaryUserProfile();
DCHECK(profile);
const std::vector<std::string> board =
base::SplitString(base::SysInfo::GetLsbReleaseBoard(), "-",
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
const std::string board_name = board[0];
base::FilePath resources_path =
offline_resources_path_.Append(kHighlightsAppPath)
.Append(kDefaultHighlightsAppResourcesPath);
base::FilePath board_specific_resources_path =
offline_resources_path_.Append(kHighlightsAppPath).Append(board_name);
if (base::PathExists(board_specific_resources_path))
resources_path = board_specific_resources_path;
if (!apps::AppLoadService::Get(profile)->LoadAndLaunch(
resources_path, base::CommandLine(base::CommandLine::NO_PROGRAM),
base::FilePath() /* cur_dir */)) {
LOG(WARNING) << "Failed to launch highlights app!";
}
}
void DemoSession::OnSessionStateChanged() {
if (session_manager::SessionManager::Get()->session_state() !=
session_manager::SessionState::ACTIVE ||
!IsDeviceInDemoMode()) {
return;
}
EnsureOfflineResourcesLoaded(
base::BindOnce(&DemoSession::LoadAndLaunchHighlightsApp,
weak_ptr_factory_.GetWeakPtr()));
}
} // namespace chromeos } // namespace chromeos
...@@ -12,13 +12,19 @@ ...@@ -12,13 +12,19 @@
#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 "base/scoped_observer.h"
#include "chrome/browser/component_updater/cros_component_installer_chromeos.h" #include "chrome/browser/component_updater/cros_component_installer_chromeos.h"
#include "components/session_manager/core/session_manager_observer.h"
namespace session_manager {
class SessionManager;
}
namespace chromeos { namespace chromeos {
// Tracks global demo session state. For example, whether the demo session has // Tracks global demo session state. For example, whether the demo session has
// started, and whether the demo session offline resources have been loaded. // started, and whether the demo session offline resources have been loaded.
class DemoSession { class DemoSession : public session_manager::SessionManagerObserver {
public: public:
enum class EnrollmentType { enum class EnrollmentType {
// Demo mode enrollment unset/unknown. // Demo mode enrollment unset/unknown.
...@@ -95,7 +101,7 @@ class DemoSession { ...@@ -95,7 +101,7 @@ class DemoSession {
private: private:
DemoSession(); DemoSession();
~DemoSession(); ~DemoSession() override;
// Called after load of a currently installed (if any) demo mode resources // Called after load of a currently installed (if any) demo mode resources
// component has finished. // component has finished.
...@@ -109,6 +115,12 @@ class DemoSession { ...@@ -109,6 +115,12 @@ class DemoSession {
// |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);
// Loads and launches the highlights app.
void LoadAndLaunchHighlightsApp();
// session_manager::SessionManagerObserver:
void OnSessionStateChanged() override;
// Whether the device was offline-enrolled into demo mode, i.e. enrolled using // Whether the device was offline-enrolled into demo mode, i.e. enrolled using
// pre-built policies. Offline enrolled demo sessions do not have working // pre-built policies. Offline enrolled demo sessions do not have working
// robot account associated with them. // robot account associated with them.
...@@ -126,6 +138,10 @@ class DemoSession { ...@@ -126,6 +138,10 @@ class DemoSession {
// List of pending callbacks passed to EnsureOfflineResourcesLoaded(). // List of pending callbacks passed to EnsureOfflineResourcesLoaded().
std::list<base::OnceClosure> offline_resources_load_callbacks_; std::list<base::OnceClosure> offline_resources_load_callbacks_;
ScopedObserver<session_manager::SessionManager,
session_manager::SessionManagerObserver>
session_manager_observer_;
base::WeakPtrFactory<DemoSession> weak_ptr_factory_; base::WeakPtrFactory<DemoSession> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DemoSession); DISALLOW_COPY_AND_ASSIGN(DemoSession);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_image_loader_client.h" #include "chromeos/dbus/fake_image_loader_client.h"
#include "components/session_manager/core/session_manager.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -120,6 +121,7 @@ class DemoSessionTest : public testing::Test { ...@@ -120,6 +121,7 @@ class DemoSessionTest : public testing::Test {
image_loader_client_ = image_loader_client.get(); image_loader_client_ = image_loader_client.get();
chromeos::DBusThreadManager::GetSetterForTesting()->SetImageLoaderClient( chromeos::DBusThreadManager::GetSetterForTesting()->SetImageLoaderClient(
std::move(image_loader_client)); std::move(image_loader_client));
session_manager_ = std::make_unique<session_manager::SessionManager>();
} }
void TearDown() override { void TearDown() override {
...@@ -134,6 +136,7 @@ class DemoSessionTest : public testing::Test { ...@@ -134,6 +136,7 @@ class DemoSessionTest : public testing::Test {
// Points to the image loader client passed to the test DBusTestManager. // Points to the image loader client passed to the test DBusTestManager.
TestImageLoaderClient* image_loader_client_ = nullptr; TestImageLoaderClient* image_loader_client_ = nullptr;
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<session_manager::SessionManager> session_manager_;
private: private:
DISALLOW_COPY_AND_ASSIGN(DemoSessionTest); DISALLOW_COPY_AND_ASSIGN(DemoSessionTest);
......
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