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

Unified Diff: chrome/browser/profiles/profile_statistics_aggregator.cc

Issue 2799143002: Improve profile stats performace. (Closed)
Patch Set: Use enum Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/profile_statistics_aggregator.cc
diff --git a/chrome/browser/profiles/profile_statistics_aggregator.cc b/chrome/browser/profiles/profile_statistics_aggregator.cc
index e3582be32006c73315bfa8af382e87adf68a2e3c..7949b8f507bd95d625c07f8a4aa1d41a152415a0 100644
--- a/chrome/browser/profiles/profile_statistics_aggregator.cc
+++ b/chrome/browser/profiles/profile_statistics_aggregator.cc
@@ -26,6 +26,19 @@
namespace {
+// Callback for each pref. Every one that should be counted as a changed
+// user pref will cause *count to be incremented.
+void AccumulatePrefStats(const PrefService* pref_service,
+ int* count,
+ const std::string& key,
+ const base::Value& value) {
+ const PrefService::Preference* pref = pref_service->FindPreference(key);
+ // Skip all dictionaries, only want to count values.
+ if (!value.is_dict() && pref && pref->IsUserControlled() &&
+ !pref->IsDefaultValue())
+ ++(*count);
+}
+
int CountBookmarksFromNode(const bookmarks::BookmarkNode* node) {
int count = 0;
if (node->is_url()) {
@@ -216,26 +229,9 @@ ProfileStatisticsAggregator::ProfileStatValue
ProfileStatValue result;
if (pref_service) {
- std::unique_ptr<base::DictionaryValue> prefs =
- pref_service->GetPreferenceValuesWithoutPathExpansion();
-
- int count = 0;
- for (base::DictionaryValue::Iterator it(*(prefs.get()));
- !it.IsAtEnd(); it.Advance()) {
- const PrefService::Preference* pref = pref_service->
- FindPreference(it.key());
- // Skip all dictionaries (which must be empty by the function call above).
- if (it.value().GetType() != base::Value::Type::DICTIONARY &&
- pref && pref->IsUserControlled() && !pref->IsDefaultValue()) {
- ++count;
- }
- }
-
- result.count = count;
+ pref_service->IteratePreferenceValues(base::BindRepeating(
+ &AccumulatePrefStats, pref_service, base::Unretained(&result.count)));
result.success = true;
- } else {
- result.count = 0;
- result.success = false;
}
return result;
}
« no previous file with comments | « chrome/browser/profiles/profile_statistics_aggregator.h ('k') | chrome/browser/ui/webui/local_state/local_state_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698