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

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: Make ProfileStatisticsAggregator tasks trackable Created 4 years, 11 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"
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 class ProfileStatistics {
24 // |success| is false, the statistics failed to load and |count| is undefined. 21 public:
25 // The data look like these: {"BrowsingHistory", 912, true}, 22 // Profile Statistics --------------------------------------------------------
26 // {"Passwords", 71, true}, {"Bookmarks", 120, true}, {"Settings", 200, true} 23
27 struct ProfileCategoryStat { 24 // This function collects statistical information about |profile|, also
28 std::string category; 25 // returns the information via |callback| if |callback| is not null. The
29 int count; 26 // statistical information is also copied to ProfileInfoCache. Currently
30 bool success; 27 // bookmarks, history, logins and preferences are counted. The callback
28 // function will probably be called more than once, so binding parameters with
29 // bind::Passed() is prohibited. Most of the async tasks involved in this
30 // function can be cancelled if |tracker| is not null.
31 static void GatherProfileStatistics(Profile* profile,
32 const profiles::ProfileStatisticsCallback& callback);
33
34 // ProfileInfoCache ----------------------------------------------------------
35
36 // Gets statistical information from ProfileInfoCache.
37 static profiles::ProfileCategoryStats GetProfileStatisticsFromCache(
38 const base::FilePath& profile_path);
39
40 // Sets an individual statistic to ProfileInfoCache.
41 static void SetProfileStatisticsInCache(const base::FilePath& profile_path,
42 const std::string& category, int count);
43
44 static bool HasAggregator(void* profile);
45 static ProfileStatisticsAggregator* const GetAggregator(void* profile);
46 static void RegisterAggregator(void* profile,
47 ProfileStatisticsAggregator* const aggregator);
48 static void DeregisterAggregator(void* profile);
49
50 private:
51 static std::map<void*, ProfileStatisticsAggregator*> aggregators_;
lwchkg 2016/01/25 21:35:53 Having a static member here is not good. Which of
Mike Lerman 2016/02/01 16:42:01 I think this could be a ProfileKeyedService.
31 }; 52 };
32 53
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_ 54 #endif // CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698