| 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 #ifndef CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_H_ |
| 6 #define CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_H_ | 6 #define CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/task/cancelable_task_tracker.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 | 9 |
| 15 namespace profiles { | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "chrome/browser/profiles/profile_statistics_common.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" |
| 16 | 13 |
| 17 // Constants for the categories in ProfileCategoryStats | 14 namespace base { |
| 18 extern const char kProfileStatisticsBrowsingHistory[]; | 15 class FilePath; |
| 19 extern const char kProfileStatisticsPasswords[]; | 16 } // namespace base |
| 20 extern const char kProfileStatisticsBookmarks[]; | 17 class Profile; |
| 21 extern const char kProfileStatisticsSettings[]; | 18 class ProfileStatisticsAggregator; |
| 22 | 19 |
| 23 // Definition of a single return value of |ProfileStatisticsCallback|. If | 20 // Instances of ProfileStatistics should be created directly. Use |
| 24 // |success| is false, the statistics failed to load and |count| is undefined. | 21 // ProfileStatisticsFactory instead. |
| 25 // The data look like these: {"BrowsingHistory", 912, true}, | 22 class ProfileStatistics : public KeyedService { |
| 26 // {"Passwords", 71, true}, {"Bookmarks", 120, true}, {"Settings", 200, true} | 23 public: |
| 27 struct ProfileCategoryStat { | 24 // Profile Statistics -------------------------------------------------------- |
| 28 std::string category; | 25 |
| 29 int count; | 26 // This function collects statistical information about |profile|, also |
| 30 bool success; | 27 // returns the information via |callback| if |callback| is not null. The |
| 28 // statistical information is also copied to ProfileAttributesStorage. |
| 29 // Currently bookmarks, history, logins and preferences are counted. The |
| 30 // callback function will probably be called more than once, so binding |
| 31 // parameters with bind::Passed() is prohibited. Most of the async tasks |
| 32 // involved in this function can be cancelled if |tracker| is not null. |
| 33 void GatherStatistics(const profiles::ProfileStatisticsCallback& callback); |
| 34 |
| 35 bool HasAggregator() const; |
| 36 ProfileStatisticsAggregator* GetAggregator() const; |
| 37 |
| 38 // ProfileAttributesStorage -------------------------------------------------- |
| 39 |
| 40 // Gets statistical information from the profiles attributes storage. |
| 41 static profiles::ProfileCategoryStats |
| 42 GetProfileStatisticsFromAttributesStorage( |
| 43 const base::FilePath& profile_path); |
| 44 |
| 45 // Sets an individual statistic to the profiles attributes storage. |
| 46 static void SetProfileStatisticsToAttributesStorage( |
| 47 const base::FilePath& profile_path, |
| 48 const std::string& category, |
| 49 int count); |
| 50 |
| 51 private: |
| 52 friend class ProfileStatisticsFactory; |
| 53 |
| 54 explicit ProfileStatistics(Profile* profile); |
| 55 ~ProfileStatistics() override; |
| 56 void RegisterAggregator(ProfileStatisticsAggregator* const aggregator); |
| 57 void DeregisterAggregator(); |
| 58 |
| 59 Profile* profile_; |
| 60 ProfileStatisticsAggregator* aggregator_; |
| 61 base::WeakPtrFactory<ProfileStatistics> weak_ptr_factory_; |
| 31 }; | 62 }; |
| 32 | 63 |
| 33 // Definition of the return value of |ProfileStatisticsCallback|. | |
| 34 using ProfileCategoryStats = std::vector<ProfileCategoryStat>; | |
| 35 | |
| 36 // Definition of the callback function. Note that a copy of | |
| 37 // |ProfileCategoryStats| is made each time the callback is called. | |
| 38 using ProfileStatisticsCallback = base::Callback<void(ProfileCategoryStats)>; | |
| 39 | |
| 40 // Profile Statistics ---------------------------------------------------------- | |
| 41 | |
| 42 // This function collects statistical information about |profile|, also returns | |
| 43 // the information via |callback| if |callback| is not null. The statistical | |
| 44 // information is also copied to ProfileInfoCache. Currently bookmarks, history, | |
| 45 // logins and preferences are counted. The callback function will probably be | |
| 46 // called more than once, so binding parameters with bind::Passed() is | |
| 47 // prohibited. Most of the async tasks involved in this function can be | |
| 48 // cancelled if |tracker| is not null. | |
| 49 void GatherProfileStatistics(Profile* profile, | |
| 50 const ProfileStatisticsCallback& callback, | |
| 51 base::CancelableTaskTracker* tracker); | |
| 52 | |
| 53 // ProfileInfoCache ------------------------------------------------------------ | |
| 54 | |
| 55 // Gets statistical information from ProfileInfoCache. | |
| 56 ProfileCategoryStats GetProfileStatisticsFromCache( | |
| 57 const base::FilePath& profile_path); | |
| 58 | |
| 59 // Sets an individual statistic to ProfileInfoCache. | |
| 60 void SetProfileStatisticsInCache(const base::FilePath& profile_path, | |
| 61 const std::string& category, int count); | |
| 62 | |
| 63 } // namespace profiles | |
| 64 | |
| 65 #endif // CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_H_ | 64 #endif // CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_H_ |
| OLD | NEW |