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