| 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 namespace { | 16 namespace { |
| 17 static const int kDelayUntilShowCalculatingMs = 140; | 17 static const int kDelayUntilShowCalculatingMs = 140; |
| 18 static const int kDelayUntilReadyToShowResultMs = 1000; | 18 static const int kDelayUntilReadyToShowResultMs = 1000; |
| 19 } | 19 } |
| 20 | 20 |
| 21 BrowsingDataCounter::BrowsingDataCounter() | 21 BrowsingDataCounter::BrowsingDataCounter() |
| 22 : initialized_(false), | 22 : initialized_(false), |
| 23 state_(State::IDLE) {} | 23 state_(State::IDLE) {} |
| 24 | 24 |
| 25 BrowsingDataCounter::~BrowsingDataCounter() {} | 25 BrowsingDataCounter::~BrowsingDataCounter() {} |
| 26 | 26 |
| 27 void BrowsingDataCounter::Init(PrefService* pref_service, | 27 void BrowsingDataCounter::Init(PrefService* pref_service, |
| 28 ClearBrowsingDataTab clear_browsing_data_tab, |
| 28 const Callback& callback) { | 29 const Callback& callback) { |
| 29 DCHECK(!initialized_); | 30 DCHECK(!initialized_); |
| 30 callback_ = callback; | 31 callback_ = callback; |
| 31 pref_service_ = pref_service; | 32 clear_browsing_data_tab_ = clear_browsing_data_tab; |
| 32 pref_.Init(GetPrefName(), pref_service_, | 33 pref_.Init(GetPrefName(), pref_service, |
| 33 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); | 34 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); |
| 34 period_.Init( | 35 period_.Init( |
| 35 browsing_data::prefs::kDeleteTimePeriod, pref_service_, | 36 GetTimePeriodPreferenceName(GetTab()), pref_service, |
| 36 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); | 37 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); |
| 37 | 38 |
| 38 initialized_ = true; | 39 initialized_ = true; |
| 39 OnInitialized(); | 40 OnInitialized(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void BrowsingDataCounter::OnInitialized() {} | 43 void BrowsingDataCounter::OnInitialized() {} |
| 43 | 44 |
| 44 base::Time BrowsingDataCounter::GetPeriodStart() { | 45 base::Time BrowsingDataCounter::GetPeriodStart() { |
| 45 return CalculateBeginDeleteTime(static_cast<TimePeriod>(*period_)); | 46 return CalculateBeginDeleteTime(static_cast<TimePeriod>(*period_)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 timer_.Stop(); | 98 timer_.Stop(); |
| 98 staged_result_.reset(); | 99 staged_result_.reset(); |
| 99 callback_.Run(std::move(result)); | 100 callback_.Run(std::move(result)); |
| 100 } | 101 } |
| 101 | 102 |
| 102 const std::vector<BrowsingDataCounter::State>& | 103 const std::vector<BrowsingDataCounter::State>& |
| 103 BrowsingDataCounter::GetStateTransitionsForTesting() { | 104 BrowsingDataCounter::GetStateTransitionsForTesting() { |
| 104 return state_transitions_; | 105 return state_transitions_; |
| 105 } | 106 } |
| 106 | 107 |
| 107 PrefService* BrowsingDataCounter::GetPrefs() const { | 108 ClearBrowsingDataTab BrowsingDataCounter::GetTab() const { |
| 108 return pref_service_; | 109 return clear_browsing_data_tab_; |
| 109 } | 110 } |
| 110 | 111 |
| 111 void BrowsingDataCounter::TransitionToShowCalculating() { | 112 void BrowsingDataCounter::TransitionToShowCalculating() { |
| 112 DCHECK(initialized_); | 113 DCHECK(initialized_); |
| 113 DCHECK_EQ(State::RESTARTED, state_); | 114 DCHECK_EQ(State::RESTARTED, state_); |
| 114 state_ = State::SHOW_CALCULATING; | 115 state_ = State::SHOW_CALCULATING; |
| 115 state_transitions_.push_back(state_); | 116 state_transitions_.push_back(state_); |
| 116 | 117 |
| 117 callback_.Run(base::MakeUnique<Result>(this)); | 118 callback_.Run(base::MakeUnique<Result>(this)); |
| 118 timer_.Start( | 119 timer_.Start( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 bool BrowsingDataCounter::FinishedResult::Finished() const { | 159 bool BrowsingDataCounter::FinishedResult::Finished() const { |
| 159 return true; | 160 return true; |
| 160 } | 161 } |
| 161 | 162 |
| 162 BrowsingDataCounter::ResultInt BrowsingDataCounter::FinishedResult::Value() | 163 BrowsingDataCounter::ResultInt BrowsingDataCounter::FinishedResult::Value() |
| 163 const { | 164 const { |
| 164 return value_; | 165 return value_; |
| 165 } | 166 } |
| 166 | 167 |
| 167 } // namespace browsing_data | 168 } // namespace browsing_data |
| OLD | NEW |