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

Side by Side Diff: chrome/browser/profiles/profile_statistics.h

Issue 1579433002: Make profile statistics tasks inspectable by tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed gyp/gn files, also a few small changes Created 4 years, 9 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 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 <map>
8 #include <string> 9 #include <string>
9 #include <utility> 10 #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 11
15 namespace profiles { 12 #include "chrome/browser/profiles/profile_statistics_types.h"
13 #include "components/keyed_service/core/keyed_service.h"
16 14
17 // Constants for the categories in ProfileCategoryStats 15 namespace base {
18 extern const char kProfileStatisticsBrowsingHistory[]; 16 class FilePath;
19 extern const char kProfileStatisticsPasswords[]; 17 } // namespace base
20 extern const char kProfileStatisticsBookmarks[]; 18 class Profile;
21 extern const char kProfileStatisticsSettings[]; 19 class ProfileStatisticsAggregator;
22 20
23 // Definition of a single return value of |ProfileStatisticsCallback|. If 21 class ProfileStatistics : public KeyedService {
24 // |success| is false, the statistics failed to load and |count| is undefined. 22 public:
25 // The data look like these: {"BrowsingHistory", 912, true}, 23 // Profile Statistics --------------------------------------------------------
26 // {"Passwords", 71, true}, {"Bookmarks", 120, true}, {"Settings", 200, true} 24
27 struct ProfileCategoryStat { 25 // This function collects statistical information about |profile|, also
28 std::string category; 26 // returns the information via |callback| if |callback| is not null. The
29 int count; 27 // statistical information is also copied to ProfileAttributesStorage.
30 bool success; 28 // Currently bookmarks, history, logins and preferences are counted. The
29 // callback function will probably be called more than once, so binding
30 // parameters with bind::Passed() is prohibited. Most of the async tasks
31 // involved in this function can be cancelled if |tracker| is not null.
32 void GatherStatistics(const profiles::ProfileStatisticsCallback& callback);
33
34 bool HasAggregator();
35 ProfileStatisticsAggregator* const GetAggregator();
36
37 // ProfileAttributesStorage --------------------------------------------------
38
39 // Gets statistical information from the profiles attributes storage.
40 static profiles::ProfileCategoryStats GetProfileStatisticsFromCache(
41 const base::FilePath& profile_path);
42
43 // Sets an individual statistic to the profiles attributes storage.
44 static void SetProfileStatisticsInCache(const base::FilePath& profile_path,
45 const std::string& category, int count);
46
47 private:
48 friend class ProfileStatisticsFactory;
49
50 explicit ProfileStatistics(Profile* profile) : profile_(profile) {}
Mike Lerman 2016/03/15 18:54:22 Set profile_ in the .cc file
lwchkg 2016/03/16 13:28:02 Done.
51 void RegisterAggregator(ProfileStatisticsAggregator* const aggregator);
52 void DeregisterAggregator();
53
54 Profile* profile_;
55 ProfileStatisticsAggregator* aggregator_ = nullptr;
Mike Lerman 2016/03/15 18:54:22 set aggregator_ = nullptr in the .cc file's constr
lwchkg 2016/03/16 13:28:02 Done.
31 }; 56 };
32 57
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_ 58 #endif // CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698