Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/browsing_data/core/counters/browsing_data_counter.h" | 5 #include "components/browsing_data/core/counters/browsing_data_counter.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/browsing_data/core/browsing_data_utils.h" | 10 #include "components/browsing_data/core/browsing_data_utils.h" |
| 11 #include "components/browsing_data/core/pref_names.h" | 11 #include "components/browsing_data/core/pref_names.h" |
| 12 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
| 13 | 13 |
| 14 namespace browsing_data { | 14 namespace browsing_data { |
| 15 | 15 |
| 16 BrowsingDataCounter::BrowsingDataCounter() {} | 16 BrowsingDataCounter::BrowsingDataCounter() {} |
| 17 | 17 |
| 18 BrowsingDataCounter::~BrowsingDataCounter() {} | 18 BrowsingDataCounter::~BrowsingDataCounter() {} |
| 19 | 19 |
| 20 void BrowsingDataCounter::Init(PrefService* pref_service, | 20 void BrowsingDataCounter::Init(PrefService* pref_service, |
| 21 ClearBrowsingDataPreferenceType pref_type, | |
| 21 const Callback& callback) { | 22 const Callback& callback) { |
| 22 DCHECK(!initialized_); | 23 DCHECK(!initialized_); |
| 23 callback_ = callback; | 24 callback_ = callback; |
| 24 pref_service_ = pref_service; | 25 pref_type_ = pref_type; |
| 25 pref_.Init(GetPrefName(), pref_service_, | 26 pref_.Init(GetPrefName(), pref_service, |
| 26 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); | 27 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); |
| 27 period_.Init( | 28 period_.Init( |
| 28 browsing_data::prefs::kDeleteTimePeriod, pref_service_, | 29 GetTimePeriodPrefName(), pref_service, |
| 29 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); | 30 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); |
| 30 | 31 |
| 31 initialized_ = true; | 32 initialized_ = true; |
| 32 OnInitialized(); | 33 OnInitialized(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void BrowsingDataCounter::OnInitialized() {} | 36 void BrowsingDataCounter::OnInitialized() {} |
| 36 | 37 |
| 37 base::Time BrowsingDataCounter::GetPeriodStart() { | 38 base::Time BrowsingDataCounter::GetPeriodStart() { |
| 38 return CalculateBeginDeleteTime(static_cast<TimePeriod>(*period_)); | 39 return CalculateBeginDeleteTime(static_cast<TimePeriod>(*period_)); |
| 39 } | 40 } |
| 40 | 41 |
| 41 void BrowsingDataCounter::Restart() { | 42 void BrowsingDataCounter::Restart() { |
| 42 DCHECK(initialized_); | 43 DCHECK(initialized_); |
| 43 callback_.Run(base::MakeUnique<Result>(this)); | 44 callback_.Run(base::MakeUnique<Result>(this)); |
| 44 Count(); | 45 Count(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void BrowsingDataCounter::ReportResult(ResultInt value) { | 48 void BrowsingDataCounter::ReportResult(ResultInt value) { |
| 48 DCHECK(initialized_); | 49 DCHECK(initialized_); |
| 49 callback_.Run(base::MakeUnique<FinishedResult>(this, value)); | 50 callback_.Run(base::MakeUnique<FinishedResult>(this, value)); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void BrowsingDataCounter::ReportResult(std::unique_ptr<Result> result) { | 53 void BrowsingDataCounter::ReportResult(std::unique_ptr<Result> result) { |
| 53 DCHECK(initialized_); | 54 DCHECK(initialized_); |
| 54 callback_.Run(std::move(result)); | 55 callback_.Run(std::move(result)); |
| 55 } | 56 } |
| 56 | 57 |
| 57 PrefService* BrowsingDataCounter::GetPrefs() const { | 58 const char* BrowsingDataCounter::GetTimePeriodPrefName() const { |
| 58 return pref_service_; | 59 return GetPrefType() == ClearBrowsingDataPreferenceType::BASIC |
|
msramek
2017/02/08 10:55:56
This is already defined as browsing_data::GetTimeP
dullweber
2017/02/08 23:03:19
Thanks, I removed this method.
| |
| 60 ? browsing_data::prefs::kDeleteTimePeriodBasic | |
| 61 : browsing_data::prefs::kDeleteTimePeriod; | |
| 62 } | |
| 63 | |
| 64 ClearBrowsingDataPreferenceType BrowsingDataCounter::GetPrefType() const { | |
| 65 return pref_type_; | |
| 59 } | 66 } |
| 60 | 67 |
| 61 // BrowsingDataCounter::Result ------------------------------------------------- | 68 // BrowsingDataCounter::Result ------------------------------------------------- |
| 62 | 69 |
| 63 BrowsingDataCounter::Result::Result(const BrowsingDataCounter* source) | 70 BrowsingDataCounter::Result::Result(const BrowsingDataCounter* source) |
| 64 : source_(source) {} | 71 : source_(source) {} |
| 65 | 72 |
| 66 BrowsingDataCounter::Result::~Result() {} | 73 BrowsingDataCounter::Result::~Result() {} |
| 67 | 74 |
| 68 bool BrowsingDataCounter::Result::Finished() const { | 75 bool BrowsingDataCounter::Result::Finished() const { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 81 bool BrowsingDataCounter::FinishedResult::Finished() const { | 88 bool BrowsingDataCounter::FinishedResult::Finished() const { |
| 82 return true; | 89 return true; |
| 83 } | 90 } |
| 84 | 91 |
| 85 BrowsingDataCounter::ResultInt BrowsingDataCounter::FinishedResult::Value() | 92 BrowsingDataCounter::ResultInt BrowsingDataCounter::FinishedResult::Value() |
| 86 const { | 93 const { |
| 87 return value_; | 94 return value_; |
| 88 } | 95 } |
| 89 | 96 |
| 90 } // namespace browsing_data | 97 } // namespace browsing_data |
| OLD | NEW |