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

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

Issue 1420013004: Polish the result communication and display of the browsing data counters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 5 years, 1 month 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
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
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(scoped_ptr<Result>)> Callback;
20 58
21 BrowsingDataCounter(); 59 BrowsingDataCounter();
22 virtual ~BrowsingDataCounter(); 60 virtual ~BrowsingDataCounter();
23 61
24 // Should be called once to initialize this class. 62 // Should be called once to initialize this class.
25 void Init(Profile* profile, 63 void Init(Profile* profile,
26 const Callback& callback); 64 const Callback& callback);
27 65
28 // Name of the preference associated with this counter. 66 // Name of the preference associated with this counter.
29 virtual const std::string& GetPrefName() const = 0; 67 virtual const std::string& GetPrefName() const = 0;
30 68
31 // The profile associated with this counter. 69 // The profile associated with this counter.
32 Profile* GetProfile() const; 70 Profile* GetProfile() const;
33 71
34 // Restarts the counter. Will be called automatically if the counting needs 72 // 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 73 // to be restarted, e.g. when the deletion preference changes state or when
36 // we are notified of data changes. 74 // we are notified of data changes.
37 void Restart(); 75 void Restart();
38 76
39 protected: 77 protected:
40 // Should be called from |Count| by any overriding class to indicate that 78 // Should be called from |Count| by any overriding class to indicate that
41 // counting is finished and report the |result|. 79 // counting is finished and report |value| as the result.
42 void ReportResult(ResultInt 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(scoped_ptr<Result> result);
43 85
44 // Calculates the beginning of the counting period as |period_| before now. 86 // Calculates the beginning of the counting period as |period_| before now.
45 base::Time GetPeriodStart(); 87 base::Time GetPeriodStart();
46 88
47 private: 89 private:
48 // Called after the class is initialized by calling |Init|. 90 // Called after the class is initialized by calling |Init|.
49 virtual void OnInitialized(); 91 virtual void OnInitialized();
50 92
51 // Count the data. 93 // Count the data.
52 virtual void Count() = 0; 94 virtual void Count() = 0;
(...skipping 11 matching lines...) Expand all
64 106
65 // The integer preference describing the time period for which this data type 107 // The integer preference describing the time period for which this data type
66 // is to be deleted. 108 // is to be deleted.
67 IntegerPrefMember period_; 109 IntegerPrefMember period_;
68 110
69 // Whether this class was properly initialized by calling |Init|. 111 // Whether this class was properly initialized by calling |Init|.
70 bool initialized_ = false; 112 bool initialized_ = false;
71 }; 113 };
72 114
73 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_ 115 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_H_
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/browsing_data/browsing_data_counter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698