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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_counter.h

Issue 2084903002: Moved BrowsingDataCounter and part of BrowsingDataCounterUtils to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 (c) 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 CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_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 "chrome/browser/browsing_data/browsing_data_remover.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "components/prefs/pref_member.h"
16
17 class BrowsingDataCounter {
18 public:
19 typedef int64_t ResultInt;
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
31 private:
32 const BrowsingDataCounter* source_;
33
34 DISALLOW_COPY_AND_ASSIGN(Result);
35 };
36
37 // A subclass of Result returned when the computation has finished. The result
38 // value can be retrieved by calling |Value()|. Some BrowsingDataCounter
39 // subclasses might use a subclass of FinishedResult to provide more complex
40 // results.
41 class FinishedResult : public Result {
42 public:
43 FinishedResult(const BrowsingDataCounter* source, ResultInt value);
44 ~FinishedResult() override;
45
46 // Result:
47 bool Finished() const override;
48
49 ResultInt Value() const;
50
51 private:
52 ResultInt value_;
53
54 DISALLOW_COPY_AND_ASSIGN(FinishedResult);
55 };
56
57 typedef base::Callback<void(std::unique_ptr<Result>)> Callback;
58
59 BrowsingDataCounter();
60 virtual ~BrowsingDataCounter();
61
62 // Should be called once to initialize this class.
63 void Init(Profile* profile,
64 const Callback& callback);
65
66 // Name of the preference associated with this counter.
67 virtual const std::string& GetPrefName() const = 0;
68
69 // The profile associated with this counter.
70 Profile* GetProfile() const;
71
72 // Restarts the counter. Will be called automatically if the counting needs
73 // to be restarted, e.g. when the deletion preference changes state or when
74 // we are notified of data changes.
75 void Restart();
76
77 protected:
78 // Should be called from |Count| by any overriding class to indicate that
79 // counting is finished and report |value| as the result.
80 void ReportResult(ResultInt value);
81
82 // A convenience overload of the previous method that allows subclasses to
83 // provide a custom |result|.
84 void ReportResult(std::unique_ptr<Result> result);
85
86 // Calculates the beginning of the counting period as |period_| before now.
87 base::Time GetPeriodStart();
88
89 private:
90 // Called after the class is initialized by calling |Init|.
91 virtual void OnInitialized();
92
93 // Count the data.
94 virtual void Count() = 0;
95
96 // The profile for which we will count the data volume.
97 Profile* profile_;
98
99 // The callback that will be called when the UI should be updated with a new
100 // counter value.
101 Callback callback_;
102
103 // The boolean preference indicating whether this data type is to be deleted.
104 // If false, we will not count it.
105 BooleanPrefMember pref_;
106
107 // The integer preference describing the time period for which this data type
108 // is to be deleted.
109 IntegerPrefMember period_;
110
111 // Whether this class was properly initialized by calling |Init|.
112 bool initialized_ = false;
113 };
114
115 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/autofill_counter_browsertest.cc ('k') | chrome/browser/browsing_data/browsing_data_counter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698