Chromium Code Reviews| Index: chrome/browser/ui/webui/settings/profile_info_handler.cc |
| diff --git a/chrome/browser/ui/webui/settings/profile_info_handler.cc b/chrome/browser/ui/webui/settings/profile_info_handler.cc |
| index b58c20fcbf525d8a9850d114406419a1734fbf67..c330b724b65a0578096e62f9a0d6d3ab41aa8ff6 100644 |
| --- a/chrome/browser/ui/webui/settings/profile_info_handler.cc |
| +++ b/chrome/browser/ui/webui/settings/profile_info_handler.cc |
| @@ -10,6 +10,7 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_attributes_entry.h" |
| #include "chrome/browser/ui/user_manager.h" |
| +#include "chrome/common/pref_names.h" |
| #include "ui/base/webui/web_ui_util.h" |
| #if defined(OS_CHROMEOS) |
| @@ -30,6 +31,9 @@ namespace settings { |
| // static |
| const char ProfileInfoHandler::kProfileInfoChangedEventName[] = |
| "profile-info-changed"; |
| +const char |
| + ProfileInfoHandler::kProfileManagesSupervisedUsersChangedEventName[] = |
| + "profile-manages-supervised-users-changed"; |
| ProfileInfoHandler::ProfileInfoHandler(Profile* profile) |
| : profile_(profile), |
| @@ -41,12 +45,23 @@ void ProfileInfoHandler::RegisterMessages() { |
| web_ui()->RegisterMessageCallback( |
| "getProfileInfo", base::Bind(&ProfileInfoHandler::HandleGetProfileInfo, |
| base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback( |
| + "getProfileManagesSupervisedUsers", |
| + base::Bind(&ProfileInfoHandler::HandleGetProfileManagesSupervisedUsers, |
| + base::Unretained(this))); |
| } |
| void ProfileInfoHandler::OnJavascriptAllowed() { |
| profile_observer_.Add( |
| &g_browser_process->profile_manager()->GetProfileAttributesStorage()); |
| + PrefService* prefs = profile_->GetPrefs(); |
| + profile_pref_registrar_.Init(prefs); |
| + profile_pref_registrar_.Add( |
| + prefs::kSupervisedUsers, |
| + base::Bind(&ProfileInfoHandler::PushProfileManagesSupervisedUsersStatus, |
| + base::Unretained(this))); |
| + |
| #if defined(OS_CHROMEOS) |
| registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
| content::NotificationService::AllSources()); |
| @@ -57,6 +72,8 @@ void ProfileInfoHandler::OnJavascriptDisallowed() { |
| profile_observer_.Remove( |
| &g_browser_process->profile_manager()->GetProfileAttributesStorage()); |
| + profile_pref_registrar_.RemoveAll(); |
| + |
| #if defined(OS_CHROMEOS) |
| registrar_.RemoveAll(); |
| #endif |
| @@ -97,12 +114,31 @@ void ProfileInfoHandler::HandleGetProfileInfo(const base::ListValue* args) { |
| ResolveJavascriptCallback(*callback_id, *GetAccountNameAndIcon()); |
| } |
| +void ProfileInfoHandler::HandleGetProfileManagesSupervisedUsers( |
| + const base::ListValue* args) { |
| + AllowJavascript(); |
| + |
| + CHECK_EQ(1U, args->GetSize()); |
| + const base::Value* callback_id; |
| + CHECK(args->Get(0, &callback_id)); |
| + |
| + ResolveJavascriptCallback( |
| + *callback_id, base::FundamentalValue(IsProfileManagingSupervisedUsers())); |
| +} |
| + |
| void ProfileInfoHandler::PushProfileInfo() { |
| CallJavascriptFunction("cr.webUIListenerCallback", |
| base::StringValue(kProfileInfoChangedEventName), |
| *GetAccountNameAndIcon()); |
| } |
| +void ProfileInfoHandler::PushProfileManagesSupervisedUsersStatus() { |
| + CallJavascriptFunction( |
| + "cr.webUIListenerCallback", |
| + base::StringValue(kProfileManagesSupervisedUsersChangedEventName), |
| + base::FundamentalValue(IsProfileManagingSupervisedUsers())); |
| +} |
| + |
| std::unique_ptr<base::DictionaryValue> |
| ProfileInfoHandler::GetAccountNameAndIcon() const { |
| std::string name; |
| @@ -148,4 +184,8 @@ ProfileInfoHandler::GetAccountNameAndIcon() const { |
| return base::WrapUnique(response); |
| } |
| +bool ProfileInfoHandler::IsProfileManagingSupervisedUsers() const { |
| + return !profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty(); |
|
tommycli
2016/06/10 22:15:32
This logic copied from https://cs.chromium.org/chr
hcarmona
2016/06/10 22:58:08
Acknowledged.
|
| +} |
| + |
| } // namespace settings |