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/macros.h" | |
| 12 #include "base/prefs/pref_member.h" | 13 #include "base/prefs/pref_member.h" |
| 13 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 14 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 | 16 |
| 16 class BrowsingDataCounter { | 17 class BrowsingDataCounter { |
| 17 public: | 18 public: |
| 18 typedef uint64_t ResultInt; | 19 typedef int64_t ResultInt; |
| 19 typedef base::Callback<void(bool, ResultInt)> Callback; | 20 |
| 21 // Base class of results returned by BrowsingDataCounter. When the computation | |
| 22 // has started, an instance is returned to represent a pending result. | |
| 23 class Result { | |
| 24 public: | |
| 25 explicit Result(const BrowsingDataCounter* source); | |
| 26 virtual ~Result(); | |
| 27 | |
| 28 const BrowsingDataCounter* source() const { return source_; } | |
| 29 virtual bool Finished() const; | |
| 30 virtual ResultInt Value() const; | |
|
Bernhard Bauer
2015/11/03 11:37:02
Add a comment that this method should only be call
msramek
2015/11/03 11:57:06
Done.
| |
| 31 | |
| 32 private: | |
| 33 const BrowsingDataCounter* source_; | |
| 34 | |
| 35 DISALLOW_COPY_AND_ASSIGN(Result); | |
| 36 }; | |
| 37 | |
| 38 // A subclass of Result returned when the computation has finished. The result | |
| 39 // value can be retrieved by calling |Value()|. Some BrowsingDataCounter | |
| 40 // subclasses might use a subclass of FinishedResult to provide more complex | |
| 41 // results. | |
| 42 class FinishedResult : public Result { | |
| 43 public: | |
| 44 FinishedResult(const BrowsingDataCounter* source, ResultInt value); | |
| 45 ~FinishedResult() override; | |
| 46 | |
| 47 bool Finished() const override; | |
| 48 ResultInt Value() const override; | |
| 49 | |
| 50 private: | |
| 51 ResultInt value_; | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(FinishedResult); | |
| 54 }; | |
| 55 | |
| 56 typedef base::Callback<void(scoped_ptr<Result>)> Callback; | |
| 20 | 57 |
| 21 BrowsingDataCounter(); | 58 BrowsingDataCounter(); |
| 22 virtual ~BrowsingDataCounter(); | 59 virtual ~BrowsingDataCounter(); |
| 23 | 60 |
| 24 // Should be called once to initialize this class. | 61 // Should be called once to initialize this class. |
| 25 void Init(Profile* profile, | 62 void Init(Profile* profile, |
| 26 const Callback& callback); | 63 const Callback& callback); |
| 27 | 64 |
| 28 // Name of the preference associated with this counter. | 65 // Name of the preference associated with this counter. |
| 29 virtual const std::string& GetPrefName() const = 0; | 66 virtual const std::string& GetPrefName() const = 0; |
| 30 | 67 |
| 31 // The profile associated with this counter. | 68 // The profile associated with this counter. |
| 32 Profile* GetProfile() const; | 69 Profile* GetProfile() const; |
| 33 | 70 |
| 34 // Restarts the counter. Will be called automatically if the counting needs | 71 // 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 | 72 // to be restarted, e.g. when the deletion preference changes state or when |
| 36 // we are notified of data changes. | 73 // we are notified of data changes. |
| 37 void Restart(); | 74 void Restart(); |
| 38 | 75 |
| 39 protected: | 76 protected: |
| 40 // Should be called from |Count| by any overriding class to indicate that | 77 // Should be called from |Count| by any overriding class to indicate that |
| 41 // counting is finished and report the |result|. | 78 // counting is finished and report |value| as the result. |
| 42 void ReportResult(ResultInt result); | 79 void ReportResult(ResultInt value); |
| 80 | |
| 81 // A convenience overload of the previous method that allows subclasses to | |
| 82 // provide a custom |result|. | |
| 83 void ReportResult(scoped_ptr<Result> result); | |
| 43 | 84 |
| 44 // Calculates the beginning of the counting period as |period_| before now. | 85 // Calculates the beginning of the counting period as |period_| before now. |
| 45 base::Time GetPeriodStart(); | 86 base::Time GetPeriodStart(); |
| 46 | 87 |
| 47 private: | 88 private: |
| 48 // Called after the class is initialized by calling |Init|. | 89 // Called after the class is initialized by calling |Init|. |
| 49 virtual void OnInitialized(); | 90 virtual void OnInitialized(); |
| 50 | 91 |
| 51 // Count the data. | 92 // Count the data. |
| 52 virtual void Count() = 0; | 93 virtual void Count() = 0; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 64 | 105 |
| 65 // The integer preference describing the time period for which this data type | 106 // The integer preference describing the time period for which this data type |
| 66 // is to be deleted. | 107 // is to be deleted. |
| 67 IntegerPrefMember period_; | 108 IntegerPrefMember period_; |
| 68 | 109 |
| 69 // Whether this class was properly initialized by calling |Init|. | 110 // Whether this class was properly initialized by calling |Init|. |
| 70 bool initialized_ = false; | 111 bool initialized_ = false; |
| 71 }; | 112 }; |
| 72 | 113 |
| 73 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ | 114 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ |
| OLD | NEW |