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. The | |
| 23 // |Value()| is not valid until the counting has |Finished()|. | |
|
Bernhard Bauer
2015/11/03 14:13:46
This is a bit confusing on its own, as there is no
msramek
2015/11/03 14:54:09
Done. Weird, I thought I removed the comment alrea
| |
| 24 class Result { | |
| 25 public: | |
| 26 explicit Result(const BrowsingDataCounter* source); | |
| 27 virtual ~Result(); | |
| 28 | |
| 29 const BrowsingDataCounter* source() const { return source_; } | |
| 30 virtual bool Finished() const; | |
| 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 // Result: | |
| 48 bool Finished() const override; | |
| 49 | |
| 50 virtual ResultInt Value() const; | |
|
Bernhard Bauer
2015/11/03 14:13:46
This doesn't need to be virtual now.
msramek
2015/11/03 14:54:09
Done.
| |
| 51 | |
| 52 private: | |
| 53 ResultInt value_; | |
| 54 | |
| 55 DISALLOW_COPY_AND_ASSIGN(FinishedResult); | |
| 56 }; | |
| 57 | |
| 58 typedef base::Callback<void(scoped_ptr<Result>)> Callback; | |
| 20 | 59 |
| 21 BrowsingDataCounter(); | 60 BrowsingDataCounter(); |
| 22 virtual ~BrowsingDataCounter(); | 61 virtual ~BrowsingDataCounter(); |
| 23 | 62 |
| 24 // Should be called once to initialize this class. | 63 // Should be called once to initialize this class. |
| 25 void Init(Profile* profile, | 64 void Init(Profile* profile, |
| 26 const Callback& callback); | 65 const Callback& callback); |
| 27 | 66 |
| 28 // Name of the preference associated with this counter. | 67 // Name of the preference associated with this counter. |
| 29 virtual const std::string& GetPrefName() const = 0; | 68 virtual const std::string& GetPrefName() const = 0; |
| 30 | 69 |
| 31 // The profile associated with this counter. | 70 // The profile associated with this counter. |
| 32 Profile* GetProfile() const; | 71 Profile* GetProfile() const; |
| 33 | 72 |
| 34 // Restarts the counter. Will be called automatically if the counting needs | 73 // 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 | 74 // to be restarted, e.g. when the deletion preference changes state or when |
| 36 // we are notified of data changes. | 75 // we are notified of data changes. |
| 37 void Restart(); | 76 void Restart(); |
| 38 | 77 |
| 39 protected: | 78 protected: |
| 40 // 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 |
| 41 // counting is finished and report the |result|. | 80 // counting is finished and report |value| as the result. |
| 42 void ReportResult(ResultInt result); | 81 void ReportResult(ResultInt value); |
| 82 | |
| 83 // A convenience overload of the previous method that allows subclasses to | |
| 84 // provide a custom |result|. | |
| 85 void ReportResult(scoped_ptr<Result> result); | |
| 43 | 86 |
| 44 // Calculates the beginning of the counting period as |period_| before now. | 87 // Calculates the beginning of the counting period as |period_| before now. |
| 45 base::Time GetPeriodStart(); | 88 base::Time GetPeriodStart(); |
| 46 | 89 |
| 47 private: | 90 private: |
| 48 // Called after the class is initialized by calling |Init|. | 91 // Called after the class is initialized by calling |Init|. |
| 49 virtual void OnInitialized(); | 92 virtual void OnInitialized(); |
| 50 | 93 |
| 51 // Count the data. | 94 // Count the data. |
| 52 virtual void Count() = 0; | 95 virtual void Count() = 0; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 64 | 107 |
| 65 // The integer preference describing the time period for which this data type | 108 // The integer preference describing the time period for which this data type |
| 66 // is to be deleted. | 109 // is to be deleted. |
| 67 IntegerPrefMember period_; | 110 IntegerPrefMember period_; |
| 68 | 111 |
| 69 // Whether this class was properly initialized by calling |Init|. | 112 // Whether this class was properly initialized by calling |Init|. |
| 70 bool initialized_ = false; | 113 bool initialized_ = false; |
| 71 }; | 114 }; |
| 72 | 115 |
| 73 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ | 116 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ |
| OLD | NEW |