Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_counter.cc
blob7464bc8973fdfe0d119b2189df2b9f6d3aef1c22
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.
5 #include "chrome/browser/browsing_data/browsing_data_counter.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/pref_names.h"
11 BrowsingDataCounter::BrowsingDataCounter() {}
13 BrowsingDataCounter::~BrowsingDataCounter() {
16 void BrowsingDataCounter::Init(
17 Profile* profile,
18 const Callback& callback) {
19 DCHECK(!initialized_);
20 profile_ = profile;
21 callback_ = callback;
22 pref_.Init(
23 GetPrefName(),
24 profile_->GetPrefs(),
25 base::Bind(&BrowsingDataCounter::Restart,
26 base::Unretained(this)));
27 period_.Init(
28 prefs::kDeleteTimePeriod,
29 profile_->GetPrefs(),
30 base::Bind(&BrowsingDataCounter::Restart,
31 base::Unretained(this)));
33 initialized_ = true;
34 OnInitialized();
37 Profile* BrowsingDataCounter::GetProfile() const {
38 return profile_;
41 void BrowsingDataCounter::OnInitialized() {
44 base::Time BrowsingDataCounter::GetPeriodStart() {
45 return BrowsingDataRemover::CalculateBeginDeleteTime(
46 static_cast<BrowsingDataRemover::TimePeriod>(*period_));
49 void BrowsingDataCounter::Restart() {
50 DCHECK(initialized_);
52 // If this data type was unchecked for deletion, we do not need to count it.
53 if (!profile_->GetPrefs()->GetBoolean(GetPrefName()))
54 return;
56 callback_.Run(false, 0u);
58 Count();
61 void BrowsingDataCounter::ReportResult(uint32 value) {
62 DCHECK(initialized_);
63 callback_.Run(true, value);