Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.h" | 5 #include "chrome/browser/profiles/profile_statistics.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/task_runner.h" | 10 #include "base/task_runner.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/history/history_service_factory.h" | 14 #include "chrome/browser/history/history_service_factory.h" |
| 14 #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_attributes_entry.h" | |
| 17 #include "chrome/browser/profiles/profile_attributes_storage.h" | |
| 18 #include "chrome/browser/profiles/profile_info_cache.h" | |
| 19 #include "chrome/browser/profiles/profile_manager.h" | |
| 15 #include "components/bookmarks/browser/bookmark_model.h" | 20 #include "components/bookmarks/browser/bookmark_model.h" |
| 16 #include "components/history/core/browser/history_service.h" | 21 #include "components/history/core/browser/history_service.h" |
| 17 #include "components/password_manager/core/browser/password_store.h" | 22 #include "components/password_manager/core/browser/password_store.h" |
| 18 #include "components/password_manager/core/browser/password_store_consumer.h" | 23 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 19 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 20 | 25 |
| 21 using content::BrowserThread; | 26 using content::BrowserThread; |
| 22 | 27 |
| 23 namespace { | 28 namespace { |
| 24 | 29 |
| 25 struct ProfileStatValue { | 30 struct ProfileStatValue { |
| 26 int count; | 31 int count; |
| 27 bool success; // false means the statistics failed to load | 32 bool success; // false means the statistics failed to load |
| 28 }; | 33 }; |
| 29 | 34 |
| 30 int CountBookmarksFromNode(const bookmarks::BookmarkNode* node) { | 35 int CountBookmarksFromNode(const bookmarks::BookmarkNode* node) { |
| 31 int count = 0; | 36 int count = 0; |
| 32 if (node->is_url()) { | 37 if (node->is_url()) { |
| 33 ++count; | 38 ++count; |
| 34 } else { | 39 } else { |
| 35 for (int i = 0; i < node->child_count(); ++i) | 40 for (int i = 0; i < node->child_count(); ++i) |
| 36 count += CountBookmarksFromNode(node->GetChild(i)); | 41 count += CountBookmarksFromNode(node->GetChild(i)); |
| 37 } | 42 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 const char kProfileStatisticsBookmarks[] = "Bookmarks"; | 261 const char kProfileStatisticsBookmarks[] = "Bookmarks"; |
| 257 const char kProfileStatisticsSettings[] = "Settings"; | 262 const char kProfileStatisticsSettings[] = "Settings"; |
| 258 | 263 |
| 259 void GetProfileStatistics(Profile* profile, | 264 void GetProfileStatistics(Profile* profile, |
| 260 const ProfileStatisticsCallback& callback, | 265 const ProfileStatisticsCallback& callback, |
| 261 base::CancelableTaskTracker* tracker) { | 266 base::CancelableTaskTracker* tracker) { |
| 262 scoped_refptr<ProfileStatisticsAggregator> aggregator = | 267 scoped_refptr<ProfileStatisticsAggregator> aggregator = |
| 263 new ProfileStatisticsAggregator(profile, callback, tracker); | 268 new ProfileStatisticsAggregator(profile, callback, tracker); |
| 264 } | 269 } |
| 265 | 270 |
| 271 ProfileCategoryStats GetProfileStatisticsFromCache(Profile* profile) { | |
| 272 DCHECK(profile); | |
| 273 | |
| 274 ProfileInfoCache& profile_info_cache = | |
| 275 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
|
lwchkg
2015/11/18 17:34:53
Wrong indent. Done.
| |
| 276 ProfileAttributesEntry* entry = nullptr; | |
| 277 bool has_entry = profile_info_cache. | |
| 278 GetProfileAttributesWithPath(profile->GetPath(), &entry); | |
| 279 | |
| 280 ProfileCategoryStats stats; | |
| 281 ProfileCategoryStat stat; | |
| 282 | |
| 283 stat.category = kProfileStatisticsBrowsingHistory; | |
| 284 stat.success = has_entry ? entry->HasStatsBrowsingHistory() : false; | |
| 285 stat.count = stat.success ? entry->GetStatsBrowsingHistory() : 0; | |
| 286 stats.push_back(stat); | |
| 287 | |
| 288 stat.category = kProfileStatisticsPasswords; | |
| 289 stat.success = has_entry ? entry->HasStatsPasswords() : false; | |
| 290 stat.count = stat.success ? entry->GetStatsPasswords() : 0; | |
| 291 stats.push_back(stat); | |
| 292 | |
| 293 stat.category = kProfileStatisticsBookmarks; | |
| 294 stat.success = has_entry ? entry->HasStatsBookmarks() : false; | |
| 295 stat.count = stat.success ? entry->GetStatsBookmarks() : 0; | |
| 296 stats.push_back(stat); | |
| 297 | |
| 298 stat.category = kProfileStatisticsSettings; | |
| 299 stat.success = has_entry ? entry->HasStatsSettings() : false; | |
| 300 stat.count = stat.success ? entry->GetStatsSettings() : 0; | |
| 301 stats.push_back(stat); | |
| 302 | |
| 303 return stats; | |
| 304 } | |
| 305 | |
| 306 void StoreProfileStatisticsToCache(Profile* profile, | |
| 307 const std::string& category, int count) { | |
| 308 DCHECK(profile); | |
| 309 | |
| 310 ProfileInfoCache& profile_info_cache = | |
| 311 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
|
lwchkg
2015/11/18 17:34:53
Wrong indent. Done.
| |
| 312 ProfileAttributesEntry* entry = nullptr; | |
| 313 if (!profile_info_cache.GetProfileAttributesWithPath( | |
| 314 profile->GetPath(), &entry)) | |
| 315 return; | |
| 316 | |
| 317 if (category == kProfileStatisticsBrowsingHistory) { | |
| 318 entry->SetStatsBrowsingHistory(count); | |
| 319 } else if (category == kProfileStatisticsPasswords) { | |
| 320 entry->SetStatsPasswords(count); | |
| 321 } else if (category == kProfileStatisticsBookmarks) { | |
| 322 entry->SetStatsBookmarks(count); | |
| 323 } else if (category == kProfileStatisticsSettings) { | |
| 324 entry->SetStatsSettings(count); | |
| 325 } else { | |
| 326 NOTREACHED(); | |
| 327 } | |
| 328 } | |
| 329 | |
| 266 } // namespace profiles | 330 } // namespace profiles |
| OLD | NEW |