Index: chrome/browser/profiles/profile_statistics.cc |
diff --git a/chrome/browser/profiles/profile_statistics.cc b/chrome/browser/profiles/profile_statistics.cc |
index 88b48f933b5e55983e991439d07c35d720664c00..511384eade308b07aebe11c4f49e6db865da6a15 100644 |
--- a/chrome/browser/profiles/profile_statistics.cc |
+++ b/chrome/browser/profiles/profile_statistics.cc |
@@ -10,8 +10,13 @@ |
#include "base/task_runner.h" |
#include "base/time/time.h" |
#include "chrome/browser/bookmarks/bookmark_model_factory.h" |
+#include "chrome/browser/browser_process.h" |
#include "chrome/browser/history/history_service_factory.h" |
#include "chrome/browser/password_manager/password_store_factory.h" |
+#include "chrome/browser/profiles/profile_attributes_entry.h" |
+#include "chrome/browser/profiles/profile_attributes_storage.h" |
+#include "chrome/browser/profiles/profile_info_cache.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
#include "components/bookmarks/browser/bookmark_model.h" |
#include "components/history/core/browser/history_service.h" |
#include "components/password_manager/core/browser/password_store.h" |
@@ -27,6 +32,8 @@ struct ProfileStatValue { |
bool success; // false means the statistics failed to load |
}; |
+void NoOp(profiles::ProfileCategoryStats result) {} |
+ |
int CountBookmarksFromNode(const bookmarks::BookmarkNode* node) { |
int count = 0; |
if (node->is_url()) { |
@@ -86,6 +93,7 @@ class ProfileStatisticsAggregator |
const profiles::ProfileStatisticsCallback callback_; |
base::CancelableTaskTracker* tracker_; |
+ scoped_ptr<base::CancelableTaskTracker> default_tracker_; |
// Password counting. |
class PasswordStoreConsumerHelper |
@@ -118,6 +126,10 @@ ProfileStatisticsAggregator::ProfileStatisticsAggregator( |
callback_(callback), |
tracker_(tracker), |
password_store_consumer_helper_(this) { |
+ if (!tracker_) { |
+ default_tracker_.reset(new base::CancelableTaskTracker); |
+ tracker_ = default_tracker_.get(); |
+ } |
Init(); |
} |
@@ -173,6 +185,20 @@ void ProfileStatisticsAggregator::StatisticsCallback( |
datum.success = result.success; |
profile_category_stats_.push_back(datum); |
callback_.Run(profile_category_stats_); |
+ |
+ // Set statistic in ProfileInfoCache if possible. |
+ // Note: if local_state() is null, profile_manager() will seg-fault. |
+ if (result.success && g_browser_process && g_browser_process->local_state()) { |
+ ProfileInfoCache& profile_info_cache = |
Mike Lerman
2015/11/03 20:50:42
const ProfileInfoCache& please
lwchkg
2015/11/04 00:11:07
Acknowledged.
lwchkg
2015/11/05 22:21:30
I've tried, but the compiler complains.
e:\chromi
Mike Lerman
2015/11/10 15:45:44
Ah - getProfileAttributesWithPath isn't const. Sor
|
+ g_browser_process->profile_manager()->GetProfileInfoCache(); |
+ if (&profile_info_cache) { |
Mike Lerman
2015/11/03 20:50:42
you can assume if you have a ProfileManager than y
lwchkg
2015/11/04 00:11:07
You're right. Thanks.
|
+ ProfileAttributesEntry* entry = nullptr; |
+ if (profile_info_cache.GetProfileAttributesWithPath( |
+ profile_->GetPath(), &entry)) { |
+ entry->SetStatistic(datum.category, result.count); |
+ } |
+ } |
+ } |
} |
void ProfileStatisticsAggregator::StatisticsCallbackSuccess( |
@@ -263,4 +289,8 @@ void GetProfileStatistics(Profile* profile, |
new ProfileStatisticsAggregator(profile, callback, tracker); |
} |
+void StoreProfileStatisticsToCache(Profile* profile) { |
+ GetProfileStatistics(profile, base::Bind(&NoOp), nullptr); |
Mike Lerman
2015/11/03 20:50:42
I think you can just write profiles::ProfileCatgeo
lwchkg
2015/11/04 00:11:07
Not sure about this. Will try tonight.
lwchkg
2015/11/05 22:21:30
Tried but not succeeded. I've tried to make a lamb
Mike Lerman
2015/11/10 15:45:44
Aha! Found an example:
https://code.google.com/p/c
lwchkg
2015/11/10 18:11:07
Thanks. It's working well!
|
+} |
+ |
} // namespace profiles |