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

Side by Side 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 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/profiles/profile_statistics_aggregator.h" 5 #include "chrome/browser/profiles/profile_statistics_aggregator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/history/history_service_factory.h" 14 #include "chrome/browser/history/history_service_factory.h"
15 #include "chrome/browser/password_manager/password_store_factory.h" 15 #include "chrome/browser/password_manager/password_store_factory.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/profiles/profile_statistics.h" 18 #include "chrome/browser/profiles/profile_statistics.h"
19 #include "chrome/browser/profiles/profile_statistics_factory.h" 19 #include "chrome/browser/profiles/profile_statistics_factory.h"
20 #include "components/bookmarks/browser/bookmark_model.h" 20 #include "components/bookmarks/browser/bookmark_model.h"
21 #include "components/bookmarks/browser/bookmark_node.h" 21 #include "components/bookmarks/browser/bookmark_node.h"
22 #include "components/history/core/browser/history_service.h" 22 #include "components/history/core/browser/history_service.h"
23 #include "components/password_manager/core/browser/password_store.h" 23 #include "components/password_manager/core/browser/password_store.h"
24 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
25 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 26
27 namespace { 27 namespace {
28 28
29 // Callback for each pref. Every one that should be counted as a changed
30 // user pref will cause *count to be incremented.
31 void AccumulatePrefStats(const PrefService* pref_service,
32 int* count,
33 const std::string& key,
34 const base::Value& value) {
35 const PrefService::Preference* pref = pref_service->FindPreference(key);
36 // Skip all dictionaries, only want to count values.
37 if (!value.is_dict() && pref && pref->IsUserControlled() &&
38 !pref->IsDefaultValue())
39 ++(*count);
40 }
41
29 int CountBookmarksFromNode(const bookmarks::BookmarkNode* node) { 42 int CountBookmarksFromNode(const bookmarks::BookmarkNode* node) {
30 int count = 0; 43 int count = 0;
31 if (node->is_url()) { 44 if (node->is_url()) {
32 ++count; 45 ++count;
33 } else { 46 } else {
34 for (int i = 0; i < node->child_count(); ++i) 47 for (int i = 0; i < node->child_count(); ++i)
35 count += CountBookmarksFromNode(node->GetChild(i)); 48 count += CountBookmarksFromNode(node->GetChild(i));
36 } 49 }
37 return count; 50 return count;
38 } 51 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 StatisticsCallbackFailure(profiles::kProfileStatisticsBookmarks); 222 StatisticsCallbackFailure(profiles::kProfileStatisticsBookmarks);
210 } 223 }
211 } 224 }
212 225
213 ProfileStatisticsAggregator::ProfileStatValue 226 ProfileStatisticsAggregator::ProfileStatValue
214 ProfileStatisticsAggregator::CountPrefs() const { 227 ProfileStatisticsAggregator::CountPrefs() const {
215 const PrefService* pref_service = profile_->GetPrefs(); 228 const PrefService* pref_service = profile_->GetPrefs();
216 229
217 ProfileStatValue result; 230 ProfileStatValue result;
218 if (pref_service) { 231 if (pref_service) {
219 std::unique_ptr<base::DictionaryValue> prefs = 232 pref_service->IteratePreferenceValues(base::BindRepeating(
220 pref_service->GetPreferenceValuesWithoutPathExpansion(); 233 &AccumulatePrefStats, pref_service, base::Unretained(&result.count)));
221
222 int count = 0;
223 for (base::DictionaryValue::Iterator it(*(prefs.get()));
224 !it.IsAtEnd(); it.Advance()) {
225 const PrefService::Preference* pref = pref_service->
226 FindPreference(it.key());
227 // Skip all dictionaries (which must be empty by the function call above).
228 if (it.value().GetType() != base::Value::Type::DICTIONARY &&
229 pref && pref->IsUserControlled() && !pref->IsDefaultValue()) {
230 ++count;
231 }
232 }
233
234 result.count = count;
235 result.success = true; 234 result.success = true;
236 } else {
237 result.count = 0;
238 result.success = false;
239 } 235 }
240 return result; 236 return result;
241 } 237 }
OLDNEW
« 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