Commit 3fce4e99 authored by treib's avatar treib Committed by Commit bot

Update the AvatarMenu (and the ProfileChooserView, which listens for changes...

Update the AvatarMenu (and the ProfileChooserView, which listens for changes to the AvatarMenu) when a supervised user's custodian info changes.

BUG=372381

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

Cr-Commit-Position: refs/heads/master@{#296954}
parent bb13612c
......@@ -53,6 +53,9 @@ AvatarMenu::AvatarMenu(ProfileInfoInterface* profile_cache,
Browser* browser)
: profile_list_(ProfileList::Create(profile_cache)),
menu_actions_(AvatarMenuActions::Create()),
#if defined(ENABLE_MANAGED_USERS)
supervised_user_observer_(this),
#endif
profile_info_(profile_cache),
observer_(observer),
browser_(browser) {
......@@ -64,6 +67,15 @@ AvatarMenu::AvatarMenu(ProfileInfoInterface* profile_cache,
// Register this as an observer of the info cache.
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
content::NotificationService::AllSources());
#if defined(ENABLE_MANAGED_USERS)
// Register this as an observer of the SupervisedUserService to be notified
// of changes to the custodian info.
if (browser_) {
supervised_user_observer_.Add(
SupervisedUserServiceFactory::GetForProfile(browser_->profile()));
}
#endif
}
AvatarMenu::~AvatarMenu() {
......@@ -234,3 +246,11 @@ void AvatarMenu::Observe(int type,
if (observer_)
observer_->OnAvatarMenuChanged(this);
}
#if defined(ENABLE_MANAGED_USERS)
void AvatarMenu::OnCustodianInfoChanged() {
RebuildMenu();
if (observer_)
observer_->OnAvatarMenuChanged(this);
}
#endif
......@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/ui/host_desktop.h"
......@@ -19,19 +20,28 @@
#include "content/public/browser/web_contents_observer.h"
#include "ui/gfx/image/image.h"
#if defined(ENABLE_MANAGED_USERS)
#include "chrome/browser/supervised_user/supervised_user_service_observer.h"
#endif
class AvatarMenuActions;
class AvatarMenuObserver;
class Browser;
class Profile;
class ProfileInfoInterface;
class ProfileList;
class AvatarMenuActions;
class SupervisedUserService;
// This class represents the menu-like interface used to select profiles,
// such as the bubble that appears when the avatar icon is clicked in the
// browser window frame. This class will notify its observer when the backend
// data changes, and the view for this model should forward actions
// back to it in response to user events.
class AvatarMenu : public content::NotificationObserver {
class AvatarMenu :
#if defined(ENABLE_MANAGED_USERS)
public SupervisedUserServiceObserver,
#endif
public content::NotificationObserver {
public:
// Represents an item in the menu.
struct Item {
......@@ -142,12 +152,23 @@ class AvatarMenu : public content::NotificationObserver {
const content::NotificationDetails& details) OVERRIDE;
private:
#if defined(ENABLE_MANAGED_USERS)
// SupervisedUserServiceObserver:
virtual void OnCustodianInfoChanged() OVERRIDE;
#endif
// The model that provides the list of menu items.
scoped_ptr<ProfileList> profile_list_;
// The controller for avatar menu actions.
scoped_ptr<AvatarMenuActions> menu_actions_;
#if defined(ENABLE_MANAGED_USERS)
// Observes changes to a supervised user's custodian info.
ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver>
supervised_user_observer_;
#endif
// The cache that provides the profile information. Weak.
ProfileInfoInterface* profile_info_;
......
......@@ -34,13 +34,8 @@ class ProfileListDesktopBrowserTest : public InProcessBrowserTest {
public:
ProfileListDesktopBrowserTest() {}
AvatarMenu* GetAvatarMenu(ProfileInfoCache* cache) {
// Reset the menu.
avatar_menu_.reset(new AvatarMenu(
cache,
NULL,
browser()));
return avatar_menu_.get();
scoped_ptr<AvatarMenu> CreateAvatarMenu(ProfileInfoCache* cache) {
return scoped_ptr<AvatarMenu>(new AvatarMenu(cache, NULL, browser()));
}
private:
......@@ -68,7 +63,7 @@ IN_PROC_BROWSER_TEST_F(ProfileListDesktopBrowserTest, MAYBE_SignOut) {
ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
size_t index = cache.GetIndexOfProfileWithPath(current_profile->GetPath());
AvatarMenu* menu = GetAvatarMenu(&cache);
scoped_ptr<AvatarMenu> menu = CreateAvatarMenu(&cache);
menu->RebuildMenu();
BrowserList* browser_list =
......@@ -125,7 +120,7 @@ IN_PROC_BROWSER_TEST_F(ProfileListDesktopBrowserTest, MAYBE_SwitchToProfile) {
content::RunMessageLoop();
ASSERT_EQ(cache.GetNumberOfProfiles(), 2U);
AvatarMenu* menu = GetAvatarMenu(&cache);
scoped_ptr<AvatarMenu> menu = CreateAvatarMenu(&cache);
menu->RebuildMenu();
BrowserList* browser_list =
BrowserList::GetInstance(chrome::GetActiveDesktop());
......
......@@ -195,6 +195,11 @@ bool SupervisedUserService::ProfileIsSupervised() const {
return profile_->IsSupervised();
}
void SupervisedUserService::OnCustodianInfoChanged() {
FOR_EACH_OBSERVER(
SupervisedUserServiceObserver, observer_list_, OnCustodianInfoChanged());
}
// static
void SupervisedUserService::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
......@@ -750,6 +755,31 @@ void SupervisedUserService::SetActive(bool active) {
pref_change_registrar_.Add(prefs::kSupervisedUserManualURLs,
base::Bind(&SupervisedUserService::UpdateManualURLs,
base::Unretained(this)));
pref_change_registrar_.Add(prefs::kSupervisedUserCustodianName,
base::Bind(&SupervisedUserService::OnCustodianInfoChanged,
base::Unretained(this)));
pref_change_registrar_.Add(prefs::kSupervisedUserCustodianEmail,
base::Bind(&SupervisedUserService::OnCustodianInfoChanged,
base::Unretained(this)));
pref_change_registrar_.Add(prefs::kSupervisedUserCustodianProfileImageURL,
base::Bind(&SupervisedUserService::OnCustodianInfoChanged,
base::Unretained(this)));
pref_change_registrar_.Add(prefs::kSupervisedUserCustodianProfileURL,
base::Bind(&SupervisedUserService::OnCustodianInfoChanged,
base::Unretained(this)));
pref_change_registrar_.Add(prefs::kSupervisedUserSecondCustodianName,
base::Bind(&SupervisedUserService::OnCustodianInfoChanged,
base::Unretained(this)));
pref_change_registrar_.Add(prefs::kSupervisedUserSecondCustodianEmail,
base::Bind(&SupervisedUserService::OnCustodianInfoChanged,
base::Unretained(this)));
pref_change_registrar_.Add(
prefs::kSupervisedUserSecondCustodianProfileImageURL,
base::Bind(&SupervisedUserService::OnCustodianInfoChanged,
base::Unretained(this)));
pref_change_registrar_.Add(prefs::kSupervisedUserSecondCustodianProfileURL,
base::Bind(&SupervisedUserService::OnCustodianInfoChanged,
base::Unretained(this)));
// Initialize the filter.
OnDefaultFilteringBehaviorChanged();
......
......@@ -262,6 +262,8 @@ class SupervisedUserService : public KeyedService,
bool ProfileIsSupervised() const;
void OnCustodianInfoChanged();
#if defined(ENABLE_EXTENSIONS)
// Internal implementation for ExtensionManagementPolicy::Delegate methods.
// If |error| is not NULL, it will be filled with an error message if the
......
......@@ -11,6 +11,10 @@ class SupervisedUserServiceObserver {
// content pack is added, or the default fallback behavior is changed.
virtual void OnURLFilterChanged() {}
// Called when information about the supervised user's custodian is changed,
// e.g. the display name.
virtual void OnCustodianInfoChanged() {}
protected:
virtual ~SupervisedUserServiceObserver() {}
};
......
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