| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 ProfileStatisticsFactory::GetForProfile(profile_)->GatherStatistics( | 134 ProfileStatisticsFactory::GetForProfile(profile_)->GatherStatistics( |
| 135 base::Bind(&ProfileInfoHandler::PushProfileStatsCount, | 135 base::Bind(&ProfileInfoHandler::PushProfileStatsCount, |
| 136 callback_weak_ptr_factory_.GetWeakPtr())); | 136 callback_weak_ptr_factory_.GetWeakPtr())); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ProfileInfoHandler::PushProfileStatsCount( | 139 void ProfileInfoHandler::PushProfileStatsCount( |
| 140 profiles::ProfileCategoryStats stats) { | 140 profiles::ProfileCategoryStats stats) { |
| 141 int count = 0; | 141 int count = 0; |
| 142 for (const auto& item : stats) { | 142 for (const auto& item : stats) { |
| 143 std::unique_ptr<base::DictionaryValue> stat(new base::DictionaryValue); | |
| 144 if (!item.success) { | |
| 145 count = 0; | |
| 146 break; | |
| 147 } | |
| 148 count += item.count; | 143 count += item.count; |
| 149 } | 144 } |
| 150 // PushProfileStatsCount gets invoked multiple times as each stat becomes | 145 // PushProfileStatsCount gets invoked multiple times as each stat becomes |
| 151 // available. Therefore, webUIListenerCallback mechanism is used instead of | 146 // available. Therefore, webUIListenerCallback mechanism is used instead of |
| 152 // the Promise callback approach. | 147 // the Promise callback approach. |
| 153 FireWebUIListener(kProfileStatsCountReadyEventName, base::Value(count)); | 148 FireWebUIListener(kProfileStatsCountReadyEventName, base::Value(count)); |
| 154 } | 149 } |
| 155 #endif | 150 #endif |
| 156 | 151 |
| 157 void ProfileInfoHandler::HandleGetProfileManagesSupervisedUsers( | 152 void ProfileInfoHandler::HandleGetProfileManagesSupervisedUsers( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 response->SetString("name", name); | 208 response->SetString("name", name); |
| 214 response->SetString("iconUrl", icon_url); | 209 response->SetString("iconUrl", icon_url); |
| 215 return base::WrapUnique(response); | 210 return base::WrapUnique(response); |
| 216 } | 211 } |
| 217 | 212 |
| 218 bool ProfileInfoHandler::IsProfileManagingSupervisedUsers() const { | 213 bool ProfileInfoHandler::IsProfileManagingSupervisedUsers() const { |
| 219 return !profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty(); | 214 return !profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUsers)->empty(); |
| 220 } | 215 } |
| 221 | 216 |
| 222 } // namespace settings | 217 } // namespace settings |
| OLD | NEW |