OLD | NEW |
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 "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); | 146 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); |
147 if (!item.success) { | 147 if (!item.success) { |
148 count = 0; | 148 count = 0; |
149 break; | 149 break; |
150 } | 150 } |
151 count += item.count; | 151 count += item.count; |
152 } | 152 } |
153 // PushProfileStatsCount gets invoked multiple times as each stat becomes | 153 // PushProfileStatsCount gets invoked multiple times as each stat becomes |
154 // available. Therefore, webUIListenerCallback mechanism is used instead of | 154 // available. Therefore, webUIListenerCallback mechanism is used instead of |
155 // the Promise callback approach. | 155 // the Promise callback approach. |
156 CallJavascriptFunction("cr.webUIListenerCallback", | 156 FireWebUIListener(kProfileStatsCountReadyEventName, base::Value(count)); |
157 base::Value(kProfileStatsCountReadyEventName), | |
158 base::Value(count)); | |
159 } | 157 } |
160 #endif | 158 #endif |
161 | 159 |
162 void ProfileInfoHandler::HandleGetProfileManagesSupervisedUsers( | 160 void ProfileInfoHandler::HandleGetProfileManagesSupervisedUsers( |
163 const base::ListValue* args) { | 161 const base::ListValue* args) { |
164 AllowJavascript(); | 162 AllowJavascript(); |
165 | 163 |
166 CHECK_EQ(1U, args->GetSize()); | 164 CHECK_EQ(1U, args->GetSize()); |
167 const base::Value* callback_id; | 165 const base::Value* callback_id; |
168 CHECK(args->Get(0, &callback_id)); | 166 CHECK(args->Get(0, &callback_id)); |
169 | 167 |
170 ResolveJavascriptCallback(*callback_id, | 168 ResolveJavascriptCallback(*callback_id, |
171 base::Value(IsProfileManagingSupervisedUsers())); | 169 base::Value(IsProfileManagingSupervisedUsers())); |
172 } | 170 } |
173 | 171 |
174 void ProfileInfoHandler::PushProfileInfo() { | 172 void ProfileInfoHandler::PushProfileInfo() { |
175 CallJavascriptFunction("cr.webUIListenerCallback", | 173 FireWebUIListener(kProfileInfoChangedEventName, *GetAccountNameAndIcon()); |
176 base::Value(kProfileInfoChangedEventName), | |
177 *GetAccountNameAndIcon()); | |
178 } | 174 } |
179 | 175 |
180 void ProfileInfoHandler::PushProfileManagesSupervisedUsersStatus() { | 176 void ProfileInfoHandler::PushProfileManagesSupervisedUsersStatus() { |
181 CallJavascriptFunction( | 177 CallJavascriptFunction( |
182 "cr.webUIListenerCallback", | 178 "cr.webUIListenerCallback", |
183 base::Value(kProfileManagesSupervisedUsersChangedEventName), | 179 base::Value(kProfileManagesSupervisedUsersChangedEventName), |
184 base::Value(IsProfileManagingSupervisedUsers())); | 180 base::Value(IsProfileManagingSupervisedUsers())); |
185 } | 181 } |
186 | 182 |
187 std::unique_ptr<base::DictionaryValue> | 183 std::unique_ptr<base::DictionaryValue> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 response->SetString("name", name); | 216 response->SetString("name", name); |
221 response->SetString("iconUrl", icon_url); | 217 response->SetString("iconUrl", icon_url); |
222 return base::WrapUnique(response); | 218 return base::WrapUnique(response); |
223 } | 219 } |
224 | 220 |
225 bool ProfileInfoHandler::IsProfileManagingSupervisedUsers() const { | 221 bool ProfileInfoHandler::IsProfileManagingSupervisedUsers() const { |
226 return !profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty(); | 222 return !profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty(); |
227 } | 223 } |
228 | 224 |
229 } // namespace settings | 225 } // namespace settings |
OLD | NEW |