Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: components/browsing_data/counters/browsing_data_counter.h

Issue 2127403002: Make browsing_data component a layered component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed output_name from components/browsing_data/content/BUILD.gn Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_BROWSING_DATA_COUNTERS_BROWSING_DATA_COUNTER_H_
6 #define COMPONENTS_BROWSING_DATA_COUNTERS_BROWSING_DATA_COUNTER_H_
7
8 #include <stdint.h>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "components/prefs/pref_member.h"
14
15 class PrefService;
16
17 namespace browsing_data {
18
19 class BrowsingDataCounter {
20 public:
21 typedef int64_t ResultInt;
22
23 // Base class of results returned by BrowsingDataCounter. When the computation
24 // has started, an instance is returned to represent a pending result.
25 class Result {
26 public:
27 explicit Result(const BrowsingDataCounter* source);
28 virtual ~Result();
29
30 const BrowsingDataCounter* source() const { return source_; }
31 virtual bool Finished() const;
32
33 private:
34 const BrowsingDataCounter* source_;
35
36 DISALLOW_COPY_AND_ASSIGN(Result);
37 };
38
39 // A subclass of Result returned when the computation has finished. The result
40 // value can be retrieved by calling |Value()|. Some BrowsingDataCounter
41 // subclasses might use a subclass of FinishedResult to provide more complex
42 // results.
43 class FinishedResult : public Result {
44 public:
45 FinishedResult(const BrowsingDataCounter* source, ResultInt value);
46 ~FinishedResult() override;
47
48 // Result:
49 bool Finished() const override;
50
51 ResultInt Value() const;
52
53 private:
54 ResultInt value_;
55
56 DISALLOW_COPY_AND_ASSIGN(FinishedResult);
57 };
58
59 typedef base::Callback<void(std::unique_ptr<Result>)> Callback;
60
61 BrowsingDataCounter(const std::string& pref_name);
62 virtual ~BrowsingDataCounter();
63
64 // Should be called once to initialize this class.
65 void Init(PrefService* pref_service, const Callback& callback);
66
67 // Name of the preference associated with this counter.
68 const std::string& GetPrefName() const;
69
70 // PrefService that manages the preferences for the user profile
71 // associated with this counter.
72 PrefService* GetPrefs() const;
73
74 // Restarts the counter. Will be called automatically if the counting needs
75 // to be restarted, e.g. when the deletion preference changes state or when
76 // we are notified of data changes.
77 void Restart();
78
79 protected:
80 // Should be called from |Count| by any overriding class to indicate that
81 // counting is finished and report |value| as the result.
82 void ReportResult(ResultInt value);
83
84 // A convenience overload of the previous method that allows subclasses to
85 // provide a custom |result|.
86 void ReportResult(std::unique_ptr<Result> result);
87
88 // Calculates the beginning of the counting period as |period_| before now.
89 base::Time GetPeriodStart();
90
91 private:
92 // Called after the class is initialized by calling |Init|.
93 virtual void OnInitialized();
94
95 // Count the data.
96 virtual void Count() = 0;
97
98 // Name of the preference associated with this counter.
99 const std::string pref_name_;
100
101 // Pointer to the PrefService that manages the preferences for the user
102 // profile associated with this counter.
103 PrefService* pref_service_;
104
105 // The callback that will be called when the UI should be updated with a new
106 // counter value.
107 Callback callback_;
108
109 // The boolean preference indicating whether this data type is to be deleted.
110 // If false, we will not count it.
111 BooleanPrefMember pref_;
112
113 // The integer preference describing the time period for which this data type
114 // is to be deleted.
115 IntegerPrefMember period_;
116
117 // Whether this class was properly initialized by calling |Init|.
118 bool initialized_ = false;
119 };
120
121 } // namespace browsing_data
122
123 #endif // COMPONENTS_BROWSING_DATA_COUNTERS_BROWSING_DATA_COUNTER_H_
OLDNEW
« no previous file with comments | « components/browsing_data/core/pref_names.cc ('k') | components/browsing_data/counters/browsing_data_counter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698