Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/ui/webui/settings/profile_info_handler.cc

Issue 2062503002: Settings People Revamp: Add 'Manage Supervised Users' row (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/settings/profile_info_handler.h" 5 #include "chrome/browser/ui/webui/settings/profile_info_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_attributes_entry.h" 11 #include "chrome/browser/profiles/profile_attributes_entry.h"
12 #include "chrome/browser/ui/user_manager.h" 12 #include "chrome/browser/ui/user_manager.h"
13 #include "chrome/common/pref_names.h"
13 #include "ui/base/webui/web_ui_util.h" 14 #include "ui/base/webui/web_ui_util.h"
14 15
15 #if defined(OS_CHROMEOS) 16 #if defined(OS_CHROMEOS)
16 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/chromeos/profiles/profile_helper.h" 18 #include "chrome/browser/chromeos/profiles/profile_helper.h"
18 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" 19 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h"
19 #include "components/signin/core/account_id/account_id.h" 20 #include "components/signin/core/account_id/account_id.h"
20 #include "components/user_manager/user_manager.h" 21 #include "components/user_manager/user_manager.h"
21 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
22 #else 23 #else
23 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
24 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 25 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 26 #include "third_party/skia/include/core/SkBitmap.h"
26 #endif 27 #endif
27 28
28 namespace settings { 29 namespace settings {
29 30
30 // static 31 // static
31 const char ProfileInfoHandler::kProfileInfoChangedEventName[] = 32 const char ProfileInfoHandler::kProfileInfoChangedEventName[] =
32 "profile-info-changed"; 33 "profile-info-changed";
34 const char
35 ProfileInfoHandler::kProfileManagesSupervisedUsersChangedEventName[] =
36 "profile-manages-supervised-users-changed";
33 37
34 ProfileInfoHandler::ProfileInfoHandler(Profile* profile) 38 ProfileInfoHandler::ProfileInfoHandler(Profile* profile)
35 : profile_(profile), 39 : profile_(profile),
36 profile_observer_(this) {} 40 profile_observer_(this) {}
37 41
38 ProfileInfoHandler::~ProfileInfoHandler() {} 42 ProfileInfoHandler::~ProfileInfoHandler() {}
39 43
40 void ProfileInfoHandler::RegisterMessages() { 44 void ProfileInfoHandler::RegisterMessages() {
41 web_ui()->RegisterMessageCallback( 45 web_ui()->RegisterMessageCallback(
42 "getProfileInfo", base::Bind(&ProfileInfoHandler::HandleGetProfileInfo, 46 "getProfileInfo", base::Bind(&ProfileInfoHandler::HandleGetProfileInfo,
43 base::Unretained(this))); 47 base::Unretained(this)));
48 web_ui()->RegisterMessageCallback(
49 "getProfileManagesSupervisedUsers",
50 base::Bind(&ProfileInfoHandler::HandleGetProfileManagesSupervisedUsers,
51 base::Unretained(this)));
44 } 52 }
45 53
46 void ProfileInfoHandler::OnJavascriptAllowed() { 54 void ProfileInfoHandler::OnJavascriptAllowed() {
47 profile_observer_.Add( 55 profile_observer_.Add(
48 &g_browser_process->profile_manager()->GetProfileAttributesStorage()); 56 &g_browser_process->profile_manager()->GetProfileAttributesStorage());
49 57
58 PrefService* prefs = profile_->GetPrefs();
59 profile_pref_registrar_.Init(prefs);
60 profile_pref_registrar_.Add(
61 prefs::kSupervisedUsers,
62 base::Bind(&ProfileInfoHandler::PushProfileManagesSupervisedUsersStatus,
63 base::Unretained(this)));
64
50 #if defined(OS_CHROMEOS) 65 #if defined(OS_CHROMEOS)
51 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 66 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
52 content::NotificationService::AllSources()); 67 content::NotificationService::AllSources());
53 #endif 68 #endif
54 } 69 }
55 70
56 void ProfileInfoHandler::OnJavascriptDisallowed() { 71 void ProfileInfoHandler::OnJavascriptDisallowed() {
57 profile_observer_.Remove( 72 profile_observer_.Remove(
58 &g_browser_process->profile_manager()->GetProfileAttributesStorage()); 73 &g_browser_process->profile_manager()->GetProfileAttributesStorage());
59 74
75 profile_pref_registrar_.RemoveAll();
76
60 #if defined(OS_CHROMEOS) 77 #if defined(OS_CHROMEOS)
61 registrar_.RemoveAll(); 78 registrar_.RemoveAll();
62 #endif 79 #endif
63 } 80 }
64 81
65 #if defined(OS_CHROMEOS) 82 #if defined(OS_CHROMEOS)
66 void ProfileInfoHandler::Observe(int type, 83 void ProfileInfoHandler::Observe(int type,
67 const content::NotificationSource& source, 84 const content::NotificationSource& source,
68 const content::NotificationDetails& details) { 85 const content::NotificationDetails& details) {
69 switch (type) { 86 switch (type) {
(...skipping 20 matching lines...) Expand all
90 void ProfileInfoHandler::HandleGetProfileInfo(const base::ListValue* args) { 107 void ProfileInfoHandler::HandleGetProfileInfo(const base::ListValue* args) {
91 AllowJavascript(); 108 AllowJavascript();
92 109
93 CHECK_EQ(1U, args->GetSize()); 110 CHECK_EQ(1U, args->GetSize());
94 const base::Value* callback_id; 111 const base::Value* callback_id;
95 CHECK(args->Get(0, &callback_id)); 112 CHECK(args->Get(0, &callback_id));
96 113
97 ResolveJavascriptCallback(*callback_id, *GetAccountNameAndIcon()); 114 ResolveJavascriptCallback(*callback_id, *GetAccountNameAndIcon());
98 } 115 }
99 116
117 void ProfileInfoHandler::HandleGetProfileManagesSupervisedUsers(
118 const base::ListValue* args) {
119 AllowJavascript();
120
121 CHECK_EQ(1U, args->GetSize());
122 const base::Value* callback_id;
123 CHECK(args->Get(0, &callback_id));
124
125 ResolveJavascriptCallback(
126 *callback_id, base::FundamentalValue(IsProfileManagingSupervisedUsers()));
127 }
128
100 void ProfileInfoHandler::PushProfileInfo() { 129 void ProfileInfoHandler::PushProfileInfo() {
101 CallJavascriptFunction("cr.webUIListenerCallback", 130 CallJavascriptFunction("cr.webUIListenerCallback",
102 base::StringValue(kProfileInfoChangedEventName), 131 base::StringValue(kProfileInfoChangedEventName),
103 *GetAccountNameAndIcon()); 132 *GetAccountNameAndIcon());
104 } 133 }
105 134
135 void ProfileInfoHandler::PushProfileManagesSupervisedUsersStatus() {
136 CallJavascriptFunction(
137 "cr.webUIListenerCallback",
138 base::StringValue(kProfileManagesSupervisedUsersChangedEventName),
139 base::FundamentalValue(IsProfileManagingSupervisedUsers()));
140 }
141
106 std::unique_ptr<base::DictionaryValue> 142 std::unique_ptr<base::DictionaryValue>
107 ProfileInfoHandler::GetAccountNameAndIcon() const { 143 ProfileInfoHandler::GetAccountNameAndIcon() const {
108 std::string name; 144 std::string name;
109 std::string icon_url; 145 std::string icon_url;
110 146
111 #if defined(OS_CHROMEOS) 147 #if defined(OS_CHROMEOS)
112 name = profile_->GetProfileUserName(); 148 name = profile_->GetProfileUserName();
113 if (name.empty()) { 149 if (name.empty()) {
114 const user_manager::User* user = 150 const user_manager::User* user =
115 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); 151 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
(...skipping 25 matching lines...) Expand all
141 } 177 }
142 } 178 }
143 #endif // defined(OS_CHROMEOS) 179 #endif // defined(OS_CHROMEOS)
144 180
145 base::DictionaryValue* response = new base::DictionaryValue(); 181 base::DictionaryValue* response = new base::DictionaryValue();
146 response->SetString("name", name); 182 response->SetString("name", name);
147 response->SetString("iconUrl", icon_url); 183 response->SetString("iconUrl", icon_url);
148 return base::WrapUnique(response); 184 return base::WrapUnique(response);
149 } 185 }
150 186
187 bool ProfileInfoHandler::IsProfileManagingSupervisedUsers() const {
188 return !profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty();
189 }
190
151 } // namespace settings 191 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698