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; |
|
Bernhard Bauer
2015/11/03 10:11:19
Hm... I guess you need 64 bits? But unless you act
msramek
2015/11/03 10:55:46
I definitely need more than 32 bits, as I'm summin
| |
| 19 typedef base::Callback<void(bool, ResultInt)> Callback; | 19 |
| 20 class Result { | |
|
Bernhard Bauer
2015/11/03 10:11:20
Add a couple of comments what these classes are fo
msramek
2015/11/03 10:55:45
Done.
| |
| 21 public: | |
| 22 explicit Result(const BrowsingDataCounter* source); | |
| 23 virtual ~Result(); | |
| 24 | |
| 25 const BrowsingDataCounter* source() const { return source_; } | |
| 26 virtual bool finished() const; | |
|
Bernhard Bauer
2015/11/03 10:11:20
Use CamelCase for non-trivial methods (which inclu
msramek
2015/11/03 10:55:45
Done.
| |
| 27 virtual const ResultInt value() const; | |
|
Bernhard Bauer
2015/11/03 10:11:20
The const isn't really necessary if you return a s
msramek
2015/11/03 10:55:45
Done. It was originally a reference, I had to remo
| |
| 28 | |
| 29 private: | |
| 30 const BrowsingDataCounter* source_; | |
|
Bernhard Bauer
2015/11/03 10:11:19
DISALLOW_COPY_AND_ASSIGN (you don't want this assi
msramek
2015/11/03 10:55:45
Done. I need to get used to this.
| |
| 31 }; | |
| 32 | |
| 33 class FinishedResult : public Result { | |
| 34 public: | |
| 35 FinishedResult(const BrowsingDataCounter* source, ResultInt value); | |
| 36 ~FinishedResult() override; | |
| 37 | |
| 38 bool finished() const override; | |
| 39 const ResultInt value() const override; | |
| 40 | |
| 41 private: | |
| 42 ResultInt value_; | |
| 43 }; | |
| 44 | |
| 45 typedef base::Callback<void(scoped_ptr<Result>)> Callback; | |
| 20 | 46 |
| 21 BrowsingDataCounter(); | 47 BrowsingDataCounter(); |
| 22 virtual ~BrowsingDataCounter(); | 48 virtual ~BrowsingDataCounter(); |
| 23 | 49 |
| 24 // Should be called once to initialize this class. | 50 // Should be called once to initialize this class. |
| 25 void Init(Profile* profile, | 51 void Init(Profile* profile, |
| 26 const Callback& callback); | 52 const Callback& callback); |
| 27 | 53 |
| 28 // Name of the preference associated with this counter. | 54 // Name of the preference associated with this counter. |
| 29 virtual const std::string& GetPrefName() const = 0; | 55 virtual const std::string& GetPrefName() const = 0; |
| 30 | 56 |
| 31 // The profile associated with this counter. | 57 // The profile associated with this counter. |
| 32 Profile* GetProfile() const; | 58 Profile* GetProfile() const; |
| 33 | 59 |
| 34 // Restarts the counter. Will be called automatically if the counting needs | 60 // 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 | 61 // to be restarted, e.g. when the deletion preference changes state or when |
| 36 // we are notified of data changes. | 62 // we are notified of data changes. |
| 37 void Restart(); | 63 void Restart(); |
| 38 | 64 |
| 39 protected: | 65 protected: |
| 40 // Should be called from |Count| by any overriding class to indicate that | 66 // Should be called from |Count| by any overriding class to indicate that |
| 41 // counting is finished and report the |result|. | 67 // counting is finished and report |value| as the result. |
| 42 void ReportResult(ResultInt result); | 68 void ReportResult(ResultInt value); |
| 69 | |
| 70 // A convenience overload of the previous method that allows subclasses to | |
| 71 // provide a custom |result|. | |
| 72 void ReportResult(scoped_ptr<Result> result); | |
| 43 | 73 |
| 44 // Calculates the beginning of the counting period as |period_| before now. | 74 // Calculates the beginning of the counting period as |period_| before now. |
| 45 base::Time GetPeriodStart(); | 75 base::Time GetPeriodStart(); |
| 46 | 76 |
| 47 private: | 77 private: |
| 48 // Called after the class is initialized by calling |Init|. | 78 // Called after the class is initialized by calling |Init|. |
| 49 virtual void OnInitialized(); | 79 virtual void OnInitialized(); |
| 50 | 80 |
| 51 // Count the data. | 81 // Count the data. |
| 52 virtual void Count() = 0; | 82 virtual void Count() = 0; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 64 | 94 |
| 65 // The integer preference describing the time period for which this data type | 95 // The integer preference describing the time period for which this data type |
| 66 // is to be deleted. | 96 // is to be deleted. |
| 67 IntegerPrefMember period_; | 97 IntegerPrefMember period_; |
| 68 | 98 |
| 69 // Whether this class was properly initialized by calling |Init|. | 99 // Whether this class was properly initialized by calling |Init|. |
| 70 bool initialized_ = false; | 100 bool initialized_ = false; |
| 71 }; | 101 }; |
| 72 | 102 |
| 73 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ | 103 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ |
| OLD | NEW |