Commit 270ffc01 authored by merkulova's avatar merkulova Committed by Commit bot

Adding infrastructure for possibility of changing manager names for the supervised accounts.

CL https://chromereviews.googleplex.com/90457013/ for pre-checks.

BUG=419007

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

Cr-Commit-Position: refs/heads/master@{#299296}
parent a456ad3f
......@@ -343,6 +343,7 @@
'system/chromeos/session/tray_session_length_limit.h',
'system/chromeos/settings/tray_settings.cc',
'system/chromeos/settings/tray_settings.h',
'system/chromeos/supervised/custodian_info_tray_observer.h',
'system/chromeos/supervised/tray_supervised_user.cc',
'system/chromeos/supervised/tray_supervised_user.h',
'system/chromeos/system_clock_observer.cc',
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_CHROMEOS_SUPERVISED_CUSTODIAN_INFO_TRAY_OBSERVER_H_
#define ASH_SYSTEM_CHROMEOS_SUPERVISED_CUSTODIAN_INFO_TRAY_OBSERVER_H_
namespace ash {
// Used to observe SystemTrayDelegate.
class CustodianInfoTrayObserver {
public:
// Called when information about the supervised user's custodian is changed,
// e.g. the display name.
virtual void OnCustodianInfoChanged() = 0;
protected:
virtual ~CustodianInfoTrayObserver() {}
};
} // namespace ash
#endif // ASH_SYSTEM_CHROMEOS_SUPERVISED_CUSTODIAN_INFO_TRAY_OBSERVER_H_
......@@ -31,9 +31,16 @@ TraySupervisedUser::TraySupervisedUser(SystemTray* system_tray)
tray_view_(NULL),
status_(ash::user::LOGGED_IN_NONE),
is_user_supervised_(false) {
Shell::GetInstance()->system_tray_delegate()->
AddCustodianInfoTrayObserver(this);
}
TraySupervisedUser::~TraySupervisedUser() {
// We need the check as on shell destruction delegate is destroyed first.
SystemTrayDelegate* system_tray_delegate =
Shell::GetInstance()->system_tray_delegate();
if (system_tray_delegate)
system_tray_delegate->RemoveCustodianInfoTrayObserver(this);
}
void TraySupervisedUser::UpdateMessage() {
......@@ -75,9 +82,10 @@ void TraySupervisedUser::UpdateAfterLoginStatusChange(
return;
if (is_user_supervised &&
status_ != ash::user::LOGGED_IN_LOCKED) {
CreateOrUpdateNotification(delegate->GetSupervisedUserMessage());
}
status_ != ash::user::LOGGED_IN_LOCKED &&
!delegate->GetSupervisedUserManager().empty())
CreateOrUpdateSupervisedWarningNotification();
status_ = status;
is_user_supervised_ = is_user_supervised;
}
......@@ -96,4 +104,20 @@ void TraySupervisedUser::CreateOrUpdateNotification(
message_center::MessageCenter::Get()->AddNotification(notification.Pass());
}
void TraySupervisedUser::CreateOrUpdateSupervisedWarningNotification() {
SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
CreateOrUpdateNotification(delegate->GetSupervisedUserMessage());
}
void TraySupervisedUser::OnCustodianInfoChanged() {
SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
std::string manager_name = delegate->GetSupervisedUserManager();
if (!manager_name.empty()) {
if (!message_center::MessageCenter::Get()->FindVisibleNotificationById(
kNotificationId))
CreateOrUpdateSupervisedWarningNotification();
UpdateMessage();
}
}
} // namespace ash
......@@ -6,6 +6,7 @@
#define ASH_SYSTEM_CHROMEOS_SUPERVISED_TRAY_SUPERVISED_USER_H
#include "ash/ash_export.h"
#include "ash/system/chromeos/supervised/custodian_info_tray_observer.h"
#include "ash/system/tray/system_tray_item.h"
#include "ash/system/tray/view_click_listener.h"
#include "base/strings/string16.h"
......@@ -15,7 +16,8 @@ class LabelTrayView;
class SystemTray;
class ASH_EXPORT TraySupervisedUser : public SystemTrayItem,
public ViewClickListener {
public ViewClickListener,
public CustodianInfoTrayObserver {
public:
explicit TraySupervisedUser(SystemTray* system_tray);
virtual ~TraySupervisedUser();
......@@ -32,6 +34,9 @@ class ASH_EXPORT TraySupervisedUser : public SystemTrayItem,
// Overridden from ViewClickListener.
virtual void OnViewClicked(views::View* sender) override;
// Overridden from CustodianInfoTrayObserver:
virtual void OnCustodianInfoChanged() override;
private:
friend class TraySupervisedUserTest;
......@@ -39,7 +44,10 @@ class ASH_EXPORT TraySupervisedUser : public SystemTrayItem,
void CreateOrUpdateNotification(const base::string16& new_message);
void CreateOrUpdateSupervisedWarningNotification();
LabelTrayView* tray_view_;
// Previous login status to avoid showing notification upon unlock.
user::LoginStatus status_;
......
......@@ -72,7 +72,9 @@ const base::string16 DefaultSystemTrayDelegate::GetEnterpriseMessage() const {
const std::string
DefaultSystemTrayDelegate::GetSupervisedUserManager() const {
return std::string();
if (!IsUserSupervised())
return std::string();
return "manager@chrome.com";
}
const base::string16
......@@ -87,7 +89,7 @@ const base::string16 DefaultSystemTrayDelegate::GetSupervisedUserMessage()
}
bool DefaultSystemTrayDelegate::IsUserSupervised() const {
return false;
return GetUserLoginStatus() == ash::user::LOGGED_IN_SUPERVISED;
}
void DefaultSystemTrayDelegate::GetSystemUpdateInfo(UpdateInfo* info) const {
......@@ -291,4 +293,12 @@ tray::UserAccountsDelegate* DefaultSystemTrayDelegate::GetUserAccountsDelegate(
return NULL;
}
void DefaultSystemTrayDelegate::AddCustodianInfoTrayObserver(
CustodianInfoTrayObserver* observer) {
}
void DefaultSystemTrayDelegate::RemoveCustodianInfoTrayObserver(
CustodianInfoTrayObserver* observer) {
}
} // namespace ash
......@@ -88,6 +88,10 @@ class ASH_EXPORT DefaultSystemTrayDelegate : public SystemTrayDelegate {
virtual bool IsSearchKeyMappedToCapsLock() override;
virtual tray::UserAccountsDelegate* GetUserAccountsDelegate(
const std::string& user_id) override;
virtual void AddCustodianInfoTrayObserver(
CustodianInfoTrayObserver* observer) override;
virtual void RemoveCustodianInfoTrayObserver(
CustodianInfoTrayObserver* observer) override;
private:
bool bluetooth_enabled_;
......
......@@ -10,6 +10,7 @@
#include "ash/ash_export.h"
#include "ash/system/user/login_status.h"
#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/i18n/time_formatting.h"
#include "base/memory/scoped_ptr.h"
......@@ -23,6 +24,8 @@ class TimeTicks;
namespace ash {
class CustodianInfoTrayObserver;
struct ASH_EXPORT NetworkIconInfo {
NetworkIconInfo();
~NetworkIconInfo();
......@@ -311,6 +314,13 @@ class ASH_EXPORT SystemTrayDelegate {
// Returns accounts delegate for given user.
virtual tray::UserAccountsDelegate* GetUserAccountsDelegate(
const std::string& user_id) = 0;
// Adding observers that are notified when supervised info is being changed.
virtual void AddCustodianInfoTrayObserver(
CustodianInfoTrayObserver* observer) = 0;
virtual void RemoveCustodianInfoTrayObserver(
CustodianInfoTrayObserver* observer) = 0;
};
} // namespace ash
......
......@@ -281,28 +281,31 @@ void SupervisedUserService::GetCategoryNames(CategoryList* list) {
}
std::string SupervisedUserService::GetCustodianEmailAddress() const {
std::string custodian_email = profile_->GetPrefs()->GetString(
prefs::kSupervisedUserCustodianEmail);
#if defined(OS_CHROMEOS)
return chromeos::ChromeUserManager::Get()
->GetSupervisedUserManager()
->GetManagerDisplayEmail(
user_manager::UserManager::Get()->GetActiveUser()->email());
#else
return profile_->GetPrefs()->GetString(prefs::kSupervisedUserCustodianEmail);
if (custodian_email.empty()) {
custodian_email = chromeos::ChromeUserManager::Get()
->GetSupervisedUserManager()
->GetManagerDisplayEmail(
user_manager::UserManager::Get()->GetActiveUser()->email());
}
#endif
return custodian_email;
}
std::string SupervisedUserService::GetCustodianName() const {
#if defined(OS_CHROMEOS)
return base::UTF16ToUTF8(
chromeos::ChromeUserManager::Get()
->GetSupervisedUserManager()
->GetManagerDisplayName(
user_manager::UserManager::Get()->GetActiveUser()->email()));
#else
std::string name = profile_->GetPrefs()->GetString(
prefs::kSupervisedUserCustodianName);
return name.empty() ? GetCustodianEmailAddress() : name;
#if defined(OS_CHROMEOS)
if (name.empty()) {
name = base::UTF16ToUTF8(chromeos::ChromeUserManager::Get()
->GetSupervisedUserManager()
->GetManagerDisplayName(
user_manager::UserManager::Get()->GetActiveUser()->email()));
}
#endif
return name.empty() ? GetCustodianEmailAddress() : name;
}
void SupervisedUserService::AddNavigationBlockedCallback(
......
......@@ -70,6 +70,8 @@
#include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/system_tray_delegate_utils.h"
#include "chrome/browser/ui/ash/user_accounts_delegate_chromeos.h"
......@@ -312,6 +314,7 @@ SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() {
BrowserList::RemoveObserver(this);
StopObservingAppWindowRegistry();
StopObservingCustodianInfoChanges();
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
......@@ -380,31 +383,30 @@ const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const {
}
const std::string SystemTrayDelegateChromeOS::GetSupervisedUserManager() const {
if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED)
if (!IsUserSupervised())
return std::string();
return ChromeUserManager::Get()
->GetSupervisedUserManager()
->GetManagerDisplayEmail(
user_manager::UserManager::Get()->GetActiveUser()->email());
return SupervisedUserServiceFactory::GetForProfile(user_profile_)->
GetCustodianEmailAddress();
}
const base::string16
SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const {
if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED)
if (!IsUserSupervised())
return base::string16();
return ChromeUserManager::Get()
->GetSupervisedUserManager()
->GetManagerDisplayName(
user_manager::UserManager::Get()->GetActiveUser()->email());
return base::UTF8ToUTF16(SupervisedUserServiceFactory::GetForProfile(
user_profile_)->GetCustodianName());
}
const base::string16 SystemTrayDelegateChromeOS::GetSupervisedUserMessage()
const {
if (!IsUserSupervised())
return base::string16();
std::string user_manager_name = GetSupervisedUserManager();
LOG_IF(WARNING, user_manager_name.empty()) <<
"Returning incomplete supervised user message as manager not known yet.";
return l10n_util::GetStringFUTF16(
IDS_USER_IS_SUPERVISED_BY_NOTICE,
base::UTF8ToUTF16(GetSupervisedUserManager()));
base::UTF8ToUTF16(user_manager_name));
}
bool SystemTrayDelegateChromeOS::IsUserSupervised() const {
......@@ -864,6 +866,16 @@ SystemTrayDelegateChromeOS::GetUserAccountsDelegate(
return accounts_delegates_.get(user_id);
}
void SystemTrayDelegateChromeOS::AddCustodianInfoTrayObserver(
ash::CustodianInfoTrayObserver* observer) {
custodian_info_changed_observers_.AddObserver(observer);
}
void SystemTrayDelegateChromeOS::RemoveCustodianInfoTrayObserver(
ash::CustodianInfoTrayObserver* observer) {
custodian_info_changed_observers_.RemoveObserver(observer);
}
void SystemTrayDelegateChromeOS::UserAddedToSession(
const user_manager::User* active_user) {
}
......@@ -891,11 +903,17 @@ void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) {
// Stop observing the AppWindowRegistry of the current |user_profile_|.
StopObservingAppWindowRegistry();
// Stop observing custodian info changes of the current |user_profile_|.
StopObservingCustodianInfoChanges();
user_profile_ = profile;
// Start observing the AppWindowRegistry of the newly set |user_profile_|.
extensions::AppWindowRegistry::Get(user_profile_)->AddObserver(this);
// Start observing custodian info changes of the newly set |user_profile_|.
SupervisedUserServiceFactory::GetForProfile(profile)->AddObserver(this);
PrefService* prefs = profile->GetPrefs();
user_pref_registrar_.reset(new PrefChangeRegistrar);
user_pref_registrar_->Init(prefs);
......@@ -939,6 +957,7 @@ void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) {
UpdateShowLogoutButtonInTray();
UpdateLogoutDialogDuration();
UpdatePerformanceTracing();
OnCustodianInfoChanged();
search_key_mapped_to_ =
profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo);
}
......@@ -1043,6 +1062,16 @@ void SystemTrayDelegateChromeOS::StopObservingAppWindowRegistry() {
registry->RemoveObserver(this);
}
void SystemTrayDelegateChromeOS::StopObservingCustodianInfoChanges() {
if (!user_profile_)
return;
SupervisedUserService* service = SupervisedUserServiceFactory::GetForProfile(
user_profile_);
if (service)
service->RemoveObserver(this);
}
void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() {
if (!user_profile_)
return;
......@@ -1292,6 +1321,13 @@ void SystemTrayDelegateChromeOS::OnAppWindowRemoved(
NotifyIfLastWindowClosed();
}
// Overridden from SupervisedUserServiceObserver.
void SystemTrayDelegateChromeOS::OnCustodianInfoChanged() {
FOR_EACH_OBSERVER(
ash::CustodianInfoTrayObserver, custodian_info_changed_observers_,
OnCustodianInfoChanged());
}
void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged(
const AccessibilityStatusEventDetails& details) {
if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN)
......
......@@ -5,20 +5,25 @@
#ifndef CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_CHROMEOS_H_
#define CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_CHROMEOS_H_
#include <vector>
#include "ash/ime/input_method_menu_manager.h"
#include "ash/session/session_state_observer.h"
#include "ash/system/chromeos/supervised/custodian_info_tray_observer.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "base/callback_forward.h"
#include "base/callback_list.h"
#include "base/compiler_specific.h"
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/prefs/pref_change_registrar.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
#include "chrome/browser/supervised_user/supervised_user_service_observer.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/session_manager_client.h"
......@@ -51,7 +56,8 @@ class SystemTrayDelegateChromeOS
public ash::SessionStateObserver,
public chrome::BrowserListObserver,
public extensions::AppWindowRegistry::Observer,
public user_manager::UserManager::UserSessionStateObserver {
public user_manager::UserManager::UserSessionStateObserver,
public SupervisedUserServiceObserver {
public:
SystemTrayDelegateChromeOS();
......@@ -132,6 +138,10 @@ class SystemTrayDelegateChromeOS
virtual bool IsSearchKeyMappedToCapsLock() override;
virtual ash::tray::UserAccountsDelegate* GetUserAccountsDelegate(
const std::string& user_id) override;
virtual void AddCustodianInfoTrayObserver(
ash::CustodianInfoTrayObserver* observer) override;
virtual void RemoveCustodianInfoTrayObserver(
ash::CustodianInfoTrayObserver* observer) override;
// Overridden from user_manager::UserManager::UserSessionStateObserver:
virtual void UserAddedToSession(const user_manager::User* active_user)
......@@ -170,6 +180,8 @@ class SystemTrayDelegateChromeOS
void StopObservingAppWindowRegistry();
void StopObservingCustodianInfoChanges();
// Notify observers if the current user has no more open browser or app
// windows.
void NotifyIfLastWindowClosed();
......@@ -244,6 +256,9 @@ class SystemTrayDelegateChromeOS
// Overridden from extensions::AppWindowRegistry::Observer:
virtual void OnAppWindowRemoved(extensions::AppWindow* app_window) override;
// Overridden from SupervisedUserServiceObserver:
virtual void OnCustodianInfoChanged() override;
void OnAccessibilityStatusChanged(
const AccessibilityStatusEventDetails& details);
......@@ -270,6 +285,9 @@ class SystemTrayDelegateChromeOS
base::ScopedPtrHashMap<std::string, ash::tray::UserAccountsDelegate>
accounts_delegates_;
ObserverList<ash::CustodianInfoTrayObserver>
custodian_info_changed_observers_;
base::WeakPtrFactory<SystemTrayDelegateChromeOS> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateChromeOS);
......
......@@ -287,6 +287,14 @@ class SystemTrayDelegateLinux : public ash::SystemTrayDelegate,
return NULL;
}
virtual void AddCustodianInfoTrayObserver(
ash::CustodianInfoTrayObserver* observer) override {
}
virtual void RemoveCustodianInfoTrayObserver(
ash::CustodianInfoTrayObserver* observer) override {
}
private:
ash::SystemTrayNotifier* GetSystemTrayNotifier() {
return ash::Shell::GetInstance()->system_tray_notifier();
......
......@@ -284,6 +284,14 @@ class SystemTrayDelegateWin : public ash::SystemTrayDelegate,
return NULL;
}
virtual void AddCustodianInfoTrayObserver(
ash::CustodianInfoTrayObserver* observer) override {
}
virtual void RemoveCustodianInfoTrayObserver(
ash::CustodianInfoTrayObserver* observer) override {
}
private:
ash::SystemTrayNotifier* GetSystemTrayNotifier() {
return ash::Shell::GetInstance()->system_tray_notifier();
......
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