Skip to content

Commit

Permalink
Hook up ChromeApp kiosk mojom on Lacros side
Browse files Browse the repository at this point in the history
This CL hooks up the Lacros side of the ChromeApp kiosk implementation. Lacros Kiosk won't be functional yet with this, as Ash side still needs to be hooked up.

Bug: b/217860344
Test: Manual (no-op)
Change-Id: Ic04d3ee0374bfb2c426592e0ca600949525462e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3623722
Commit-Queue: Ben Franz <bfranz@chromium.org>
Reviewed-by: Roland Bock <rbock@google.com>
Reviewed-by: Jeroen Dhollander <jeroendh@google.com>
Cr-Commit-Position: refs/heads/main@{#1001470}
  • Loading branch information
Ben Franz authored and Chromium LUCI CQ committed May 10, 2022
1 parent d1099e7 commit c1d9294
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 77 deletions.
11 changes: 11 additions & 0 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5198,11 +5198,21 @@ static_library("browser") {
"chrome_browser_main_parts_lacros.h",
"chromeos/app_mode/app_session.cc",
"chromeos/app_mode/app_session.h",
"chromeos/app_mode/chrome_kiosk_app_installer.cc",
"chromeos/app_mode/chrome_kiosk_app_installer.h",
"chromeos/app_mode/chrome_kiosk_app_launcher.cc",
"chromeos/app_mode/chrome_kiosk_app_launcher.h",
"chromeos/app_mode/chrome_kiosk_external_loader_broker.cc",
"chromeos/app_mode/chrome_kiosk_external_loader_broker.h",
"chromeos/app_mode/kiosk_app_external_loader.cc",
"chromeos/app_mode/kiosk_app_external_loader.h",
"chromeos/app_mode/kiosk_session_plugin_handler.cc",
"chromeos/app_mode/kiosk_session_plugin_handler.h",
"chromeos/app_mode/kiosk_session_plugin_handler_delegate.h",
"chromeos/app_mode/kiosk_settings_navigation_throttle.cc",
"chromeos/app_mode/kiosk_settings_navigation_throttle.h",
"chromeos/app_mode/startup_app_launcher_update_checker.cc",
"chromeos/app_mode/startup_app_launcher_update_checker.h",
"chromeos/extensions/echo_private/echo_private_api.cc",
"chromeos/extensions/echo_private/echo_private_api.h",
"chromeos/extensions/info_private_api.cc",
Expand Down Expand Up @@ -5397,6 +5407,7 @@ static_library("browser") {
"//chromeos/lacros/dbus",
"//chromeos/ui/frame",
"//components/arc/common",
"//extensions/browser/updater",
"//ui/chromeos/styles:cros_styles_views",
"//ui/platform_window",
]
Expand Down
18 changes: 7 additions & 11 deletions chrome/browser/ash/app_mode/kiosk_app_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chromeos/crosapi/mojom/chrome_app_kiosk_service.mojom.h"
#include "components/account_id/account_id.h"
#include "components/ownership/owner_key_util.h"
#include "components/prefs/pref_registry_simple.h"
Expand Down Expand Up @@ -589,13 +590,12 @@ bool KioskAppManager::GetCachedCrx(const std::string& app_id,
return external_cache_->GetExtension(app_id, file_path, version);
}

ChromeKioskAppInstaller::AppInstallData
KioskAppManager::CreatePrimaryAppInstallData(const std::string& id) const {
crosapi::mojom::AppInstallParams KioskAppManager::CreatePrimaryAppInstallData(
const std::string& id) const {
const base::DictionaryValue* extension = nullptr;
if (!external_cache_->GetCachedExtensions()->GetDictionary(id, &extension)) {
ChromeKioskAppInstaller::AppInstallData data;
data.id = id;
return data;
return crosapi::mojom::AppInstallParams(id, std::string(), std::string(),
false);
}

const absl::optional<bool> is_store_app_maybe =
Expand All @@ -613,12 +613,8 @@ KioskAppManager::CreatePrimaryAppInstallData(const std::string& id) const {
extensions::ExternalProviderImpl::kExternalVersion);
DCHECK(external_version);

ChromeKioskAppInstaller::AppInstallData data;
data.id = id;
data.is_store_app = is_store_app_bool;
data.crx_file_location = *crx_file_location;
data.version = *external_version;
return data;
return crosapi::mojom::AppInstallParams(id, *crx_file_location,
*external_version, is_store_app_bool);
}

void KioskAppManager::UpdateExternalCache() {
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/ash/app_mode/kiosk_app_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "chrome/browser/chromeos/app_mode/chrome_kiosk_external_loader_broker.h"
#include "chrome/browser/chromeos/extensions/external_cache.h"
#include "chrome/browser/chromeos/extensions/external_cache_delegate.h"
#include "chromeos/crosapi/mojom/chrome_app_kiosk_service.mojom.h"
#include "components/account_id/account_id.h"
#include "extensions/common/extension_id.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
Expand Down Expand Up @@ -177,7 +178,7 @@ class KioskAppManager : public KioskAppManagerBase,
base::FilePath* file_path,
std::string* version) const;

ChromeKioskAppInstaller::AppInstallData CreatePrimaryAppInstallData(
crosapi::mojom::AppInstallParams CreatePrimaryAppInstallData(
const std::string& id) const;

void UpdateExternalCache();
Expand Down
15 changes: 12 additions & 3 deletions chrome/browser/ash/app_mode/startup_app_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "base/bind.h"
#include "base/command_line.h"
#include "base/notreached.h"
#include "base/syslog_logging.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
Expand Down Expand Up @@ -176,18 +177,22 @@ void StartupAppLauncher::OnInstallComplete(
case ChromeKioskAppInstaller::InstallResult::kSuccess:
OnInstallSuccess();
return;
case ChromeKioskAppInstaller::InstallResult::kUnableToInstallPrimaryApp:
case ChromeKioskAppInstaller::InstallResult::kPrimaryAppInstallFailed:
OnLaunchFailure(KioskAppLaunchError::Error::kUnableToInstall);
return;
case ChromeKioskAppInstaller::InstallResult::kNotKioskEnabled:
case ChromeKioskAppInstaller::InstallResult::kPrimaryAppNotKioskEnabled:
OnLaunchFailure(KioskAppLaunchError::Error::kNotKioskEnabled);
return;
case ChromeKioskAppInstaller::InstallResult::kPrimaryAppNotCached:
case ChromeKioskAppInstaller::InstallResult::kUnableToInstallSecondaryApp:
case ChromeKioskAppInstaller::InstallResult::kSecondaryAppInstallFailed:
if (!RetryWhenNetworkIsAvailable()) {
OnLaunchFailure(KioskAppLaunchError::Error::kUnableToInstall);
}
return;
case ChromeKioskAppInstaller::InstallResult::kUnknown:
SYSLOG(ERROR) << "Received unknown InstallResult";
OnLaunchFailure(KioskAppLaunchError::Error::kUnableToInstall);
return;
}
}

Expand Down Expand Up @@ -228,6 +233,10 @@ void StartupAppLauncher::OnLaunchComplete(
if (!RetryWhenNetworkIsAvailable())
OnLaunchFailure(KioskAppLaunchError::Error::kUnableToLaunch);
return;
case ChromeKioskAppLauncher::LaunchResult::kUnknown:
SYSLOG(ERROR) << "Received unknown LaunchResult";
OnLaunchFailure(KioskAppLaunchError::Error::kUnableToLaunch);
return;
}
}

Expand Down
30 changes: 9 additions & 21 deletions chrome/browser/chromeos/app_mode/chrome_kiosk_app_installer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chrome/browser/chromeos/app_mode/chrome_kiosk_app_installer.h"

#include "base/metrics/histogram_functions.h"
#include "base/syslog_logging.h"
#include "chrome/browser/chromeos/app_mode/chrome_kiosk_external_loader_broker.h"
#include "chrome/browser/chromeos/app_mode/startup_app_launcher_update_checker.h"
Expand All @@ -16,17 +17,9 @@

namespace ash {

ChromeKioskAppInstaller::AppInstallData::AppInstallData() = default;
ChromeKioskAppInstaller::AppInstallData::AppInstallData(
const AppInstallData& other) = default;
ChromeKioskAppInstaller::AppInstallData&
ChromeKioskAppInstaller::AppInstallData::operator=(
const AppInstallData& other) = default;
ChromeKioskAppInstaller::AppInstallData::~AppInstallData() = default;

ChromeKioskAppInstaller::ChromeKioskAppInstaller(
Profile* profile,
const AppInstallData& install_data)
const AppInstallParams& install_data)
: profile_(profile), primary_app_install_data_(install_data) {}

ChromeKioskAppInstaller::~ChromeKioskAppInstaller() {}
Expand Down Expand Up @@ -56,15 +49,13 @@ void ChromeKioskAppInstaller::BeginInstall(InstallCallback callback) {
const extensions::Extension* primary_app = GetPrimaryAppExtension();
if (!primary_app) {
// The extension is skipped for installation due to some error.
ReportInstallFailure(
ChromeKioskAppInstaller::InstallResult::kUnableToInstallPrimaryApp);
ReportInstallFailure(InstallResult::kPrimaryAppInstallFailed);
return;
}

if (!extensions::KioskModeInfo::IsKioskEnabled(primary_app)) {
// The installed primary app is not kiosk enabled.
ReportInstallFailure(
ChromeKioskAppInstaller::InstallResult::kNotKioskEnabled);
ReportInstallFailure(InstallResult::kPrimaryAppNotKioskEnabled);
return;
}

Expand Down Expand Up @@ -95,8 +86,7 @@ void ChromeKioskAppInstaller::MaybeInstallSecondaryApps() {
// Check extension update before launching the primary kiosk app.
MaybeCheckExtensionUpdate();
} else {
ReportInstallFailure(
ChromeKioskAppInstaller::InstallResult::kUnableToInstallSecondaryApp);
ReportInstallFailure(InstallResult::kSecondaryAppInstallFailed);
}
}

Expand Down Expand Up @@ -164,8 +154,8 @@ void ChromeKioskAppInstaller::OnFinishCrxInstall(
if (DidPrimaryOrSecondaryAppFailedToInstall(success, extension_id)) {
install_observation_.Reset();
ReportInstallFailure((extension_id == primary_app_install_data_.id)
? InstallResult::kUnableToInstallPrimaryApp
: InstallResult::kUnableToInstallSecondaryApp);
? InstallResult::kPrimaryAppInstallFailed
: InstallResult::kSecondaryAppInstallFailed);
return;
}

Expand All @@ -181,14 +171,12 @@ void ChromeKioskAppInstaller::OnFinishCrxInstall(

const extensions::Extension* primary_app = GetPrimaryAppExtension();
if (!primary_app) {
ReportInstallFailure(
ChromeKioskAppInstaller::InstallResult::kUnableToInstallPrimaryApp);
ReportInstallFailure(InstallResult::kPrimaryAppInstallFailed);
return;
}

if (!extensions::KioskModeInfo::IsKioskEnabled(primary_app)) {
ReportInstallFailure(
ChromeKioskAppInstaller::InstallResult::kNotKioskEnabled);
ReportInstallFailure(InstallResult::kPrimaryAppNotKioskEnabled);
return;
}

Expand Down
33 changes: 9 additions & 24 deletions chrome/browser/chromeos/app_mode/chrome_kiosk_app_installer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,21 @@
#include "chrome/browser/chromeos/app_mode/startup_app_launcher_update_checker.h"
#include "chrome/browser/extensions/install_observer.h"
#include "chrome/browser/extensions/install_tracker.h"
#include "chromeos/crosapi/mojom/chrome_app_kiosk_service.mojom.h"

class Profile;

namespace ash {

class ChromeKioskAppInstaller : private extensions::InstallObserver {
public:
enum class InstallResult {
kSuccess,
kPrimaryAppNotCached,
kUnableToInstallPrimaryApp,
kUnableToInstallSecondaryApp,
kNotKioskEnabled,
};

struct AppInstallData {
AppInstallData();
AppInstallData(const AppInstallData&);
AppInstallData& operator=(const AppInstallData&);
~AppInstallData();

std::string id;
std::string crx_file_location;
std::string version;
bool is_store_app = false;
};

using InstallCallback = base::OnceCallback<void(InstallResult result)>;

ChromeKioskAppInstaller(Profile* profile, const AppInstallData& install_data);
using InstallResult = crosapi::mojom::ChromeKioskInstallResult;
using AppInstallParams = crosapi::mojom::AppInstallParams;
using InstallCallback =
crosapi::mojom::ChromeKioskLaunchController::InstallKioskAppCallback;

ChromeKioskAppInstaller(Profile* profile,
const AppInstallParams& install_data);
ChromeKioskAppInstaller(const ChromeKioskAppInstaller&) = delete;
ChromeKioskAppInstaller& operator=(const ChromeKioskAppInstaller&) = delete;
~ChromeKioskAppInstaller() override;
Expand Down Expand Up @@ -82,7 +67,7 @@ class ChromeKioskAppInstaller : private extensions::InstallObserver {
const std::string& id) const;

Profile* const profile_;
const AppInstallData primary_app_install_data_;
AppInstallParams primary_app_install_data_;

InstallCallback on_ready_callback_;

Expand Down
11 changes: 4 additions & 7 deletions chrome/browser/chromeos/app_mode/chrome_kiosk_app_launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@

#include "base/callback.h"
#include "chrome/browser/profiles/profile.h"
#include "chromeos/crosapi/mojom/chrome_app_kiosk_service.mojom.h"
#include "extensions/common/extension.h"

namespace ash {

class ChromeKioskAppLauncher {
public:
enum class LaunchResult {
kSuccess,
kUnableToLaunch,
kNetworkMissing,
};

using LaunchCallback = base::OnceCallback<void(LaunchResult result)>;
using LaunchResult = crosapi::mojom::ChromeKioskLaunchResult;
using LaunchCallback =
crosapi::mojom::ChromeKioskLaunchController::LaunchKioskAppCallback;

ChromeKioskAppLauncher(Profile* profile,
const std::string& app_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void ChromeKioskExternalLoaderBroker::RegisterSecondaryAppInstallDataObserver(
}

void ChromeKioskExternalLoaderBroker::TriggerPrimaryAppInstall(
const ChromeKioskAppInstaller::AppInstallData& install_data) {
primary_app_install_data_ = install_data;
const crosapi::mojom::AppInstallParams& install_data) {
primary_app_install_data_.emplace(install_data);

if (primary_app_changed_handler_)
primary_app_changed_handler_.Run(CreatePrimaryAppLoaderPrefs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/callback.h"
#include "base/values.h"
#include "chrome/browser/chromeos/app_mode/chrome_kiosk_app_installer.h"
#include "chromeos/crosapi/mojom/chrome_app_kiosk_service.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace ash {
Expand Down Expand Up @@ -41,15 +42,14 @@ class ChromeKioskExternalLoaderBroker {
InstallDataChangeCallback callback);

void TriggerPrimaryAppInstall(
const ChromeKioskAppInstaller::AppInstallData& install_data);
const crosapi::mojom::AppInstallParams& install_data);
void TriggerSecondaryAppInstall(std::vector<std::string> secondary_app_ids);

private:
base::DictionaryValue CreatePrimaryAppLoaderPrefs() const;
base::DictionaryValue CreateSecondaryAppLoaderPrefs() const;

absl::optional<ChromeKioskAppInstaller::AppInstallData>
primary_app_install_data_;
absl::optional<crosapi::mojom::AppInstallParams> primary_app_install_data_;
absl::optional<std::vector<std::string>> secondary_app_ids_;

// Handle to the primary app external loader.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

#include "base/bind.h"
#include "base/notreached.h"
#include "chrome/browser/chromeos/app_mode/chrome_kiosk_app_installer.h"
#include "chrome/browser/chromeos/app_mode/chrome_kiosk_app_launcher.h"
#include "chromeos/crosapi/mojom/chrome_app_kiosk_service.mojom.h"
#include "chromeos/lacros/lacros_service.h"

ChromeKioskLaunchControllerLacros::ChromeKioskLaunchControllerLacros() {
ChromeKioskLaunchControllerLacros::ChromeKioskLaunchControllerLacros(
Profile& profile)
: profile_(profile) {
auto* service = chromeos::LacrosService::Get();
if (!service->IsAvailable<crosapi::mojom::ChromeAppKioskService>())
return;
Expand All @@ -25,12 +29,16 @@ ChromeKioskLaunchControllerLacros::~ChromeKioskLaunchControllerLacros() {}
void ChromeKioskLaunchControllerLacros::InstallKioskApp(
AppInstallParamsPtr params,
InstallKioskAppCallback callback) {
NOTIMPLEMENTED();
installer_ =
std::make_unique<ash::ChromeKioskAppInstaller>(&profile_, *params);
installer_->BeginInstall(std::move(callback));
}

void ChromeKioskLaunchControllerLacros::LaunchKioskApp(
const std::string& app_id,
bool is_network_ready,
LaunchKioskAppCallback callback) {
NOTIMPLEMENTED();
launcher_ = std::make_unique<ash::ChromeKioskAppLauncher>(&profile_, app_id,
is_network_ready);
launcher_->LaunchApp(std::move(callback));
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using LaunchKioskAppCallback =
class ChromeKioskLaunchControllerLacros
: public crosapi::mojom::ChromeKioskLaunchController {
public:
ChromeKioskLaunchControllerLacros();
explicit ChromeKioskLaunchControllerLacros(Profile& profile);
ChromeKioskLaunchControllerLacros(const ChromeKioskLaunchControllerLacros&) =
delete;
ChromeKioskLaunchControllerLacros& operator=(
Expand All @@ -37,6 +37,10 @@ class ChromeKioskLaunchControllerLacros
LaunchKioskAppCallback callback) override;

private:
Profile& profile_;
std::unique_ptr<ash::ChromeKioskAppInstaller> installer_;
std::unique_ptr<ash::ChromeKioskAppLauncher> launcher_;

mojo::Receiver<crosapi::mojom::ChromeKioskLaunchController>
controller_receiver_{this};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,6 @@ void ChromeBrowserMainExtraPartsLacros::PostProfileInit(
if (chromeos::LacrosService::Get()->init_params()->session_type ==
crosapi::mojom::SessionType::kAppKioskSession) {
chrome_kiosk_launch_controller_ =
std::make_unique<ChromeKioskLaunchControllerLacros>();
std::make_unique<ChromeKioskLaunchControllerLacros>(*profile);
}
}

0 comments on commit c1d9294

Please sign in to comment.