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 <set> | 7 #include <set> |
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/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/history/history_service_factory.h" | 17 #include "chrome/browser/history/history_service_factory.h" |
18 #include "chrome/browser/password_manager/password_store_factory.h" | 18 #include "chrome/browser/password_manager/password_store_factory.h" |
19 #include "chrome/browser/profiles/profile_attributes_entry.h" | 19 #include "chrome/browser/profiles/profile_attributes_entry.h" |
20 #include "chrome/browser/profiles/profile_attributes_storage.h" | 20 #include "chrome/browser/profiles/profile_attributes_storage.h" |
21 #include "chrome/browser/profiles/profile_info_cache.h" | |
22 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
23 #include "components/bookmarks/browser/bookmark_model.h" | 22 #include "components/bookmarks/browser/bookmark_model.h" |
24 #include "components/bookmarks/browser/bookmark_model_observer.h" | 23 #include "components/bookmarks/browser/bookmark_model_observer.h" |
25 #include "components/history/core/browser/history_service.h" | 24 #include "components/history/core/browser/history_service.h" |
26 #include "components/password_manager/core/browser/password_store.h" | 25 #include "components/password_manager/core/browser/password_store.h" |
27 #include "components/password_manager/core/browser/password_store_consumer.h" | 26 #include "components/password_manager/core/browser/password_store_consumer.h" |
28 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
29 | 28 |
30 namespace { | 29 namespace { |
31 | 30 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 DCHECK(profile); | 344 DCHECK(profile); |
346 if (profile->IsOffTheRecord() || profile->IsSystemProfile()) { | 345 if (profile->IsOffTheRecord() || profile->IsSystemProfile()) { |
347 NOTREACHED(); | 346 NOTREACHED(); |
348 return; | 347 return; |
349 } | 348 } |
350 | 349 |
351 scoped_refptr<ProfileStatisticsAggregator> aggregator = | 350 scoped_refptr<ProfileStatisticsAggregator> aggregator = |
352 new ProfileStatisticsAggregator(profile, callback, tracker); | 351 new ProfileStatisticsAggregator(profile, callback, tracker); |
353 } | 352 } |
354 | 353 |
355 ProfileCategoryStats GetProfileStatisticsFromCache( | 354 ProfileCategoryStats GetProfileStatisticsFromCache( |
lwchkg
2016/01/17 12:33:28
This function will be renamed to GetProfileStatist
anthonyvd
2016/01/18 15:22:31
I think this functionality (as well as the other o
lwchkg
2016/01/18 17:54:02
The decision of putting these two functions here w
| |
356 const base::FilePath& profile_path) { | 355 const base::FilePath& profile_path) { |
357 ProfileInfoCache& profile_info_cache = | |
358 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
359 ProfileAttributesEntry* entry = nullptr; | 356 ProfileAttributesEntry* entry = nullptr; |
360 bool has_entry = profile_info_cache. | 357 bool has_entry = g_browser_process->profile_manager()-> |
358 GetProfileAttributesStorage(). | |
361 GetProfileAttributesWithPath(profile_path, &entry); | 359 GetProfileAttributesWithPath(profile_path, &entry); |
362 | 360 |
363 ProfileCategoryStats stats; | 361 ProfileCategoryStats stats; |
364 ProfileCategoryStat stat; | 362 ProfileCategoryStat stat; |
365 | 363 |
366 stat.category = kProfileStatisticsBrowsingHistory; | 364 stat.category = kProfileStatisticsBrowsingHistory; |
367 stat.success = has_entry ? entry->HasStatsBrowsingHistory() : false; | 365 stat.success = has_entry ? entry->HasStatsBrowsingHistory() : false; |
368 stat.count = stat.success ? entry->GetStatsBrowsingHistory() : 0; | 366 stat.count = stat.success ? entry->GetStatsBrowsingHistory() : 0; |
369 stats.push_back(stat); | 367 stats.push_back(stat); |
370 | 368 |
371 stat.category = kProfileStatisticsPasswords; | 369 stat.category = kProfileStatisticsPasswords; |
372 stat.success = has_entry ? entry->HasStatsPasswords() : false; | 370 stat.success = has_entry ? entry->HasStatsPasswords() : false; |
373 stat.count = stat.success ? entry->GetStatsPasswords() : 0; | 371 stat.count = stat.success ? entry->GetStatsPasswords() : 0; |
374 stats.push_back(stat); | 372 stats.push_back(stat); |
375 | 373 |
376 stat.category = kProfileStatisticsBookmarks; | 374 stat.category = kProfileStatisticsBookmarks; |
377 stat.success = has_entry ? entry->HasStatsBookmarks() : false; | 375 stat.success = has_entry ? entry->HasStatsBookmarks() : false; |
378 stat.count = stat.success ? entry->GetStatsBookmarks() : 0; | 376 stat.count = stat.success ? entry->GetStatsBookmarks() : 0; |
379 stats.push_back(stat); | 377 stats.push_back(stat); |
380 | 378 |
381 stat.category = kProfileStatisticsSettings; | 379 stat.category = kProfileStatisticsSettings; |
382 stat.success = has_entry ? entry->HasStatsSettings() : false; | 380 stat.success = has_entry ? entry->HasStatsSettings() : false; |
383 stat.count = stat.success ? entry->GetStatsSettings() : 0; | 381 stat.count = stat.success ? entry->GetStatsSettings() : 0; |
384 stats.push_back(stat); | 382 stats.push_back(stat); |
385 | 383 |
386 return stats; | 384 return stats; |
387 } | 385 } |
388 | 386 |
389 void SetProfileStatisticsInCache(const base::FilePath& profile_path, | 387 void SetProfileStatisticsInCache(const base::FilePath& profile_path, |
lwchkg
2016/01/17 12:33:28
Similarly, this function will be renamed SetProfil
Mike Lerman
2016/01/19 16:57:46
Or just SetProfileStatisticsInStorage. (don't need
| |
390 const std::string& category, int count) { | 388 const std::string& category, int count) { |
391 // If local_state() is null, profile_manager() will seg-fault. | 389 // If local_state() is null, profile_manager() will seg-fault. |
392 if (!g_browser_process || !g_browser_process->local_state()) | 390 if (!g_browser_process || !g_browser_process->local_state()) |
393 return; | 391 return; |
394 | 392 |
395 // profile_manager() may return a null pointer. | 393 // profile_manager() may return a null pointer. |
396 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 394 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
397 if (!profile_manager) | 395 if (!profile_manager) |
398 return; | 396 return; |
399 | 397 |
400 ProfileInfoCache& profile_info_cache = profile_manager->GetProfileInfoCache(); | |
401 ProfileAttributesEntry* entry = nullptr; | 398 ProfileAttributesEntry* entry = nullptr; |
402 if (!profile_info_cache.GetProfileAttributesWithPath(profile_path, &entry)) | 399 if (!profile_manager->GetProfileAttributesStorage(). |
400 GetProfileAttributesWithPath(profile_path, &entry)) | |
403 return; | 401 return; |
404 | 402 |
405 if (category == kProfileStatisticsBrowsingHistory) { | 403 if (category == kProfileStatisticsBrowsingHistory) { |
406 entry->SetStatsBrowsingHistory(count); | 404 entry->SetStatsBrowsingHistory(count); |
407 } else if (category == kProfileStatisticsPasswords) { | 405 } else if (category == kProfileStatisticsPasswords) { |
408 entry->SetStatsPasswords(count); | 406 entry->SetStatsPasswords(count); |
409 } else if (category == kProfileStatisticsBookmarks) { | 407 } else if (category == kProfileStatisticsBookmarks) { |
410 entry->SetStatsBookmarks(count); | 408 entry->SetStatsBookmarks(count); |
411 } else if (category == kProfileStatisticsSettings) { | 409 } else if (category == kProfileStatisticsSettings) { |
412 entry->SetStatsSettings(count); | 410 entry->SetStatsSettings(count); |
413 } else { | 411 } else { |
414 NOTREACHED(); | 412 NOTREACHED(); |
415 } | 413 } |
416 } | 414 } |
417 | 415 |
418 } // namespace profiles | 416 } // namespace profiles |
OLD | NEW |