Commit bb0aad3b authored by Nicholas Verne's avatar Nicholas Verne Committed by Commit Bot

Disable Crostini for children.

Also legacy supervised profiles.

Bug: 853198
Change-Id: I8a42363f3f28476f4882605517eac9b1b3512200
Reviewed-on: https://chromium-review.googlesource.com/1103984
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569194}
parent e0588bf3
......@@ -121,10 +121,13 @@ void SetCrostiniUIAllowedForTesting(bool enabled) {
g_crostini_ui_allowed_for_testing = enabled;
}
bool IsCrostiniAllowed() {
bool IsCrostiniAllowedForProfile(Profile* profile) {
if (g_crostini_ui_allowed_for_testing) {
return true;
}
if (profile && (profile->IsChild() || profile->IsLegacySupervised())) {
return false;
}
return virtual_machines::AreVirtualMachinesAllowedByVersionAndChannel() &&
virtual_machines::AreVirtualMachinesAllowedByPolicy() &&
base::FeatureList::IsEnabled(features::kCrostini);
......@@ -138,7 +141,7 @@ bool IsCrostiniUIAllowedForProfile(Profile* profile) {
return false;
}
return IsCrostiniAllowed() &&
return IsCrostiniAllowedForProfile(profile) &&
base::FeatureList::IsEnabled(features::kExperimentalCrostiniUI);
}
......
......@@ -19,12 +19,13 @@ class Profile;
// behaviour and returning true instead.
void SetCrostiniUIAllowedForTesting(bool enabled);
// Returns true if crostini is allowed to run.
// Returns true if crostini is allowed to run for |profile|.
// Otherwise, returns false, e.g. if crostini is not available on the device,
// or it is in the flow to set up managed account creation.
bool IsCrostiniAllowed();
bool IsCrostiniAllowedForProfile(Profile* profile);
// Returns true if crostini UI can be shown. Implies crostini is allowed to run.
// Returns true if crostini UI can be shown. Implies crostini is allowed to
// run.
bool IsCrostiniUIAllowedForProfile(Profile* profile);
// Returns whether if Crostini has been enabled, i.e. the user has launched it
......
......@@ -4,7 +4,10 @@
#include "chrome/browser/chromeos/dbus/finch_features_service_provider_delegate.h"
#include "chrome/browser/chromeos/virtual_machines/virtual_machines_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile_manager.h"
namespace chromeos {
......@@ -12,9 +15,17 @@ FinchFeaturesServiceProviderDelegate::FinchFeaturesServiceProviderDelegate() {}
FinchFeaturesServiceProviderDelegate::~FinchFeaturesServiceProviderDelegate() {}
bool FinchFeaturesServiceProviderDelegate::IsCrostiniEnabled() {
return virtual_machines::AreVirtualMachinesAllowedByVersionAndChannel() &&
virtual_machines::AreVirtualMachinesAllowedByPolicy();
bool FinchFeaturesServiceProviderDelegate::IsCrostiniEnabled(
const std::string& user_id_hash) {
Profile* profile = nullptr;
if (!user_id_hash.empty()) {
profile = g_browser_process->profile_manager()->GetProfileByPath(
ProfileHelper::GetProfilePathByUserIdHash(user_id_hash));
} else {
profile = ProfileManager::GetActiveUserProfile();
}
return IsCrostiniAllowedForProfile(profile);
}
} // namespace chromeos
......@@ -18,7 +18,7 @@ class FinchFeaturesServiceProviderDelegate
~FinchFeaturesServiceProviderDelegate() override;
// ChromeServiceProvider::Delegate:
bool IsCrostiniEnabled() override;
bool IsCrostiniEnabled(const std::string& user_id_hash) override;
private:
DISALLOW_COPY_AND_ASSIGN(FinchFeaturesServiceProviderDelegate);
......
......@@ -42,10 +42,16 @@ void ChromeFeaturesServiceProvider::OnExported(
void ChromeFeaturesServiceProvider::IsCrostiniEnabled(
dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender) {
dbus::MessageReader reader(method_call);
std::string user_id_hash;
// TODO(nverne): Make it an error to fail to PopString once callers have been
// updated.
reader.PopString(&user_id_hash);
std::unique_ptr<dbus::Response> response =
dbus::Response::FromMethodCall(method_call);
dbus::MessageWriter writer(response.get());
writer.AppendBool(delegate_->IsCrostiniEnabled());
writer.AppendBool(delegate_->IsCrostiniEnabled(user_id_hash));
response_sender.Run(std::move(response));
}
......
......@@ -40,7 +40,7 @@ class CHROMEOS_EXPORT ChromeFeaturesServiceProvider
Delegate() {}
virtual ~Delegate() {}
virtual bool IsCrostiniEnabled() = 0;
virtual bool IsCrostiniEnabled(const std::string& user_id_hash) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(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