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

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

Issue 2084903002: Moved BrowsingDataCounter and part of BrowsingDataCounterUtils to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed deps Created 4 years, 6 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) 2016 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 #include "components/browsing_data/counters/browsing_data_counter.h"
6
7 #include <utility>
8
9 #include "base/memory/ptr_util.h"
10 #include "components/browsing_data/browsing_data_utils.h"
11
12 BrowsingDataCounter::BrowsingDataCounter(const std::string& pref_name)
13 : pref_name_(pref_name) {}
14
15 BrowsingDataCounter::~BrowsingDataCounter() {}
16
17 void BrowsingDataCounter::Init(PrefService* pref_service,
18 const std::string& delete_time_period_pref,
19 const Callback& callback) {
20 DCHECK(!initialized_);
21 callback_ = callback;
22 pref_service_ = pref_service;
23 pref_.Init(GetPrefName(), pref_service_,
24 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this)));
25 period_.Init(
26 delete_time_period_pref, pref_service_,
27 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this)));
28
29 initialized_ = true;
30 OnInitialized();
31 }
32
33 void BrowsingDataCounter::OnInitialized() {}
34
35 base::Time BrowsingDataCounter::GetPeriodStart() {
36 return CalculateBeginDeleteTime(static_cast<TimePeriod>(*period_));
37 }
38
39 void BrowsingDataCounter::Restart() {
40 DCHECK(initialized_);
41
42 // If this data type was unchecked for deletion, we do not need to count it.
43 if (!pref_service_->GetBoolean(GetPrefName()))
44 return;
45
46 callback_.Run(base::WrapUnique(new Result(this)));
47
48 Count();
49 }
50
51 void BrowsingDataCounter::ReportResult(ResultInt value) {
52 DCHECK(initialized_);
53 callback_.Run(base::WrapUnique(new FinishedResult(this, value)));
54 }
55
56 void BrowsingDataCounter::ReportResult(std::unique_ptr<Result> result) {
57 DCHECK(initialized_);
58 callback_.Run(std::move(result));
59 }
60
61 const std::string& BrowsingDataCounter::GetPrefName() const {
62 return pref_name_;
63 }
64
65 PrefService* BrowsingDataCounter::GetPrefs() const {
66 return pref_service_;
67 }
68
69 // BrowsingDataCounter::Result -------------------------------------------------
70
71 BrowsingDataCounter::Result::Result(const BrowsingDataCounter* source)
72 : source_(source) {}
73
74 BrowsingDataCounter::Result::~Result() {}
75
76 bool BrowsingDataCounter::Result::Finished() const {
77 return false;
78 }
79
80 // BrowsingDataCounter::FinishedResult -----------------------------------------
81
82 BrowsingDataCounter::FinishedResult::FinishedResult(
83 const BrowsingDataCounter* source,
84 ResultInt value)
85 : Result(source), value_(value) {}
86
87 BrowsingDataCounter::FinishedResult::~FinishedResult() {}
88
89 bool BrowsingDataCounter::FinishedResult::Finished() const {
90 return true;
91 }
92
93 BrowsingDataCounter::ResultInt BrowsingDataCounter::FinishedResult::Value()
94 const {
95 return value_;
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698