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