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

Unified 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: Moved Value() to FinishedResult. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/browsing_data/browsing_data_counter.h
diff --git a/chrome/browser/browsing_data/browsing_data_counter.h b/chrome/browser/browsing_data/browsing_data_counter.h
index ba3afbd741fad06ec58a9a4c408f941766f2d176..dc9c543e6f2e75f644c6e5ce72c763a33574617d 100644
--- a/chrome/browser/browsing_data/browsing_data_counter.h
+++ b/chrome/browser/browsing_data/browsing_data_counter.h
@@ -9,14 +9,53 @@
#include <string>
#include "base/callback.h"
+#include "base/macros.h"
#include "base/prefs/pref_member.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/profiles/profile.h"
class BrowsingDataCounter {
public:
- typedef uint64_t ResultInt;
- typedef base::Callback<void(bool, ResultInt)> Callback;
+ typedef int64_t ResultInt;
+
+ // Base class of results returned by BrowsingDataCounter. When the computation
+ // has started, an instance is returned to represent a pending result. The
+ // |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
+ class Result {
+ public:
+ explicit Result(const BrowsingDataCounter* source);
+ virtual ~Result();
+
+ const BrowsingDataCounter* source() const { return source_; }
+ virtual bool Finished() const;
+
+ private:
+ const BrowsingDataCounter* source_;
+
+ DISALLOW_COPY_AND_ASSIGN(Result);
+ };
+
+ // A subclass of Result returned when the computation has finished. The result
+ // value can be retrieved by calling |Value()|. Some BrowsingDataCounter
+ // subclasses might use a subclass of FinishedResult to provide more complex
+ // results.
+ class FinishedResult : public Result {
+ public:
+ FinishedResult(const BrowsingDataCounter* source, ResultInt value);
+ ~FinishedResult() override;
+
+ // Result:
+ bool Finished() const override;
+
+ 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.
+
+ private:
+ ResultInt value_;
+
+ DISALLOW_COPY_AND_ASSIGN(FinishedResult);
+ };
+
+ typedef base::Callback<void(scoped_ptr<Result>)> Callback;
BrowsingDataCounter();
virtual ~BrowsingDataCounter();
@@ -38,8 +77,12 @@ class BrowsingDataCounter {
protected:
// Should be called from |Count| by any overriding class to indicate that
- // counting is finished and report the |result|.
- void ReportResult(ResultInt result);
+ // counting is finished and report |value| as the result.
+ void ReportResult(ResultInt value);
+
+ // A convenience overload of the previous method that allows subclasses to
+ // provide a custom |result|.
+ void ReportResult(scoped_ptr<Result> result);
// Calculates the beginning of the counting period as |period_| before now.
base::Time GetPeriodStart();

Powered by Google App Engine
This is Rietveld 408576698