Commit 03a72b3f authored by merkulova's avatar merkulova Committed by Commit bot

ash: Add checks for supervised users.

Propagate the user's supervised state to the ash system
so that it becomes available for views

https://chromereviews.googleplex.com/79527013/

BUG=394417

Committed: https://crrev.com/8616ac4cf7bd77f53dc001eb9d8d61c6c975eaaa
Cr-Commit-Position: refs/heads/master@{#294821}

Review URL: https://codereview.chromium.org/561713002

Cr-Commit-Position: refs/heads/master@{#296160}
parent 357e910c
......@@ -714,6 +714,9 @@ bool ShelfWidget::IsShelfHiddenBehindBlackBar() const {
// static
bool ShelfWidget::ShelfAlignmentAllowed() {
if (Shell::GetInstance()->system_tray_delegate()->IsUserSupervised())
return false;
user::LoginStatus login_status =
Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus();
......
......@@ -29,7 +29,8 @@ const char TraySupervisedUser::kNotificationId[] =
TraySupervisedUser::TraySupervisedUser(SystemTray* system_tray)
: SystemTrayItem(system_tray),
tray_view_(NULL),
status_(ash::user::LOGGED_IN_NONE) {
status_(ash::user::LOGGED_IN_NONE),
is_user_supervised_(false) {
}
TraySupervisedUser::~TraySupervisedUser() {
......@@ -48,7 +49,8 @@ void TraySupervisedUser::UpdateMessage() {
views::View* TraySupervisedUser::CreateDefaultView(
user::LoginStatus status) {
CHECK(tray_view_ == NULL);
if (status != ash::user::LOGGED_IN_SUPERVISED)
SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
if (!delegate->IsUserSupervised())
return NULL;
tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_SUPERVISED_USER);
......@@ -66,14 +68,18 @@ void TraySupervisedUser::OnViewClicked(views::View* sender) {
void TraySupervisedUser::UpdateAfterLoginStatusChange(
user::LoginStatus status) {
if (status == status_)
SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
bool is_user_supervised = delegate->IsUserSupervised();
if (status == status_ && is_user_supervised == is_user_supervised_)
return;
if (status == ash::user::LOGGED_IN_SUPERVISED &&
if (is_user_supervised &&
status_ != ash::user::LOGGED_IN_LOCKED) {
SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
CreateOrUpdateNotification(delegate->GetSupervisedUserMessage());
}
status_ = status;
is_user_supervised_ = is_user_supervised;
}
void TraySupervisedUser::CreateOrUpdateNotification(
......
......@@ -15,7 +15,7 @@ class LabelTrayView;
class SystemTray;
class ASH_EXPORT TraySupervisedUser : public SystemTrayItem,
public ViewClickListener {
public ViewClickListener {
public:
explicit TraySupervisedUser(SystemTray* system_tray);
virtual ~TraySupervisedUser();
......@@ -43,6 +43,9 @@ class ASH_EXPORT TraySupervisedUser : public SystemTrayItem,
// Previous login status to avoid showing notification upon unlock.
user::LoginStatus status_;
// Previous user supervised state to avoid showing notification upon unlock.
bool is_user_supervised_;
DISALLOW_COPY_AND_ASSIGN(TraySupervisedUser);
};
......
......@@ -86,6 +86,10 @@ const base::string16 DefaultSystemTrayDelegate::GetSupervisedUserMessage()
return base::string16();
}
bool DefaultSystemTrayDelegate::IsUserSupervised() const {
return false;
}
bool DefaultSystemTrayDelegate::SystemShouldUpgrade() const {
return true;
}
......
......@@ -29,6 +29,7 @@ class ASH_EXPORT DefaultSystemTrayDelegate : public SystemTrayDelegate {
virtual const base::string16 GetSupervisedUserManagerName() const
OVERRIDE;
virtual const base::string16 GetSupervisedUserMessage() const OVERRIDE;
virtual bool IsUserSupervised() const OVERRIDE;
virtual bool SystemShouldUpgrade() const OVERRIDE;
virtual base::HourClockType GetHourClockType() const OVERRIDE;
virtual void ShowSettings() OVERRIDE;
......
......@@ -119,6 +119,9 @@ class ASH_EXPORT SystemTrayDelegate {
// Returns the notification for supervised users.
virtual const base::string16 GetSupervisedUserMessage() const = 0;
// Returns true if the current user is supervised.
virtual bool IsUserSupervised() const = 0;
// Returns whether a system upgrade is available.
virtual bool SystemShouldUpgrade() const = 0;
......
......@@ -137,6 +137,9 @@ void TrayUser::UpdateAfterLoginStatusChange(user::LoginStatus status) {
return;
bool need_label = false;
bool need_avatar = false;
SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
if (delegate->IsUserSupervised())
need_label = true;
switch (status) {
case user::LOGGED_IN_LOCKED:
case user::LOGGED_IN_USER:
......@@ -175,7 +178,7 @@ void TrayUser::UpdateAfterLoginStatusChange(user::LoginStatus status) {
}
}
if (status == user::LOGGED_IN_SUPERVISED) {
if (delegate->IsUserSupervised()) {
label_->SetText(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL));
} else if (status == user::LOGGED_IN_GUEST) {
......
......@@ -394,8 +394,10 @@ void UserCardView::AddUserContent(user::LoginStatus login_status,
views::Label* user_email = NULL;
if (login_status != user::LOGGED_IN_GUEST &&
(multiprofile_index || !IsMultiAccountSupportedAndUserActive())) {
SystemTrayDelegate* tray_delegate =
Shell::GetInstance()->system_tray_delegate();
base::string16 user_email_string =
login_status == user::LOGGED_IN_SUPERVISED
tray_delegate->IsUserSupervised()
? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)
: base::UTF8ToUTF16(
delegate->GetUserInfo(multiprofile_index)->GetEmail());
......
......@@ -8,6 +8,7 @@
#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/system/user/login_status.h"
#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
......@@ -69,6 +70,10 @@ user::LoginStatus TestSystemTrayDelegate::GetUserLoginStatus() const {
return login_status_;
}
bool TestSystemTrayDelegate::IsUserSupervised() const {
return login_status_ == ash::user::LOGGED_IN_SUPERVISED;
}
bool TestSystemTrayDelegate::ShouldShowDisplayNotification() {
return should_show_display_notification_;
}
......
......@@ -43,6 +43,7 @@ class TestSystemTrayDelegate : public DefaultSystemTrayDelegate {
// Overridden from SystemTrayDelegate:
virtual user::LoginStatus GetUserLoginStatus() const OVERRIDE;
virtual bool IsUserSupervised() const OVERRIDE;
virtual bool ShouldShowDisplayNotification() OVERRIDE;
virtual bool GetSessionStartTime(
base::TimeTicks* session_start_time) OVERRIDE;
......
......@@ -394,13 +394,18 @@ SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const {
const base::string16 SystemTrayDelegateChromeOS::GetSupervisedUserMessage()
const {
if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED)
if (!IsUserSupervised())
return base::string16();
return l10n_util::GetStringFUTF16(
IDS_USER_IS_SUPERVISED_BY_NOTICE,
base::UTF8ToUTF16(GetSupervisedUserManager()));
}
bool SystemTrayDelegateChromeOS::IsUserSupervised() const {
user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser();
return user && user->IsSupervised();
}
bool SystemTrayDelegateChromeOS::SystemShouldUpgrade() const {
return UpgradeDetector::GetInstance()->notify_upgrade();
}
......
......@@ -65,6 +65,7 @@ class SystemTrayDelegateChromeOS
virtual const std::string GetSupervisedUserManager() const OVERRIDE;
virtual const base::string16 GetSupervisedUserManagerName() const OVERRIDE;
virtual const base::string16 GetSupervisedUserMessage() const OVERRIDE;
virtual bool IsUserSupervised() const OVERRIDE;
virtual bool SystemShouldUpgrade() const OVERRIDE;
virtual base::HourClockType GetHourClockType() const OVERRIDE;
virtual void ShowSettings() OVERRIDE;
......
......@@ -83,6 +83,10 @@ class SystemTrayDelegateLinux : public ash::SystemTrayDelegate,
return base::string16();
}
virtual bool IsUserSupervised() const OVERRIDE {
return false;
}
virtual bool SystemShouldUpgrade() const OVERRIDE {
return UpgradeDetector::GetInstance()->notify_upgrade();
}
......
......@@ -83,6 +83,10 @@ class SystemTrayDelegateWin : public ash::SystemTrayDelegate,
return base::string16();
}
virtual bool IsUserSupervised() const OVERRIDE {
return false;
}
virtual bool SystemShouldUpgrade() const OVERRIDE {
return UpgradeDetector::GetInstance()->notify_upgrade();
}
......
......@@ -28,6 +28,14 @@ std::string GetUserName(const std::string& email) {
} // namespace
bool User::IsSupervised() const {
return false;
}
void User::SetIsSupervised(bool is_supervised) {
VLOG(1) << "Ignoring SetIsSupervised call with param " << is_supervised;
}
class RegularUser : public User {
public:
explicit RegularUser(const std::string& email);
......@@ -36,8 +44,17 @@ class RegularUser : public User {
// Overridden from User:
virtual UserType GetType() const OVERRIDE;
virtual bool CanSyncImage() const OVERRIDE;
virtual void SetIsSupervised(bool is_supervised) OVERRIDE {
VLOG(1) << "Setting user is supervised to " << is_supervised;
is_supervised_ = is_supervised;
}
virtual bool IsSupervised() const OVERRIDE {
return is_supervised_;
}
private:
bool is_supervised_;
DISALLOW_COPY_AND_ASSIGN(RegularUser);
};
......@@ -72,6 +89,7 @@ class SupervisedUser : public User {
// Overridden from User:
virtual UserType GetType() const OVERRIDE;
virtual bool IsSupervised() const OVERRIDE;
virtual std::string display_email() const OVERRIDE;
private:
......@@ -224,7 +242,8 @@ void User::SetStubImage(const UserImage& stub_user_image,
image_is_loading_ = is_loading;
}
RegularUser::RegularUser(const std::string& email) : User(email) {
RegularUser::RegularUser(const std::string& email)
: User(email), is_supervised_(false) {
set_can_lock(true);
set_display_email(email);
}
......@@ -278,6 +297,10 @@ std::string SupervisedUser::display_email() const {
return base::UTF16ToUTF8(display_name());
}
bool SupervisedUser::IsSupervised() const {
return true;
}
RetailModeUser::RetailModeUser() : User(chromeos::login::kRetailModeUserName) {
set_display_email(std::string());
}
......
......@@ -91,6 +91,10 @@ class USER_MANAGER_EXPORT User : public UserInfo {
virtual const gfx::ImageSkia& GetImage() const OVERRIDE;
virtual std::string GetUserID() const OVERRIDE;
// Is user supervised.
virtual bool IsSupervised() const;
virtual void SetIsSupervised(bool is_supervised);
// Returns the account name part of the email. Use the display form of the
// email if available and use_display_name == true. Otherwise use canonical.
std::string GetAccountName(bool use_display_email) const;
......
......@@ -289,6 +289,9 @@ class USER_MANAGER_EXPORT UserManager {
// Returns true if supervised users allowed.
virtual bool AreSupervisedUsersAllowed() const = 0;
// Force update login state.
virtual void ForceUpdateState() {}
protected:
// Sets UserManager instance.
static void SetInstance(UserManager* user_manager);
......
......@@ -634,6 +634,10 @@ void UserManagerBase::NotifyLocalStateChanged() {
UserManager::Observer, observer_list_, LocalStateChanged(this));
}
void UserManagerBase::ForceUpdateState() {
UpdateLoginState();
}
bool UserManagerBase::CanUserBeRemoved(const User* user) const {
// Only regular and supervised users are allowed to be manually removed.
if (!user || (user->GetType() != USER_TYPE_REGULAR &&
......
......@@ -102,6 +102,7 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager {
virtual void RemoveSessionStateObserver(
UserManager::UserSessionStateObserver* obs) OVERRIDE;
virtual void NotifyLocalStateChanged() OVERRIDE;
virtual void ForceUpdateState() OVERRIDE;
// Helper function that copies users from |users_list| to |users_vector| and
// |users_set|. Duplicates and users already present in |existing_users| are
......
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