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 COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ | 5 #ifndef COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ |
6 #define COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ | 6 #define COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 ResultInt Value() const; | 51 ResultInt Value() const; |
52 | 52 |
53 private: | 53 private: |
54 ResultInt value_; | 54 ResultInt value_; |
55 | 55 |
56 DISALLOW_COPY_AND_ASSIGN(FinishedResult); | 56 DISALLOW_COPY_AND_ASSIGN(FinishedResult); |
57 }; | 57 }; |
58 | 58 |
59 typedef base::Callback<void(std::unique_ptr<Result>)> Callback; | 59 typedef base::Callback<void(std::unique_ptr<Result>)> Callback; |
60 | 60 |
61 BrowsingDataCounter(const std::string& pref_name); | 61 BrowsingDataCounter(); |
62 virtual ~BrowsingDataCounter(); | 62 virtual ~BrowsingDataCounter(); |
63 | 63 |
64 // Should be called once to initialize this class. | 64 // Should be called once to initialize this class. |
65 void Init(PrefService* pref_service, const Callback& callback); | 65 void Init(PrefService* pref_service, const Callback& callback); |
66 | 66 |
67 // Name of the preference associated with this counter. | 67 // Name of the preference associated with this counter. |
68 const std::string& GetPrefName() const; | 68 virtual const char* GetPrefName() const = 0; |
69 | 69 |
70 // PrefService that manages the preferences for the user profile | 70 // PrefService that manages the preferences for the user profile |
71 // associated with this counter. | 71 // associated with this counter. |
72 PrefService* GetPrefs() const; | 72 PrefService* GetPrefs() const; |
73 | 73 |
74 // Restarts the counter. Will be called automatically if the counting needs | 74 // Restarts the counter. Will be called automatically if the counting needs |
75 // to be restarted, e.g. when the deletion preference changes state or when | 75 // to be restarted, e.g. when the deletion preference changes state or when |
76 // we are notified of data changes. | 76 // we are notified of data changes. |
77 void Restart(); | 77 void Restart(); |
78 | 78 |
79 protected: | 79 protected: |
80 // Should be called from |Count| by any overriding class to indicate that | 80 // Should be called from |Count| by any overriding class to indicate that |
81 // counting is finished and report |value| as the result. | 81 // counting is finished and report |value| as the result. |
82 void ReportResult(ResultInt value); | 82 void ReportResult(ResultInt value); |
83 | 83 |
84 // A convenience overload of the previous method that allows subclasses to | 84 // A convenience overload of the previous method that allows subclasses to |
85 // provide a custom |result|. | 85 // provide a custom |result|. |
86 void ReportResult(std::unique_ptr<Result> result); | 86 void ReportResult(std::unique_ptr<Result> result); |
87 | 87 |
88 // Calculates the beginning of the counting period as |period_| before now. | 88 // Calculates the beginning of the counting period as |period_| before now. |
89 base::Time GetPeriodStart(); | 89 base::Time GetPeriodStart(); |
90 | 90 |
91 private: | 91 private: |
92 // Called after the class is initialized by calling |Init|. | 92 // Called after the class is initialized by calling |Init|. |
93 virtual void OnInitialized(); | 93 virtual void OnInitialized(); |
94 | 94 |
95 // Count the data. | 95 // Count the data. |
96 virtual void Count() = 0; | 96 virtual void Count() = 0; |
97 | 97 |
98 // Name of the preference associated with this counter. | |
99 const std::string pref_name_; | |
100 | |
101 // Pointer to the PrefService that manages the preferences for the user | 98 // Pointer to the PrefService that manages the preferences for the user |
102 // profile associated with this counter. | 99 // profile associated with this counter. |
103 PrefService* pref_service_; | 100 PrefService* pref_service_; |
104 | 101 |
105 // The callback that will be called when the UI should be updated with a new | 102 // The callback that will be called when the UI should be updated with a new |
106 // counter value. | 103 // counter value. |
107 Callback callback_; | 104 Callback callback_; |
108 | 105 |
109 // The boolean preference indicating whether this data type is to be deleted. | 106 // The boolean preference indicating whether this data type is to be deleted. |
110 // If false, we will not count it. | 107 // If false, we will not count it. |
111 BooleanPrefMember pref_; | 108 BooleanPrefMember pref_; |
112 | 109 |
113 // The integer preference describing the time period for which this data type | 110 // The integer preference describing the time period for which this data type |
114 // is to be deleted. | 111 // is to be deleted. |
115 IntegerPrefMember period_; | 112 IntegerPrefMember period_; |
116 | 113 |
117 // Whether this class was properly initialized by calling |Init|. | 114 // Whether this class was properly initialized by calling |Init|. |
118 bool initialized_ = false; | 115 bool initialized_ = false; |
119 }; | 116 }; |
120 | 117 |
121 } // namespace browsing_data | 118 } // namespace browsing_data |
122 | 119 |
123 #endif // COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ | 120 #endif // COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ |
OLD | NEW |