| 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 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 16 #include "components/browsing_data/core/clear_browsing_data_tab.h" |
| 16 #include "components/prefs/pref_member.h" | 17 #include "components/prefs/pref_member.h" |
| 17 | 18 |
| 18 class PrefService; | 19 class PrefService; |
| 19 | 20 |
| 20 namespace browsing_data { | 21 namespace browsing_data { |
| 21 | 22 |
| 22 class BrowsingDataCounter { | 23 class BrowsingDataCounter { |
| 23 public: | 24 public: |
| 24 typedef int64_t ResultInt; | 25 typedef int64_t ResultInt; |
| 25 | 26 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 RESTARTED, | 79 RESTARTED, |
| 79 SHOW_CALCULATING, | 80 SHOW_CALCULATING, |
| 80 REPORT_STAGED_RESULT, | 81 REPORT_STAGED_RESULT, |
| 81 READY_TO_REPORT_RESULT, | 82 READY_TO_REPORT_RESULT, |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 BrowsingDataCounter(); | 85 BrowsingDataCounter(); |
| 85 virtual ~BrowsingDataCounter(); | 86 virtual ~BrowsingDataCounter(); |
| 86 | 87 |
| 87 // Should be called once to initialize this class. | 88 // Should be called once to initialize this class. |
| 88 void Init(PrefService* pref_service, const Callback& callback); | 89 void Init(PrefService* pref_service, |
| 90 ClearBrowsingDataTab clear_browsing_data_tab, |
| 91 const Callback& callback); |
| 89 | 92 |
| 90 // Name of the preference associated with this counter. | 93 // Name of the preference associated with this counter. |
| 91 virtual const char* GetPrefName() const = 0; | 94 virtual const char* GetPrefName() const = 0; |
| 92 | 95 |
| 93 // PrefService that manages the preferences for the user profile | |
| 94 // associated with this counter. | |
| 95 PrefService* GetPrefs() const; | |
| 96 | |
| 97 // Restarts the counter. Will be called automatically if the counting needs | 96 // Restarts the counter. Will be called automatically if the counting needs |
| 98 // to be restarted, e.g. when the deletion preference changes state or when | 97 // to be restarted, e.g. when the deletion preference changes state or when |
| 99 // we are notified of data changes. | 98 // we are notified of data changes. |
| 100 void Restart(); | 99 void Restart(); |
| 101 | 100 |
| 102 // Returns the state transition of this counter since past restart. | 101 // Returns the state transition of this counter since past restart. |
| 103 // Used only for testing. | 102 // Used only for testing. |
| 104 const std::vector<State>& GetStateTransitionsForTesting(); | 103 const std::vector<State>& GetStateTransitionsForTesting(); |
| 105 | 104 |
| 106 protected: | 105 protected: |
| 107 // Should be called from |Count| by any overriding class to indicate that | 106 // Should be called from |Count| by any overriding class to indicate that |
| 108 // counting is finished and report |value| as the result. | 107 // counting is finished and report |value| as the result. |
| 109 void ReportResult(ResultInt value); | 108 void ReportResult(ResultInt value); |
| 110 | 109 |
| 111 // A convenience overload of the previous method that allows subclasses to | 110 // A convenience overload of the previous method that allows subclasses to |
| 112 // provide a custom |result|. | 111 // provide a custom |result|. |
| 113 void ReportResult(std::unique_ptr<Result> result); | 112 void ReportResult(std::unique_ptr<Result> result); |
| 114 | 113 |
| 115 // A synchronous implementation of ReportResult(). Called immediately in the | 114 // A synchronous implementation of ReportResult(). Called immediately in the |
| 116 // RESTARTED and READY_TO_REPORT_RESULT states, called later if the counter is | 115 // RESTARTED and READY_TO_REPORT_RESULT states, called later if the counter is |
| 117 // in the SHOW_CALCULATING stage. This method is made virtual to be overriden | 116 // in the SHOW_CALCULATING stage. This method is made virtual to be overriden |
| 118 // in tests. | 117 // in tests. |
| 119 virtual void DoReportResult(std::unique_ptr<Result> result); | 118 virtual void DoReportResult(std::unique_ptr<Result> result); |
| 120 | 119 |
| 121 // Calculates the beginning of the counting period as |period_| before now. | 120 // Calculates the beginning of the counting period as |period_| before now. |
| 122 base::Time GetPeriodStart(); | 121 base::Time GetPeriodStart(); |
| 123 | 122 |
| 123 // Returns if this counter belongs to a preference on the default, basic or |
| 124 // advanced CBD tab. |
| 125 ClearBrowsingDataTab GetTab() const; |
| 126 |
| 124 private: | 127 private: |
| 125 // Called after the class is initialized by calling |Init|. | 128 // Called after the class is initialized by calling |Init|. |
| 126 virtual void OnInitialized(); | 129 virtual void OnInitialized(); |
| 127 | 130 |
| 128 // Count the data. | 131 // Count the data. |
| 129 virtual void Count() = 0; | 132 virtual void Count() = 0; |
| 130 | 133 |
| 131 // State transition methods. | 134 // State transition methods. |
| 132 void TransitionToShowCalculating(); | 135 void TransitionToShowCalculating(); |
| 133 void TransitionToReadyToReportResult(); | 136 void TransitionToReadyToReportResult(); |
| 134 | 137 |
| 135 // Pointer to the PrefService that manages the preferences for the user | 138 // Indicates if this counter belongs to a preference on the basic CBD tab. |
| 136 // profile associated with this counter. | 139 ClearBrowsingDataTab clear_browsing_data_tab_; |
| 137 PrefService* pref_service_; | |
| 138 | 140 |
| 139 // The callback that will be called when the UI should be updated with a new | 141 // The callback that will be called when the UI should be updated with a new |
| 140 // counter value. | 142 // counter value. |
| 141 Callback callback_; | 143 Callback callback_; |
| 142 | 144 |
| 143 // The boolean preference indicating whether this data type is to be deleted. | 145 // The boolean preference indicating whether this data type is to be deleted. |
| 144 // If false, we will not count it. | 146 // If false, we will not count it. |
| 145 BooleanPrefMember pref_; | 147 BooleanPrefMember pref_; |
| 146 | 148 |
| 147 // The integer preference describing the time period for which this data type | 149 // The integer preference describing the time period for which this data type |
| (...skipping 13 matching lines...) Expand all Loading... |
| 161 std::unique_ptr<Result> staged_result_; | 163 std::unique_ptr<Result> staged_result_; |
| 162 | 164 |
| 163 // A timer to time the RESTARTED->SHOW_CALCULATION and | 165 // A timer to time the RESTARTED->SHOW_CALCULATION and |
| 164 // SHOW_CALCULATION->READY_TO_REPORT_RESULT state transitions. | 166 // SHOW_CALCULATION->READY_TO_REPORT_RESULT state transitions. |
| 165 base::OneShotTimer timer_; | 167 base::OneShotTimer timer_; |
| 166 }; | 168 }; |
| 167 | 169 |
| 168 } // namespace browsing_data | 170 } // namespace browsing_data |
| 169 | 171 |
| 170 #endif // COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ | 172 #endif // COMPONENTS_BROWSING_DATA_CORE_COUNTERS_BROWSING_DATA_COUNTER_H_ |
| OLD | NEW |