| OLD | NEW |
| 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 #include "chrome/browser/browsing_data/browsing_data_counter.h" | 5 #include "chrome/browser/browsing_data/browsing_data_counter.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 10 | 10 |
| 11 BrowsingDataCounter::BrowsingDataCounter() {} | 11 BrowsingDataCounter::BrowsingDataCounter() {} |
| 12 | 12 |
| 13 BrowsingDataCounter::~BrowsingDataCounter() { | 13 BrowsingDataCounter::~BrowsingDataCounter() { |
| 14 } | 14 } |
| 15 | 15 |
| 16 void BrowsingDataCounter::Init( | 16 void BrowsingDataCounter::Init( |
| 17 Profile* profile, | 17 Profile* profile, |
| 18 const Callback& callback) { | 18 const Callback& callback) { |
| 19 DCHECK(!initialized_); | 19 DCHECK(!initialized_); |
| 20 profile_ = profile; | 20 profile_ = profile; |
| 21 callback_ = callback; | 21 callback_ = callback; |
| 22 pref_.Init( | 22 pref_.Init( |
| 23 GetPrefName(), | 23 GetPrefName(), |
| 24 profile_->GetPrefs(), | 24 profile_->GetPrefs(), |
| 25 base::Bind(&BrowsingDataCounter::RestartCounting, | 25 base::Bind(&BrowsingDataCounter::Restart, |
| 26 base::Unretained(this))); | 26 base::Unretained(this))); |
| 27 period_.Init( | 27 period_.Init( |
| 28 prefs::kDeleteTimePeriod, | 28 prefs::kDeleteTimePeriod, |
| 29 profile_->GetPrefs(), | 29 profile_->GetPrefs(), |
| 30 base::Bind(&BrowsingDataCounter::RestartCounting, | 30 base::Bind(&BrowsingDataCounter::Restart, |
| 31 base::Unretained(this))); | 31 base::Unretained(this))); |
| 32 | 32 |
| 33 initialized_ = true; | 33 initialized_ = true; |
| 34 OnInitialized(); | 34 OnInitialized(); |
| 35 RestartCounting(); | |
| 36 } | 35 } |
| 37 | 36 |
| 38 Profile* BrowsingDataCounter::GetProfile() const { | 37 Profile* BrowsingDataCounter::GetProfile() const { |
| 39 return profile_; | 38 return profile_; |
| 40 } | 39 } |
| 41 | 40 |
| 42 void BrowsingDataCounter::OnInitialized() { | 41 void BrowsingDataCounter::OnInitialized() { |
| 43 } | 42 } |
| 44 | 43 |
| 45 base::Time BrowsingDataCounter::GetPeriodStart() { | 44 base::Time BrowsingDataCounter::GetPeriodStart() { |
| 46 return BrowsingDataRemover::CalculateBeginDeleteTime( | 45 return BrowsingDataRemover::CalculateBeginDeleteTime( |
| 47 static_cast<BrowsingDataRemover::TimePeriod>(*period_)); | 46 static_cast<BrowsingDataRemover::TimePeriod>(*period_)); |
| 48 } | 47 } |
| 49 | 48 |
| 50 void BrowsingDataCounter::RestartCounting() { | 49 void BrowsingDataCounter::Restart() { |
| 51 DCHECK(initialized_); | 50 DCHECK(initialized_); |
| 52 | 51 |
| 53 // If this data type was unchecked for deletion, we do not need to count it. | 52 // If this data type was unchecked for deletion, we do not need to count it. |
| 54 if (!profile_->GetPrefs()->GetBoolean(GetPrefName())) | 53 if (!profile_->GetPrefs()->GetBoolean(GetPrefName())) |
| 55 return; | 54 return; |
| 56 | 55 |
| 57 callback_.Run(false, 0u); | 56 callback_.Run(false, 0u); |
| 58 | 57 |
| 59 Count(); | 58 Count(); |
| 60 } | 59 } |
| 61 | 60 |
| 62 void BrowsingDataCounter::ReportResult(uint32 value) { | 61 void BrowsingDataCounter::ReportResult(uint32 value) { |
| 63 DCHECK(initialized_); | 62 DCHECK(initialized_); |
| 64 callback_.Run(true, value); | 63 callback_.Run(true, value); |
| 65 } | 64 } |
| OLD | NEW |