OLD | NEW |
| (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 #include "chrome/browser/browsing_data/browsing_data_counter.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/memory/ptr_util.h" | |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/common/pref_names.h" | |
12 #include "components/prefs/pref_service.h" | |
13 | |
14 BrowsingDataCounter::BrowsingDataCounter() {} | |
15 | |
16 BrowsingDataCounter::~BrowsingDataCounter() { | |
17 } | |
18 | |
19 void BrowsingDataCounter::Init( | |
20 Profile* profile, | |
21 const Callback& callback) { | |
22 DCHECK(!initialized_); | |
23 profile_ = profile; | |
24 callback_ = callback; | |
25 pref_.Init( | |
26 GetPrefName(), | |
27 profile_->GetPrefs(), | |
28 base::Bind(&BrowsingDataCounter::Restart, | |
29 base::Unretained(this))); | |
30 period_.Init( | |
31 prefs::kDeleteTimePeriod, | |
32 profile_->GetPrefs(), | |
33 base::Bind(&BrowsingDataCounter::Restart, | |
34 base::Unretained(this))); | |
35 | |
36 initialized_ = true; | |
37 OnInitialized(); | |
38 } | |
39 | |
40 Profile* BrowsingDataCounter::GetProfile() const { | |
41 return profile_; | |
42 } | |
43 | |
44 void BrowsingDataCounter::OnInitialized() { | |
45 } | |
46 | |
47 base::Time BrowsingDataCounter::GetPeriodStart() { | |
48 return BrowsingDataRemover::CalculateBeginDeleteTime( | |
49 static_cast<BrowsingDataRemover::TimePeriod>(*period_)); | |
50 } | |
51 | |
52 void BrowsingDataCounter::Restart() { | |
53 DCHECK(initialized_); | |
54 | |
55 // If this data type was unchecked for deletion, we do not need to count it. | |
56 if (!profile_->GetPrefs()->GetBoolean(GetPrefName())) | |
57 return; | |
58 | |
59 callback_.Run(base::WrapUnique(new Result(this))); | |
60 | |
61 Count(); | |
62 } | |
63 | |
64 void BrowsingDataCounter::ReportResult(ResultInt value) { | |
65 DCHECK(initialized_); | |
66 callback_.Run(base::WrapUnique(new FinishedResult(this, value))); | |
67 } | |
68 | |
69 void BrowsingDataCounter::ReportResult(std::unique_ptr<Result> result) { | |
70 DCHECK(initialized_); | |
71 callback_.Run(std::move(result)); | |
72 } | |
73 | |
74 // BrowsingDataCounter::Result ------------------------------------------------- | |
75 | |
76 BrowsingDataCounter::Result::Result(const BrowsingDataCounter* source) | |
77 : source_(source) { | |
78 } | |
79 | |
80 BrowsingDataCounter::Result::~Result() { | |
81 } | |
82 | |
83 bool BrowsingDataCounter::Result::Finished() const { | |
84 return false; | |
85 } | |
86 | |
87 // BrowsingDataCounter::FinishedResult ----------------------------------------- | |
88 | |
89 BrowsingDataCounter::FinishedResult::FinishedResult( | |
90 const BrowsingDataCounter* source, ResultInt value) | |
91 : Result(source), | |
92 value_(value) { | |
93 } | |
94 | |
95 BrowsingDataCounter::FinishedResult::~FinishedResult() { | |
96 } | |
97 | |
98 bool BrowsingDataCounter::FinishedResult::Finished() const { | |
99 return true; | |
100 } | |
101 | |
102 BrowsingDataCounter::ResultInt | |
103 BrowsingDataCounter::FinishedResult::Value() const { | |
104 return value_; | |
105 } | |
OLD | NEW |