Skip to content

Commit

Permalink
Reland "enterprise: Update device license mode when device policy dat…
Browse files Browse the repository at this point in the history
…a is

This is a reland of commit 160a7de

Reason of Revert was that EnterpriseDomainObserver was added more than once.

Now `ScopedObservation` is used instead of calling addObservation
directly and adding the observer is also moved to the ctor, which ensures
that it'll happen only once.

Revert CL: crrev.com/c/3655395

Original change's description:
> enterprise: Update device license mode when device policy data is set
>
> Previously, the device license mode is not updated correctly as login
> shelf view ctor is called before the policy is set.
>
> Inherit EnterpriseDomainObserver to update the device enterprise info when available.
>
> Bug: 1307303, 1327365
> Change-Id: Ie5cf63da93401ce5900f0d35f7396d0acf300271
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3650732
> Commit-Queue: Sherri Lin <sherrilin@google.com>
> Reviewed-by: Denis Kuznetsov <antrim@chromium.org>
> Reviewed-by: James Cook <jamescook@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1005422}

(cherry picked from commit ea95dfc)

Bug: 1307303, 1327365
Change-Id: I5b072cc76ddb4ca6dafea7407659c3556e8e2031
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3654231
Commit-Queue: Sherri Lin <sherrilin@google.com>
Reviewed-by: Denis Kuznetsov <antrim@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1005887}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3660145
Cr-Commit-Position: refs/branch-heads/5060@{#179}
Cr-Branched-From: b83393d-refs/heads/main@{#1002911}
  • Loading branch information
hsuanyulin authored and Chromium LUCI CQ committed May 23, 2022
1 parent eee2a01 commit 4c0fa58
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
27 changes: 17 additions & 10 deletions ash/shelf/login_shelf_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -656,16 +656,8 @@ LoginShelfView::LoginShelfView(
lock_screen_action_background);
login_data_dispatcher_observation_.Observe(
Shell::Get()->login_screen_controller()->data_dispatcher());

// If feature is enabled, update the boolean kiosk_license_mode_. Otherwise,
// it's false by default.
if (features::IsKioskEnrollmentInOobeEnabled()) {
kiosk_license_mode_ =
Shell::Get()
->system_tray_model()
->enterprise_domain()
->management_device_mode() == ManagementDeviceMode::kKioskSku;
}
enterprise_domain_model_observation_.Observe(
Shell::Get()->system_tray_model()->enterprise_domain());
}

LoginShelfView::~LoginShelfView() = default;
Expand Down Expand Up @@ -881,6 +873,21 @@ void LoginShelfView::OnOobeDialogStateChanged(OobeDialogState state) {
SetLoginDialogState(state);
}

void LoginShelfView::OnDeviceEnterpriseInfoChanged() {
// If feature is enabled, update the boolean kiosk_license_mode_. Otherwise,
// it's false by default.
if (features::IsKioskEnrollmentInOobeEnabled()) {
kiosk_license_mode_ =
Shell::Get()
->system_tray_model()
->enterprise_domain()
->management_device_mode() == ManagementDeviceMode::kKioskSku;
UpdateUi();
}
}

void LoginShelfView::OnEnterpriseAccountDomainChanged() {}

void LoginShelfView::HandleLocaleChange() {
for (views::View* child : children()) {
if (child->GetClassName() == kLoginShelfButtonClassName) {
Expand Down
12 changes: 11 additions & 1 deletion ash/shelf/login_shelf_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "ash/shelf/kiosk_app_instruction_bubble.h"
#include "ash/shelf/shelf_shutdown_confirmation_bubble.h"
#include "ash/shutdown_controller_impl.h"
#include "ash/system/enterprise/enterprise_domain_observer.h"
#include "ash/system/model/enterprise_domain_model.h"
#include "ash/tray_action/tray_action.h"
#include "ash/tray_action/tray_action_observer.h"
#include "base/memory/weak_ptr.h"
Expand Down Expand Up @@ -47,7 +49,8 @@ class ASH_EXPORT LoginShelfView : public views::View,
public TrayActionObserver,
public LockScreenActionBackgroundObserver,
public ShutdownControllerImpl::Observer,
public LoginDataDispatcher::Observer {
public LoginDataDispatcher::Observer,
public EnterpriseDomainObserver {
public:
enum ButtonId {
kShutdown = 1, // Shut down the device.
Expand Down Expand Up @@ -162,6 +165,10 @@ class ASH_EXPORT LoginShelfView : public views::View,
void OnUsersChanged(const std::vector<LoginUserInfo>& users) override;
void OnOobeDialogStateChanged(OobeDialogState state) override;

// ash::EnterpriseDomainObserver
void OnDeviceEnterpriseInfoChanged() override;
void OnEnterpriseAccountDomainChanged() override;

// Called when a locale change is detected. Updates the login shelf button
// strings.
void HandleLocaleChange();
Expand Down Expand Up @@ -247,6 +254,9 @@ class ASH_EXPORT LoginShelfView : public views::View,
base::ScopedObservation<LoginDataDispatcher, LoginDataDispatcher::Observer>
login_data_dispatcher_observation_{this};

base::ScopedObservation<EnterpriseDomainModel, EnterpriseDomainObserver>
enterprise_domain_model_observation_{this};

// The kiosk app button will only be created for the primary display's login
// shelf.
KioskAppsButton* kiosk_apps_button_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/ash/system_tray_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void OpenInBrowser(const GURL& event_url) {

ash::ManagementDeviceMode GetManagementDeviceMode(
policy::BrowserPolicyConnectorAsh* connector) {
if (connector->IsDeviceEnterpriseManaged())
if (!connector->IsDeviceEnterpriseManaged())
return ash::ManagementDeviceMode::kNone;

if (connector->IsKioskEnrolled())
Expand Down

0 comments on commit 4c0fa58

Please sign in to comment.