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