Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ |
| 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_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/prefs/pref_member.h" | 12 #include "base/prefs/pref_member.h" |
| 13 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 13 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 | 15 |
| 16 class BrowsingDataCounter { | 16 class BrowsingDataCounter { |
| 17 public: | 17 public: |
| 18 typedef uint64_t ResultInt; | 18 typedef uint64_t ResultInt; |
| 19 typedef base::Callback<void(bool, ResultInt)> Callback; | 19 |
| 20 class Result { | |
| 21 public: | |
| 22 Result(const BrowsingDataCounter* source, bool finished, ResultInt value); | |
|
Bernhard Bauer
2015/11/02 16:15:27
Do you want someone to construct object of this cl
msramek
2015/11/02 20:54:05
That is what I also did originally, I just didn't
| |
| 23 ~Result(); | |
| 24 | |
| 25 const BrowsingDataCounter* source() const { return source_; } | |
| 26 bool finished() const { return finished_; } | |
| 27 const ResultInt& value() const { return value_; } | |
| 28 | |
| 29 private: | |
| 30 const BrowsingDataCounter* source_; | |
| 31 bool finished_; | |
|
Bernhard Bauer
2015/11/02 16:15:27
Hm... seeing as we have this class structure now,
msramek
2015/11/02 20:54:06
Yes! Done.
| |
| 32 ResultInt value_; | |
| 33 }; | |
| 34 | |
| 35 class FinishedResult : public Result { | |
| 36 public: | |
| 37 FinishedResult(const BrowsingDataCounter* source, ResultInt value); | |
| 38 ~FinishedResult(); | |
| 39 }; | |
| 40 | |
| 41 typedef base::Callback<void(scoped_ptr<Result>)> Callback; | |
| 20 | 42 |
| 21 BrowsingDataCounter(); | 43 BrowsingDataCounter(); |
| 22 virtual ~BrowsingDataCounter(); | 44 virtual ~BrowsingDataCounter(); |
| 23 | 45 |
| 24 // Should be called once to initialize this class. | 46 // Should be called once to initialize this class. |
| 25 void Init(Profile* profile, | 47 void Init(Profile* profile, |
| 26 const Callback& callback); | 48 const Callback& callback); |
| 27 | 49 |
| 28 // Name of the preference associated with this counter. | 50 // Name of the preference associated with this counter. |
| 29 virtual const std::string& GetPrefName() const = 0; | 51 virtual const std::string& GetPrefName() const = 0; |
| 30 | 52 |
| 31 // The profile associated with this counter. | 53 // The profile associated with this counter. |
| 32 Profile* GetProfile() const; | 54 Profile* GetProfile() const; |
| 33 | 55 |
| 34 // Restarts the counter. Will be called automatically if the counting needs | 56 // Restarts the counter. Will be called automatically if the counting needs |
| 35 // to be restarted, e.g. when the deletion preference changes state or when | 57 // to be restarted, e.g. when the deletion preference changes state or when |
| 36 // we are notified of data changes. | 58 // we are notified of data changes. |
| 37 void Restart(); | 59 void Restart(); |
| 38 | 60 |
| 39 protected: | 61 protected: |
| 40 // Should be called from |Count| by any overriding class to indicate that | 62 // Should be called from |Count| by any overriding class to indicate that |
| 41 // counting is finished and report the |result|. | 63 // counting is finished and report |value| as the result. |
| 42 void ReportResult(ResultInt result); | 64 void ReportResult(ResultInt value); |
| 65 | |
| 66 // A convenience overload of the previous method that allows subclasses to | |
| 67 // provide a custom |result|. | |
| 68 void ReportResult(scoped_ptr<Result> result); | |
| 43 | 69 |
| 44 // Calculates the beginning of the counting period as |period_| before now. | 70 // Calculates the beginning of the counting period as |period_| before now. |
| 45 base::Time GetPeriodStart(); | 71 base::Time GetPeriodStart(); |
| 46 | 72 |
| 47 private: | 73 private: |
| 74 class PendingResult : public Result { | |
| 75 public: | |
| 76 explicit PendingResult(const BrowsingDataCounter* source); | |
| 77 ~PendingResult(); | |
| 78 }; | |
| 79 | |
| 48 // Called after the class is initialized by calling |Init|. | 80 // Called after the class is initialized by calling |Init|. |
| 49 virtual void OnInitialized(); | 81 virtual void OnInitialized(); |
| 50 | 82 |
| 51 // Count the data. | 83 // Count the data. |
| 52 virtual void Count() = 0; | 84 virtual void Count() = 0; |
| 53 | 85 |
| 54 // The profile for which we will count the data volume. | 86 // The profile for which we will count the data volume. |
| 55 Profile* profile_; | 87 Profile* profile_; |
| 56 | 88 |
| 57 // The callback that will be called when the UI should be updated with a new | 89 // The callback that will be called when the UI should be updated with a new |
| 58 // counter value. | 90 // counter value. |
| 59 Callback callback_; | 91 Callback callback_; |
| 60 | 92 |
| 61 // The boolean preference indicating whether this data type is to be deleted. | 93 // The boolean preference indicating whether this data type is to be deleted. |
| 62 // If false, we will not count it. | 94 // If false, we will not count it. |
| 63 BooleanPrefMember pref_; | 95 BooleanPrefMember pref_; |
| 64 | 96 |
| 65 // The integer preference describing the time period for which this data type | 97 // The integer preference describing the time period for which this data type |
| 66 // is to be deleted. | 98 // is to be deleted. |
| 67 IntegerPrefMember period_; | 99 IntegerPrefMember period_; |
| 68 | 100 |
| 69 // Whether this class was properly initialized by calling |Init|. | 101 // Whether this class was properly initialized by calling |Init|. |
| 70 bool initialized_ = false; | 102 bool initialized_ = false; |
| 71 }; | 103 }; |
| 72 | 104 |
| 73 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ | 105 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ |
| OLD | NEW |