OLD | NEW |
1 // Copyright (c) 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_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ | 5 #ifndef COMPONENTS_BROWSING_DATA_COUNTERS_BROWSING_DATA_COUNTER_H_ |
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ | 6 #define COMPONENTS_BROWSING_DATA_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 "chrome/browser/browsing_data/browsing_data_remover.h" | |
14 #include "chrome/browser/profiles/profile.h" | |
15 #include "components/prefs/pref_member.h" | 13 #include "components/prefs/pref_member.h" |
16 | 14 |
| 15 class PrefService; |
| 16 |
| 17 namespace browsing_data { |
| 18 |
17 class BrowsingDataCounter { | 19 class BrowsingDataCounter { |
18 public: | 20 public: |
19 typedef int64_t ResultInt; | 21 typedef int64_t ResultInt; |
20 | 22 |
21 // Base class of results returned by BrowsingDataCounter. When the computation | 23 // Base class of results returned by BrowsingDataCounter. When the computation |
22 // has started, an instance is returned to represent a pending result. | 24 // has started, an instance is returned to represent a pending result. |
23 class Result { | 25 class Result { |
24 public: | 26 public: |
25 explicit Result(const BrowsingDataCounter* source); | 27 explicit Result(const BrowsingDataCounter* source); |
26 virtual ~Result(); | 28 virtual ~Result(); |
(...skipping 22 matching lines...) Expand all Loading... |
49 ResultInt Value() const; | 51 ResultInt Value() const; |
50 | 52 |
51 private: | 53 private: |
52 ResultInt value_; | 54 ResultInt value_; |
53 | 55 |
54 DISALLOW_COPY_AND_ASSIGN(FinishedResult); | 56 DISALLOW_COPY_AND_ASSIGN(FinishedResult); |
55 }; | 57 }; |
56 | 58 |
57 typedef base::Callback<void(std::unique_ptr<Result>)> Callback; | 59 typedef base::Callback<void(std::unique_ptr<Result>)> Callback; |
58 | 60 |
59 BrowsingDataCounter(); | 61 BrowsingDataCounter(const std::string& pref_name); |
60 virtual ~BrowsingDataCounter(); | 62 virtual ~BrowsingDataCounter(); |
61 | 63 |
62 // Should be called once to initialize this class. | 64 // Should be called once to initialize this class. |
63 void Init(Profile* profile, | 65 void Init(PrefService* pref_service, const Callback& callback); |
64 const Callback& callback); | |
65 | 66 |
66 // Name of the preference associated with this counter. | 67 // Name of the preference associated with this counter. |
67 virtual const std::string& GetPrefName() const = 0; | 68 const std::string& GetPrefName() const; |
68 | 69 |
69 // The profile associated with this counter. | 70 // PrefService that manages the preferences for the user profile |
70 Profile* GetProfile() const; | 71 // associated with this counter. |
| 72 PrefService* GetPrefs() const; |
71 | 73 |
72 // Restarts the counter. Will be called automatically if the counting needs | 74 // Restarts the counter. Will be called automatically if the counting needs |
73 // 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 |
74 // we are notified of data changes. | 76 // we are notified of data changes. |
75 void Restart(); | 77 void Restart(); |
76 | 78 |
77 protected: | 79 protected: |
78 // 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 |
79 // counting is finished and report |value| as the result. | 81 // counting is finished and report |value| as the result. |
80 void ReportResult(ResultInt value); | 82 void ReportResult(ResultInt value); |
81 | 83 |
82 // A convenience overload of the previous method that allows subclasses to | 84 // A convenience overload of the previous method that allows subclasses to |
83 // provide a custom |result|. | 85 // provide a custom |result|. |
84 void ReportResult(std::unique_ptr<Result> result); | 86 void ReportResult(std::unique_ptr<Result> result); |
85 | 87 |
86 // Calculates the beginning of the counting period as |period_| before now. | 88 // Calculates the beginning of the counting period as |period_| before now. |
87 base::Time GetPeriodStart(); | 89 base::Time GetPeriodStart(); |
88 | 90 |
89 private: | 91 private: |
90 // Called after the class is initialized by calling |Init|. | 92 // Called after the class is initialized by calling |Init|. |
91 virtual void OnInitialized(); | 93 virtual void OnInitialized(); |
92 | 94 |
93 // Count the data. | 95 // Count the data. |
94 virtual void Count() = 0; | 96 virtual void Count() = 0; |
95 | 97 |
96 // The profile for which we will count the data volume. | 98 // Name of the preference associated with this counter. |
97 Profile* profile_; | 99 const std::string pref_name_; |
| 100 |
| 101 // Pointer to the PrefService that manages the preferences for the user |
| 102 // profile associated with this counter. |
| 103 PrefService* pref_service_; |
98 | 104 |
99 // The callback that will be called when the UI should be updated with a new | 105 // The callback that will be called when the UI should be updated with a new |
100 // counter value. | 106 // counter value. |
101 Callback callback_; | 107 Callback callback_; |
102 | 108 |
103 // The boolean preference indicating whether this data type is to be deleted. | 109 // The boolean preference indicating whether this data type is to be deleted. |
104 // If false, we will not count it. | 110 // If false, we will not count it. |
105 BooleanPrefMember pref_; | 111 BooleanPrefMember pref_; |
106 | 112 |
107 // The integer preference describing the time period for which this data type | 113 // The integer preference describing the time period for which this data type |
108 // is to be deleted. | 114 // is to be deleted. |
109 IntegerPrefMember period_; | 115 IntegerPrefMember period_; |
110 | 116 |
111 // Whether this class was properly initialized by calling |Init|. | 117 // Whether this class was properly initialized by calling |Init|. |
112 bool initialized_ = false; | 118 bool initialized_ = false; |
113 }; | 119 }; |
114 | 120 |
115 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ | 121 } // namespace browsing_data |
| 122 |
| 123 #endif // COMPONENTS_BROWSING_DATA_COUNTERS_BROWSING_DATA_COUNTER_H_ |
OLD | NEW |